2021-01-27 08:05:25 +01:00
|
|
|
#include "snes_clk.h"
|
|
|
|
#include <SdFat.h>
|
|
|
|
|
|
|
|
int32_t readClockOffset() {
|
|
|
|
File clock_file;
|
|
|
|
unsigned char* clock_buf;
|
|
|
|
int16_t i;
|
|
|
|
int32_t clock_offset;
|
2021-01-31 09:16:16 +01:00
|
|
|
|
2021-01-27 08:05:25 +01:00
|
|
|
if(!clock_file.open("/snes_clk.txt", FILE_READ)) {
|
|
|
|
return INT32_MIN;
|
|
|
|
}
|
|
|
|
|
2021-01-31 09:16:16 +01:00
|
|
|
clock_buf = malloc(12 * sizeof(char));
|
|
|
|
i = clock_file.read(clock_buf, 11);
|
2021-01-27 08:05:25 +01:00
|
|
|
clock_file.close();
|
|
|
|
if(i == -1) {
|
|
|
|
free(clock_buf);
|
2021-01-27 08:09:17 +01:00
|
|
|
return INT32_MIN;
|
2021-01-31 09:16:16 +01:00
|
|
|
} else if((i == 11) && (clock_buf[0] != '-')) {
|
|
|
|
free(clock_buf);
|
|
|
|
return INT32_MIN;
|
|
|
|
} else {
|
2021-01-27 08:05:25 +01:00
|
|
|
clock_buf[i] = 0;
|
|
|
|
}
|
|
|
|
|
2021-01-31 09:16:16 +01:00
|
|
|
for(i = 0; i < 12; i++) {
|
|
|
|
if(clock_buf[i] != '-' && clock_buf[i] < '0' && clock_buf[i] > '9') {
|
|
|
|
if(i == 0) {
|
|
|
|
free(clock_buf);
|
|
|
|
return INT32_MIN;
|
|
|
|
} else if((i == 1) && (clock_buf[0] == '-')) {
|
|
|
|
free(clock_buf);
|
|
|
|
return INT32_MIN;
|
|
|
|
} else {
|
|
|
|
clock_buf[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-27 08:05:25 +01:00
|
|
|
clock_offset = (int32_t)atoi(clock_buf);
|
|
|
|
free(clock_buf);
|
|
|
|
|
|
|
|
return clock_offset;
|
|
|
|
}
|