aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author浅倉麗子2020-04-22 19:54:54 -0400
committer浅倉麗子2020-04-22 19:54:54 -0400
commit04c4d6baffa140c54839d305fb873266cd151be5 (patch)
treeb1effabe25bb76ccae69a9414ff87b380405200e
parentAdd PS1 aspect ratio modes (diff)
downloadsharpscale-04c4d6baffa140c54839d305fb873266cd151be5.tar.gz
Add syscalls to get and set config
-rw-r--r--CMakeLists.txt16
-rw-r--r--config.c71
-rw-r--r--config.h28
-rw-r--r--exports.yml6
-rw-r--r--main.c6
-rw-r--r--sharpscale.h29
6 files changed, 120 insertions, 36 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ea40516..7897018 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.0)
+cmake_minimum_required(VERSION 3.13)
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
if(DEFINED ENV{DOLCESDK})
@@ -12,7 +12,7 @@ include("$ENV{DOLCESDK}/share/dolce.cmake" REQUIRED)
project(sharpscale LANGUAGES C)
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdlib -Wall -Wextra -O3 -std=c99")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -O3 -std=c99")
if(LOG_PRINTF)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLOG_PRINTF")
@@ -30,6 +30,10 @@ add_executable("${ELF}"
config.c
)
+target_link_options("${ELF}"
+ PRIVATE -nostdlib
+)
+
target_link_libraries("${ELF}"
gcc
SceDebugForDriver_stub
@@ -37,6 +41,7 @@ target_link_libraries("${ELF}"
SceIofilemgrForDriver_stub
SceSblACMgrForDriver_stub
SceSysclibForDriver_stub
+ SceSysmemForDriver_stub
taihenForKernel_stub
taihenModuleUtils_stub
)
@@ -46,3 +51,10 @@ dolce_create_self("${SELF}"
CONFIG exports.yml
UNSAFE
)
+
+dolce_create_stubs("${PROJECT_NAME}-stubs"
+ "${ELF}"
+ exports.yml
+ KERNEL
+ LIB Sharpscale_stub
+)
diff --git a/config.c b/config.c
index fc30c55..9ac78af 100644
--- a/config.c
+++ b/config.c
@@ -15,11 +15,32 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+#include <string.h>
#include <psp2kern/io/fcntl.h>
#include <psp2kern/io/stat.h>
+#include <psp2kern/kernel/sysmem.h>
#include "config.h"
-void read_config(SharpscaleConfig *config) {
+#define BASE_PATH "ur0:/data"
+#define SS_BASE_PATH BASE_PATH"/sharpscale"
+#define CONFIG_PATH SS_BASE_PATH"/config.bin"
+
+SharpscaleConfig ss_config;
+
+static bool is_config_valid(SharpscaleConfig *config) {
+ return config->mode < SHARPSCALE_MODE_INVALID
+ && config->psone_mode < SHARPSCALE_PSONE_MODE_INVALID
+ && (config->bilinear == true || config->bilinear == false);
+}
+
+int reset_config(SharpscaleConfig *config) {
+ config->mode = SHARPSCALE_MODE_INTEGER;
+ config->psone_mode = SHARPSCALE_PSONE_MODE_4_3;
+ config->bilinear = false;
+ return 0;
+}
+
+int read_config(SharpscaleConfig *config) {
SceUID fd = ksceIoOpen(CONFIG_PATH, SCE_O_RDONLY, 0);
if (fd < 0) { goto fail; }
@@ -27,14 +48,48 @@ void read_config(SharpscaleConfig *config) {
ksceIoClose(fd);
if (ret != sizeof(*config)) { goto fail; }
- if (SHARPSCALE_MODE_INVALID <= config->mode) { goto fail; }
- if (SHARPSCALE_PSONE_MODE_INVALID <= config->psone_mode) { goto fail; }
- if (config->bilinear != false && config->bilinear != true) { goto fail; }
+ if (!is_config_valid(config)) { goto fail; }
- return;
+ return 0;
fail:
- config->mode = SHARPSCALE_MODE_INTEGER;
- config->psone_mode = SHARPSCALE_PSONE_MODE_4_3;
- config->bilinear = false;
+ return -1;
+}
+
+int write_config(SharpscaleConfig *config) {
+ if (!is_config_valid(config)) { goto fail; }
+
+ ksceIoMkdir(BASE_PATH, 0777);
+ ksceIoMkdir(SS_BASE_PATH, 0777);
+ SceUID fd = ksceIoOpen(CONFIG_PATH, SCE_O_WRONLY | SCE_O_CREAT, 0777);
+ if (fd < 0) { goto fail; }
+
+ int ret = ksceIoWrite(fd, config, sizeof(*config));
+ ksceIoClose(fd);
+ if (ret != sizeof(*config)) { goto fail; }
+
+ return 0;
+
+fail:
+ return -1;
+}
+
+int SharpscaleGetConfig(SharpscaleConfig *config) {
+ if (!is_config_valid(&ss_config)) { goto fail; }
+ return ksceKernelMemcpyKernelToUser((uintptr_t)config, &ss_config, sizeof(*config));
+
+fail:
+ return -1;
+}
+
+int SharpscaleSetConfig(SharpscaleConfig *config) {
+ SharpscaleConfig kconfig;
+ int ret = ksceKernelMemcpyUserToKernel(&kconfig, (uintptr_t)config, sizeof(kconfig));
+ if (ret < 0) { goto fail; }
+ if (!is_config_valid(&kconfig)) { goto fail; }
+ memcpy(&ss_config, &kconfig, sizeof(ss_config));
+ return write_config(&ss_config);
+
+fail:
+ return -1;
}
diff --git a/config.h b/config.h
index d286494..5424f78 100644
--- a/config.h
+++ b/config.h
@@ -1,30 +1,10 @@
#ifndef CONFIG_H
#define CONFIG_H
-#include <stdbool.h>
+#include "sharpscale.h"
-#define CONFIG_PATH "ur0:/data/sharpscale/config.bin"
-
-typedef enum SharpscaleMode {
- SHARPSCALE_MODE_ORIGINAL,
- SHARPSCALE_MODE_INTEGER,
- SHARPSCALE_MODE_REAL,
- SHARPSCALE_MODE_INVALID,
-} SharpscaleMode;
-
-typedef enum SharpscalePSOneMode {
- SHARPSCALE_PSONE_MODE_PIXEL,
- SHARPSCALE_PSONE_MODE_4_3,
- SHARPSCALE_PSONE_MODE_16_9,
- SHARPSCALE_PSONE_MODE_INVALID,
-} SharpscalePSOneMode;
-
-typedef struct SharpscaleConfig {
- SharpscaleMode mode;
- SharpscalePSOneMode psone_mode;
- bool bilinear;
-} SharpscaleConfig;
-
-void read_config(SharpscaleConfig *config);
+int reset_config(SharpscaleConfig *config);
+int read_config(SharpscaleConfig *config);
+int write_config(SharpscaleConfig *config);
#endif
diff --git a/exports.yml b/exports.yml
index ab9cdb4..d8c9735 100644
--- a/exports.yml
+++ b/exports.yml
@@ -6,3 +6,9 @@ Sharpscale:
main:
start: module_start
stop: module_stop
+ modules:
+ Sharpscale:
+ syscall: true
+ functions:
+ - SharpscaleGetConfig
+ - SharpscaleSetConfig
diff --git a/main.c b/main.c
index 1c6028e..7cd9a47 100644
--- a/main.c
+++ b/main.c
@@ -97,7 +97,7 @@ extern int module_get_offset(SceUID pid, SceUID modid, int segidx, size_t offset
#define GET_OFFSET(modid, seg, ofs, addr)\
module_get_offset(KERNEL_PID, modid, seg, ofs, (uintptr_t*)addr)
-static SharpscaleConfig ss_config;
+extern SharpscaleConfig ss_config;
// SceDisplay_8100B000
static SceDisplayHead *head_data = 0;
@@ -232,7 +232,9 @@ int _start() __attribute__ ((weak, alias("module_start")));
int module_start(SceSize argc, const void *argv) { (void)argc; (void)argv;
startup();
- read_config(&ss_config);
+ if (read_config(&ss_config) < 0) {
+ reset_config(&ss_config);
+ }
tai_module_info_t minfo;
minfo.size = sizeof(minfo);
diff --git a/sharpscale.h b/sharpscale.h
new file mode 100644
index 0000000..6dd1dae
--- /dev/null
+++ b/sharpscale.h
@@ -0,0 +1,29 @@
+#ifndef SHARPSCALE_H
+#define SHARPSCALE_H
+
+#include <stdbool.h>
+
+typedef enum SharpscaleMode {
+ SHARPSCALE_MODE_ORIGINAL,
+ SHARPSCALE_MODE_INTEGER,
+ SHARPSCALE_MODE_REAL,
+ SHARPSCALE_MODE_INVALID,
+} SharpscaleMode;
+
+typedef enum SharpscalePSOneMode {
+ SHARPSCALE_PSONE_MODE_PIXEL,
+ SHARPSCALE_PSONE_MODE_4_3,
+ SHARPSCALE_PSONE_MODE_16_9,
+ SHARPSCALE_PSONE_MODE_INVALID,
+} SharpscalePSOneMode;
+
+typedef struct SharpscaleConfig {
+ SharpscaleMode mode;
+ SharpscalePSOneMode psone_mode;
+ bool bilinear;
+} SharpscaleConfig;
+
+int SharpscaleGetConfig(SharpscaleConfig *config);
+int SharpscaleSetConfig(SharpscaleConfig *config);
+
+#endif