aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author浅倉麗子2020-04-21 18:57:21 -0400
committer浅倉麗子2020-04-21 18:57:21 -0400
commit36976d5028ebc208e104b63681b4c8e0686872b6 (patch)
tree2c25935e3331cca4f63348c50dcfa8501b97cecd
parentAdd lines to verify cropping in scaling test (diff)
downloadsharpscale-36976d5028ebc208e104b63681b4c8e0686872b6.tar.gz
Use binary config file
-rw-r--r--config.c21
-rw-r--r--config.h23
-rw-r--r--main.c2
3 files changed, 22 insertions, 24 deletions
diff --git a/config.c b/config.c
index 2d843e3..39d594c 100644
--- a/config.c
+++ b/config.c
@@ -15,33 +15,24 @@ 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 <stdlib.h>
-#include <string.h>
#include <psp2kern/io/fcntl.h>
#include <psp2kern/io/stat.h>
#include "config.h"
-#define CONFIG_PATH "ur0:/data/sharpscale/config.txt"
-
-void read_config(sharpscale_config_t *config) {
+void read_config(SharpscaleConfig *config) {
SceUID fd = ksceIoOpen(CONFIG_PATH, SCE_O_RDONLY, 0);
if (fd < 0) { goto fail; }
- char buf[4];
- memset(buf, 0x00, sizeof(buf));
- int ret = ksceIoRead(fd, buf, sizeof(buf) - 1);
+ int ret = ksceIoRead(fd, config, sizeof(*config));
ksceIoClose(fd);
- if (ret != sizeof(buf) - 1) { goto fail; }
-
- config->mode = strtol(buf, NULL, 10);
- config->bilinear = strtol(buf + 2, NULL, 10);
+ if (ret != sizeof(*config)) { goto fail; }
- if (config->mode < 0 || 2 < config->mode) { goto fail; }
- if ((config->bilinear & ~1) != 0) { goto fail; }
+ if (SHARPSCALE_MODE_INVALID <= config->mode) { goto fail; }
+ if (config->bilinear != false && config->bilinear != true) { goto fail; }
return;
fail:
config->mode = SHARPSCALE_MODE_INTEGER;
- config->bilinear = 0;
+ config->bilinear = false;
}
diff --git a/config.h b/config.h
index dacc293..a6c6cba 100644
--- a/config.h
+++ b/config.h
@@ -1,15 +1,22 @@
#ifndef CONFIG_H
#define CONFIG_H
-#define SHARPSCALE_MODE_ORIGINAL 0
-#define SHARPSCALE_MODE_INTEGER 1
-#define SHARPSCALE_MODE_REAL 2
+#include <stdbool.h>
-typedef struct {
- int mode;
- int bilinear;
-} sharpscale_config_t;
+#define CONFIG_PATH "ur0:/data/sharpscale/config.bin"
-void read_config(sharpscale_config_t *config);
+typedef enum SharpscaleMode {
+ SHARPSCALE_MODE_ORIGINAL,
+ SHARPSCALE_MODE_INTEGER,
+ SHARPSCALE_MODE_REAL,
+ SHARPSCALE_MODE_INVALID,
+} SharpscaleMode;
+
+typedef struct SharpscaleConfig {
+ SharpscaleMode mode;
+ bool bilinear;
+} SharpscaleConfig;
+
+void read_config(SharpscaleConfig *config);
#endif
diff --git a/main.c b/main.c
index 1f02a57..111a293 100644
--- a/main.c
+++ b/main.c
@@ -96,7 +96,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 sharpscale_config_t ss_config;
+static SharpscaleConfig ss_config;
// SceDisplay_8100B000
static SceDisplayHead *head_data = 0;