mirror of
https://github.com/sanni/cartreader.git
synced 2024-11-10 23:15:08 +01:00
Implemented custom atoi methods, as the included one only has 16-bit precision
This commit is contained in:
parent
97e5e21962
commit
cf477ee629
@ -7,22 +7,23 @@
|
||||
|
||||
#include "options.h"
|
||||
#ifdef enable_NES
|
||||
#include "atoi32.h"
|
||||
|
||||
//Line Content
|
||||
//26 Supported Mappers
|
||||
//101 Defines
|
||||
//131 Variables
|
||||
//192 Menu
|
||||
//311 Setup
|
||||
//340 Low Level Functions
|
||||
//587 CRC Functions
|
||||
//647 File Functions
|
||||
//831 NES 2.0 Header Functions
|
||||
//1112 Config Functions
|
||||
//1708 ROM Functions
|
||||
//2806 RAM Functions
|
||||
//3235 Eeprom Functions
|
||||
//3431 NESmaker Flash Cart Functions
|
||||
//28 Supported Mappers
|
||||
//103 Defines
|
||||
//133 Variables
|
||||
//194 Menu
|
||||
//313 Setup
|
||||
//342 Low Level Functions
|
||||
//589 CRC Functions
|
||||
//649 File Functions
|
||||
//844 NES 2.0 Header Functions
|
||||
//1125 Config Functions
|
||||
//1721 ROM Functions
|
||||
//2819 RAM Functions
|
||||
//3248 Eeprom Functions
|
||||
//3444 NESmaker Flash Cart Functions
|
||||
|
||||
/******************************************
|
||||
Supported Mappers
|
||||
@ -1037,7 +1038,7 @@ uint32_t getPRGSizeFromDatabaseRow(const char* crctest) {
|
||||
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);
|
||||
|
||||
return return_size;
|
||||
@ -1049,7 +1050,7 @@ uint32_t getCHRSizeFromDatabaseRow(const char* crctest) {
|
||||
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);
|
||||
|
||||
return return_size;
|
||||
|
55
Cart_Reader/atoi32.cpp
Normal file
55
Cart_Reader/atoi32.cpp
Normal 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
10
Cart_Reader/atoi32.h
Normal 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
|
@ -1,5 +1,6 @@
|
||||
#include "snes_clk.h"
|
||||
#include <SdFat.h>
|
||||
#include "atoi32.h"
|
||||
|
||||
int32_t readClockOffset() {
|
||||
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);
|
||||
|
||||
return clock_offset;
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define _SNES_CLK_H
|
||||
|
||||
#include <SdFat.h>
|
||||
#include "atoi32.h"
|
||||
|
||||
int32_t readClockOffset();
|
||||
|
||||
|
BIN
sd/nes20db.txt
BIN
sd/nes20db.txt
Binary file not shown.
Loading…
Reference in New Issue
Block a user