-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #519 from red031000/master
sync ascii_util from HG
- Loading branch information
Showing
9 changed files
with
127 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef POKEDIAMOND_NNS_G3D_RES_STRUCT_H | ||
#define POKEDIAMOND_NNS_G3D_RES_STRUCT_H | ||
|
||
#include "nitro/types.h" | ||
|
||
#define NNS_G3D_RESNAME_SIZE (16) | ||
#define NNS_G3D_RESNAME_VALSIZE (NNS_G3D_RESNAME_SIZE / sizeof(u32)) | ||
|
||
typedef union NNSG3dResName { | ||
char name[NNS_G3D_RESNAME_SIZE]; | ||
u32 val[NNS_G3D_RESNAME_VALSIZE]; | ||
} NNSG3dResName; | ||
|
||
#endif //POKEDIAMOND_NNS_G3D_RES_STRUCT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include "global.h" | ||
#include "ascii_util.h" | ||
|
||
s32 Ascii_StrLen(const s8 *str) { | ||
s32 i = 0; | ||
while (str[i] != 0) { | ||
i++; | ||
} | ||
return i; | ||
} | ||
|
||
const s8 *Ascii_GetDelim(const s8 *src, s8 *dst, s32 c) { | ||
for (int i = 0; i < 256; i++) { | ||
dst[i] = src[i]; | ||
if (src[i] == c || src[i] == 0) { | ||
dst[i] = 0; | ||
if (c == '\r' && src[i + 1] == '\n') { | ||
return &src[i + 2]; | ||
} | ||
return &src[i + 1]; | ||
} | ||
} | ||
|
||
return NULL; | ||
} | ||
|
||
s32 Ascii_StrToL(const s8 *str) { | ||
s32 length = Ascii_StrLen(str); | ||
s32 i; | ||
s32 pow10 = 1; | ||
s32 num = 0; | ||
|
||
// Traverse from right to left | ||
for (i = length - 1; i >= 0; i--) { | ||
if (str[i] >= '0' && str[i] <= '9') { | ||
// Numeric digit | ||
num += pow10 * (str[i] - '0'); | ||
} else { | ||
// If first character is a minus sign, it's negative | ||
if (i == 0) { | ||
if(str[i] == '-') { | ||
num *= -1; | ||
} | ||
} else { | ||
// Invalid character | ||
return -1; | ||
} | ||
// UB: If first character is invalid, still treated as valid string | ||
} | ||
pow10 *= 10; | ||
|
||
// UB: No check for integer overflow! | ||
} | ||
return num; | ||
} | ||
|
||
void sub_0201C750(NNSG3dResName *resName, const s8 *input) { | ||
// memset(resName, 0, NNS_G3D_RESNAME_SIZE); | ||
// strncpy(resName->name, input, NNS_G3D_RESNAME_SIZE); | ||
|
||
for (u8 i = 0; i < NNS_G3D_RESNAME_VALSIZE; i++) { | ||
resName->val[i] = 0; | ||
} | ||
u8 length = Ascii_StrLen(input); | ||
for (u8 i = 0; i < length; i++) { | ||
resName->name[i] = input[i]; | ||
} | ||
} | ||
|
||
BOOL sub_0201C78C(u16 c) { | ||
return c < CHAR_0; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef POKEDIAMOND_ASCII_UTIL_H | ||
#define POKEDIAMOND_ASCII_UTIL_H | ||
|
||
#include "nitro/types.h" | ||
|
||
s32 Ascii_StrLen(const s8 *str); | ||
const s8 *Ascii_GetDelim(const s8 *src, s8 *dst, s32 c); | ||
s32 Ascii_StrToL(const s8 *str); | ||
void sub_0201C750(NNSG3dResName *resName, const s8 *input); | ||
BOOL sub_0201C78C(u16 c); | ||
|
||
#endif // POKEDIAMOND_ASCII_UTIL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.