Skip to content

Commit

Permalink
Merge pull request #519 from red031000/master
Browse files Browse the repository at this point in the history
sync ascii_util from HG
  • Loading branch information
red031000 authored Jul 1, 2023
2 parents fd55544 + 2b992a8 commit b145ba9
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 117 deletions.
2 changes: 1 addition & 1 deletion arm9/arm9.lsf
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Static arm9
Object unk_0201C24C.o
Object unk_0201C360.o
Object unk_0201C620.o
Object unk_0201C6B4.o
Object ascii_util.o
Object unk_0201C7A0.o
Object unk_0201CBEC.o
Object unk_0201CC08.o
Expand Down
4 changes: 2 additions & 2 deletions arm9/global.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1181,8 +1181,8 @@
.extern sub_0201C620
.extern sub_0201C62C
.extern sub_0201C638
.extern sub_0201C6C8
.extern sub_0201C70C
.extern Ascii_GetDelim
.extern Ascii_StrToL
.extern sub_0201C750
.extern sub_0201C78C
.extern sub_0201C7A0
Expand Down
14 changes: 14 additions & 0 deletions arm9/lib/libnns/include/NNS_G3D_res_struct.h
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
48 changes: 24 additions & 24 deletions arm9/overlays/05/asm/ov05_021DB44C.s
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ ov05_021DB61C: ; 0x021DB61C
_021DB63C:
add r1, r5, #0
mov r2, #0xd
bl sub_0201C6C8
bl Ascii_GetDelim
ldrsb r1, [r5, r4]
cmp r1, #0x45
bne _021DB656
Expand All @@ -279,31 +279,31 @@ _021DB63C:
_021DB656:
add r1, r5, #0
mov r2, #0xd
bl sub_0201C6C8
bl Ascii_GetDelim
add r1, r5, #0
mov r2, #0xd
bl sub_0201C6C8
bl Ascii_GetDelim
add r1, r5, #0
mov r2, #0xd
bl sub_0201C6C8
bl Ascii_GetDelim
add r1, r5, #0
mov r2, #0xd
bl sub_0201C6C8
bl Ascii_GetDelim
add r1, r5, #0
mov r2, #0xd
bl sub_0201C6C8
bl Ascii_GetDelim
add r1, r5, #0
mov r2, #0xd
bl sub_0201C6C8
bl Ascii_GetDelim
add r1, r5, #0
mov r2, #0xd
bl sub_0201C6C8
bl Ascii_GetDelim
add r1, r5, #0
mov r2, #0xd
bl sub_0201C6C8
bl Ascii_GetDelim
add r1, r5, #0
mov r2, #0xd
bl sub_0201C6C8
bl Ascii_GetDelim
ldr r1, [sp, #8]
add r1, r1, #1
str r1, [sp, #8]
Expand Down Expand Up @@ -347,14 +347,14 @@ _021DB6E8:
ldr r1, [sp, #0x10]
add r4, r5, r1
add r1, sp, #0x11c
bl sub_0201C6C8
bl Ascii_GetDelim
str r0, [sp, #4]
add r0, sp, #0x11c
add r1, sp, #0x1c
mov r2, #0x2c
bl sub_0201C6C8
bl Ascii_GetDelim
add r0, sp, #0x1c
bl sub_0201C70C
bl Ascii_StrToL
ldr r1, [sp, #0x10]
add r6, r4, #0
str r0, [r5, r1]
Expand Down Expand Up @@ -406,7 +406,7 @@ _021DB73E:
bl ov05_021DB8A4
add r1, sp, #0x11c
mov r2, #0xd
bl sub_0201C6C8
bl Ascii_GetDelim
ldr r1, [sp, #0x10]
add r1, #0x30
str r1, [sp, #0x10]
Expand Down Expand Up @@ -448,15 +448,15 @@ ov05_021DB7B4: ; 0x021DB7B4
add r7, r2, #0
add r1, sp, #0x11c
mov r2, #0xd
bl sub_0201C6C8
bl Ascii_GetDelim
str r0, [sp]
add r0, sp, #0x11c
add r1, sp, #0x1c
mov r2, #0x2c
bl sub_0201C6C8
bl Ascii_GetDelim
add r4, r0, #0
add r0, sp, #0x1c
bl sub_0201C70C
bl Ascii_StrToL
cmp r0, #1
bne _021DB88C
mov r6, #0
Expand All @@ -465,10 +465,10 @@ _021DB7E2:
add r0, r4, #0
add r1, sp, #0x1c
mov r2, #0x2c
bl sub_0201C6C8
bl Ascii_GetDelim
add r4, r0, #0
add r0, sp, #0x1c
bl sub_0201C70C
bl Ascii_StrToL
strh r0, [r5]
add r6, r6, #1
add r5, r5, #2
Expand All @@ -490,10 +490,10 @@ _021DB816:
add r0, r4, #0
add r1, sp, #0x1c
mov r2, #0x2c
bl sub_0201C6C8
bl Ascii_GetDelim
add r4, r0, #0
add r0, sp, #0x1c
bl sub_0201C70C
bl Ascii_StrToL
add r6, r6, #1
stmia r5!, {r0}
cmp r6, #3
Expand Down Expand Up @@ -571,7 +571,7 @@ ov05_021DB8A4: ; 0x021DB8A4
add r1, sp, #0x10c
add r1, #2
mov r2, #0xd
bl sub_0201C6C8
bl Ascii_GetDelim
add r6, sp, #0x10c
add r7, sp, #0xc
str r0, [sp]
Expand All @@ -583,10 +583,10 @@ _021DB8C4:
add r0, r6, #0
add r1, r7, #0
mov r2, #0x2c
bl sub_0201C6C8
bl Ascii_GetDelim
add r6, r0, #0
add r0, r7, #0
bl sub_0201C70C
bl Ascii_StrToL
strh r0, [r5]
add r4, r4, #1
add r5, r5, #2
Expand Down
72 changes: 72 additions & 0 deletions arm9/src/ascii_util.c
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;
}
80 changes: 0 additions & 80 deletions arm9/src/unk_0201C6B4.c

This file was deleted.

12 changes: 12 additions & 0 deletions include/ascii_util.h
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
2 changes: 2 additions & 0 deletions include/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "config.h"

#include "NNS_G3D_res_struct.h" //todo: add to nnsys.h

#include <string.h>
#include "function_target.h"
#include "nitro/types.h"
Expand Down
10 changes: 0 additions & 10 deletions include/unk_0201C6B4.h

This file was deleted.

0 comments on commit b145ba9

Please sign in to comment.