Implemented custom atoi methods, as the included one only has 16-bit precision

This commit is contained in:
Kreeblah 2021-02-07 20:34:39 -08:00
parent 97e5e21962
commit cf477ee629
6 changed files with 85 additions and 17 deletions

View File

@ -7,22 +7,23 @@
#include "options.h" #include "options.h"
#ifdef enable_NES #ifdef enable_NES
#include "atoi32.h"
//Line Content //Line Content
//26 Supported Mappers //28 Supported Mappers
//101 Defines //103 Defines
//131 Variables //133 Variables
//192 Menu //194 Menu
//311 Setup //313 Setup
//340 Low Level Functions //342 Low Level Functions
//587 CRC Functions //589 CRC Functions
//647 File Functions //649 File Functions
//831 NES 2.0 Header Functions //844 NES 2.0 Header Functions
//1112 Config Functions //1125 Config Functions
//1708 ROM Functions //1721 ROM Functions
//2806 RAM Functions //2819 RAM Functions
//3235 Eeprom Functions //3248 Eeprom Functions
//3431 NESmaker Flash Cart Functions //3444 NESmaker Flash Cart Functions
/****************************************** /******************************************
Supported Mappers Supported Mappers
@ -1037,7 +1038,7 @@ uint32_t getPRGSizeFromDatabaseRow(const char* crctest) {
return 0; return 0;
} }
uint32_t return_size = (uint32_t)atoi(prg_size_str); uint32_t return_size = atoi32_unsigned(prg_size_str);
free(prg_size_str); free(prg_size_str);
return return_size; return return_size;
@ -1049,7 +1050,7 @@ uint32_t getCHRSizeFromDatabaseRow(const char* crctest) {
return 0; return 0;
} }
uint32_t return_size = (uint32_t)atoi(chr_size_str); uint32_t return_size = atoi32_unsigned(chr_size_str);
free(chr_size_str); free(chr_size_str);
return return_size; return return_size;

55
Cart_Reader/atoi32.cpp Normal file
View File

@ -0,0 +1,55 @@
#include "atoi32.h"
#include <stddef.h>
#include <inttypes.h>
int32_t atoi32_signed(const char* input_string) {
if (input_string == NULL) {
return 0;
}
int int_sign = 1;
int i = 0;
if (input_string[0] == '-') {
int_sign = -1;
i = 1;
}
int64_t return_val = 0;
while (input_string[i] != '\0') {
if (input_string[i] >= '0' && input_string[i] <= '9') {
return_val = (return_val * 10) + (input_string[i] - '0');
} else if (input_string[i] != '\0') {
return 0;
}
i++;
}
return_val = return_val * int_sign;
return return_val;
}
uint32_t atoi32_unsigned(const char* input_string) {
if (input_string == NULL) {
return 0;
}
int i = 0;
uint64_t return_val = 0;
while (input_string[i] != '\0') {
if (input_string[i] >= '0' && input_string[i] <= '9') {
return_val = (return_val * 10) + (input_string[i] - '0');
} else if (input_string[i] != '\0') {
return 0;
}
i++;
}
return return_val;
}

10
Cart_Reader/atoi32.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef _ATOI32_H
#define _ATOI32_H
#include <stddef.h>
#include <inttypes.h>
int32_t atoi32_signed(const char* input_string);
uint32_t atoi32_unsigned(const char* input_string);
#endif

View File

@ -1,5 +1,6 @@
#include "snes_clk.h" #include "snes_clk.h"
#include <SdFat.h> #include <SdFat.h>
#include "atoi32.h"
int32_t readClockOffset() { int32_t readClockOffset() {
File clock_file; File clock_file;
@ -38,7 +39,7 @@ int32_t readClockOffset() {
} }
} }
clock_offset = (int32_t)atoi(clock_buf); clock_offset = atoi32_signed(clock_buf);
free(clock_buf); free(clock_buf);
return clock_offset; return clock_offset;

View File

@ -2,6 +2,7 @@
#define _SNES_CLK_H #define _SNES_CLK_H
#include <SdFat.h> #include <SdFat.h>
#include "atoi32.h"
int32_t readClockOffset(); int32_t readClockOffset();

Binary file not shown.