Attempt to decompile strtol

This commit is contained in:
Ryan Dwyer
2021-01-30 23:35:56 +10:00
parent 36f092e775
commit a4819ebe65
4 changed files with 109 additions and 7 deletions
+3 -3
View File
@@ -54,7 +54,7 @@ void gfxInitMemory(void)
s32 gfx;
s32 gfxtra = 0;
gfx = func00013408(argFindByPrefix(1, "-mgfx"), NULL, 0) * 1024;
gfx = strtol(argFindByPrefix(1, "-mgfx"), NULL, 0) * 1024;
if (argFindByPrefix(1, "-mgfxtra")) {
// ******** Extra specified but are we in the correct game mode I wonder???\n
@@ -64,7 +64,7 @@ void gfxInitMemory(void)
// ******** If you try and run hi-res then\n
// ******** you're gonna shafted up the arse\n
// ******** so don't blame me\n
gfxtra = func00013408(argFindByPrefix(1, "-mgfxtra"), NULL, 0) * 1024;
gfxtra = strtol(argFindByPrefix(1, "-mgfxtra"), NULL, 0) * 1024;
} else {
// ******** No we're not so there\n
}
@@ -78,7 +78,7 @@ void gfxInitMemory(void)
if (argFindByPrefix(1, "-mvtx")) {
// Argument specified mtxvtx_size\n
g_VtxSizesByPlayerCount[PLAYERCOUNT() - 1] = func00013408(argFindByPrefix(1, "-mvtx"), NULL, 0) * 1024;
g_VtxSizesByPlayerCount[PLAYERCOUNT() - 1] = strtol(argFindByPrefix(1, "-mvtx"), NULL, 0) * 1024;
}
// %d Players : Allocating %d bytes for master dl's\n
+1 -1
View File
@@ -12,6 +12,6 @@ char toupper(char c);
s32 isdigit(char c);
s32 isalpha(char c);
s32 isspace(char c);
s32 func00013408(char *arg0, s32 *arg1, s32 arg2);
s32 strtol(char *arg0, char **arg1, s32 arg2);
#endif
+2 -2
View File
@@ -961,7 +961,7 @@ void mainLoop(void)
func0f1672f0(4);
if (argFindByPrefix(1, "-ma")) {
var8005d9b8 = func00013408(argFindByPrefix(1, "-ma"), NULL, 0) * 1024;
var8005d9b8 = strtol(argFindByPrefix(1, "-ma"), NULL, 0) * 1024;
}
func00012a14(malloc(var8005d9b8, MEMPOOL_STAGE), var8005d9b8);
@@ -972,7 +972,7 @@ void mainLoop(void)
numplayers = 0;
} else {
if (argFindByPrefix(1, "-play")) {
numplayers = func00013408(argFindByPrefix(1, "-play"), NULL, 0);
numplayers = strtol(argFindByPrefix(1, "-play"), NULL, 0);
} else {
numplayers = 1;
}
+103 -1
View File
@@ -143,7 +143,7 @@ s32 isspace(char c)
}
GLOBAL_ASM(
glabel func00013408
glabel strtol
/* 13408: 27bdffa0 */ addiu $sp,$sp,-96
/* 1340c: afb30024 */ sw $s3,0x24($sp)
/* 13410: 00c09825 */ or $s3,$a2,$zero
@@ -331,3 +331,105 @@ glabel func00013408
/* 13688: 27bd0060 */ addiu $sp,$sp,0x60
/* 1368c: 00000000 */ nop
);
// Mismatch: The below moves c from s0 to v1 near 590 for the compare with
// cutlim and the add to value, while goal keeps it in s0. Also tried verbatim
// strtol from glibc 1995 (commit 28f540f45b) which has the same codegen.
//s32 strtol(char *src, char **endptr, s32 base)
//{
// bool negative;
// u32 cutoff;
// u32 cutlim;
// u32 value;
// char *ptr;
// char c;
// char *save;
// bool overflow;
//
// if (base < 0 || base == 1 || base > 36) {
// base = 10;
// }
//
// ptr = src;
//
// while (isspace(*ptr)) {
// ptr++;
// }
//
// if (*ptr != '\0') {
// if (*ptr == '-') {
// negative = true;
// ptr++;
// } else if (*ptr == '+') {
// negative = false;
// ptr++;
// } else {
// negative = false;
// }
//
// if (base == 16 && ptr[0] == '0' && toupper(ptr[1]) == 'X') {
// ptr += 2;
// }
//
// if (base == 0) {
// if (*ptr == '0') {
// if (toupper(ptr[1]) == 'X') {
// ptr += 2;
// base = 16;
// } else {
// base = 8;
// }
// } else {
// base = 10;
// }
// }
//
// save = ptr;
//
// cutoff = U32_MAX / base;
// cutlim = U32_MAX % base;
// overflow = false;
// value = 0;
//
// for (c = *ptr; c != '\0'; c = *++ptr) {
// if (isdigit(c)) {
// c -= '0';
// } else if (isalpha(c)) {
// c = toupper(c) - 'A' + 10;
// } else {
// break;
// }
//
// // 590
// if (c >= base) {
// break;
// }
//
// // 5a4
// if (value > cutoff || (value == cutoff && c > cutlim)) {
// overflow = true;
// } else {
// value *= base;
// value += c;
// }
// }
//
// if (ptr != save) {
// if (endptr != NULL) {
// *endptr = ptr;
// }
//
// if (overflow) {
// return -1;
// }
//
// return negative ? -value : value;
// }
// }
//
// if (endptr != NULL) {
// *endptr = src;
// }
//
// return 0;
//}