os_printf.c

This commit is contained in:
PikalaxALT 2021-09-19 09:33:03 -04:00
parent 94d8343c1f
commit fd6cfb9c50
15 changed files with 130 additions and 95 deletions

View File

@ -29205,9 +29205,9 @@
.public G3_EndMakeDL
.public OS_SetIrqFunction
.public OS_GetIrqFunction
.public sub_020D164C
.public sub_020D168C
.public sub_020D16B4
.public OS_SPrintf
.public OS_SNPrintf
.public OS_VSNPrintf
.public sub_020D1AC4
.public sub_020D1AD4
.public sub_020D1BD0

View File

@ -1057,7 +1057,7 @@ ov00_021E89AC: ; 0x021E89AC
ldr r2, _021E8C3C ; =_02216550
mov r0, r4
str r5, [sp]
bl sub_020D168C
bl OS_SNPrintf
b _021E8A08
_021E89F0:
ldr r3, [r6, #8]
@ -1065,13 +1065,13 @@ _021E89F0:
ldr r2, _021E8C3C ; =_02216550
mov r0, r4
str r5, [sp]
bl sub_020D168C
bl OS_SNPrintf
_021E8A08:
ldrh r3, [r6, #0x10]
ldr r2, _021E8C40 ; =_02216558
add r0, r4, #0xe
mov r1, #7
bl sub_020D168C
bl OS_SNPrintf
ldr r0, _021E8C44 ; =0x027FFE0C
ldrb r0, [r0]
cmp r0, #0
@ -1104,7 +1104,7 @@ _021E8A84:
ldrb r2, [r7], #1
mov r0, r8
mov r1, r5
bl sub_020D164C
bl OS_SPrintf
add r6, r6, #1
cmp r6, #6
add r8, r8, #2
@ -1119,7 +1119,7 @@ _021E8A84:
strhsb r0, [sp, #0x38]
ldrb r3, [sp, #0x38]
add r0, r4, #0x2c
bl sub_020D168C
bl OS_SNPrintf
add r0, sp, #0x3c
add r1, r4, #0x7e
mov r2, #0x14
@ -1130,7 +1130,7 @@ _021E8A84:
str r1, [sp]
ldrb r3, [sp, #0x3a]
mov r1, #5
bl sub_020D168C
bl OS_SNPrintf
add r0, sp, #0x28
add r1, sp, #0x1c
bl sub_020DBBFC
@ -1152,7 +1152,7 @@ _021E8A84:
ldr r3, [sp, #0x24]
str r3, [sp, #0x10]
ldr r3, [sp, #0x28]
bl sub_020D168C
bl OS_SNPrintf
bl OS_DisableInterrupts
mov r6, r0
bl sub_020AFF20
@ -1174,7 +1174,7 @@ _021E8B94:
ldrb r2, [r7, sb]
mov r0, r8
mov r1, r5
bl sub_020D164C
bl OS_SPrintf
add sb, sb, #1
cmp sb, #6
add r8, r8, #2
@ -1191,7 +1191,7 @@ _021E8BD0:
ldr r2, _021E8C58 ; =_02216590
add r0, r4, #0x6f
mov r1, #0xe
bl sub_020D168C
bl OS_SNPrintf
add r0, sp, #0x14
bl sub_020AFF64
mov r5, r0
@ -1239,7 +1239,7 @@ ov00_021E8C5C: ; 0x021E8C5C
add r0, sp, #4
mov r1, #0x21
str r3, [sp]
bl sub_020D168C
bl OS_SNPrintf
add r0, sp, #4
bl strlen
mov r3, r0
@ -1403,7 +1403,7 @@ _021E8EFC:
add r0, sp, #4
mov r1, #0x21
str r3, [sp]
bl sub_020D168C
bl OS_SNPrintf
ldr r1, _021E8F98 ; =_02216634
add r2, sp, #4
mov r0, r6
@ -1543,7 +1543,7 @@ ov00_021E90BC: ; 0x021E90BC
ldr r2, _021E914C ; =_022166CC
add r0, sp, #0
mov r1, #7
bl sub_020D168C
bl OS_SNPrintf
ldr r1, _021E9150 ; =_022166D0
add r2, sp, #0
mov r0, r4
@ -2090,7 +2090,7 @@ ov00_021E9808: ; 0x021E9808
ldr r0, [r5, #4]
ldr r1, [r5, #0xc]
ldr r3, [r3, #0x128]
bl sub_020D168C
bl OS_SNPrintf
ldr r1, [r5, #4]
add r0, r1, r0
str r0, [r5, #4]
@ -2151,7 +2151,7 @@ _021E9940:
mov r3, r7
mov r0, sb
add r1, r4, #1
bl sub_020D168C
bl OS_SNPrintf
strb r8, [sb, r0]
ldr r1, [r5, #4]
mov r0, #0
@ -2212,7 +2212,7 @@ ov00_021E99A4: ; 0x021E99A4
_021E9A54:
mov r2, r7
mov r3, sb
bl sub_020D168C
bl OS_SNPrintf
ldr r2, [r6, #4]
mov r1, fp
add r2, r2, r0
@ -2263,7 +2263,7 @@ ov00_021E9AB0: ; 0x021E9AB0
_021E9B08:
ldr r2, _021E9B34 ; =_022167B4
mov r3, r6
bl sub_020D168C
bl OS_SNPrintf
cmp r0, r4
movne r0, #1
ldmneia sp!, {r3, r4, r5, r6, r7, pc}
@ -6241,7 +6241,7 @@ _021ED09C:
add r0, sp, #0x1a0
add r3, r5, #0x50
mov r1, #0x100
bl sub_020D168C
bl OS_SNPrintf
ldr r0, _021ED1D8 ; =_0221A768
ldr r4, [r0]
add r0, r4, #0x91
@ -6541,7 +6541,7 @@ ov00_021ED470: ; 0x021ED470
ldr r2, _021ED4A4 ; =_022179E0
mov r0, r4
mov r1, #0x1000
bl sub_020D168C
bl OS_SNPrintf
mov r0, r4
bl strlen
add sp, sp, #0xc
@ -11023,7 +11023,7 @@ _021F0FD4:
and r3, r1, #0xff
ldr r2, _021F10A4 ; =_02217A4C
mov r1, #5
bl sub_020D168C
bl OS_SNPrintf
ldr r8, [sb, #4]
bl ov00_021EF3A4
ldr r1, [r4, #8]
@ -13013,7 +13013,7 @@ _021F2C6C:
ldr r2, _021F2E34 ; =_02217A64
add r0, sp, #0x10
mov r1, #0xc
bl sub_020D168C
bl OS_SNPrintf
bl ov00_021F955C
mov r4, r0
bl ov00_021F955C
@ -13783,7 +13783,7 @@ ov00_021F36BC: ; 0x021F36BC
add r0, sp, #0x20
add r3, r1, #1
mov r1, #0xc
bl sub_020D168C
bl OS_SNPrintf
ldr r0, _021F3780 ; =_02217AA4
add r1, sp, #0x20
add r2, sp, #0
@ -13795,7 +13795,7 @@ ov00_021F36BC: ; 0x021F36BC
mov r1, #0xc
add r3, r2, #1
ldr r2, _021F377C ; =_02217A64
bl sub_020D168C
bl OS_SNPrintf
ldr r0, _021F3784 ; =_02217AA8
add r1, sp, #0x20
add r2, sp, #0
@ -13805,7 +13805,7 @@ ov00_021F36BC: ; 0x021F36BC
add r0, sp, #0x20
mov r1, #0xc
mov r3, #3
bl sub_020D168C
bl OS_SNPrintf
ldr r0, _021F3788 ; =_02217A70
add r1, sp, #0x20
add r2, sp, #0
@ -14280,7 +14280,7 @@ _021F3DB8:
add r0, r0, r1
ldr r2, _021F3EE4 ; =_02217AE4
rsb r1, r1, #0x100
bl sub_020D168C
bl OS_SNPrintf
b _021F3E44
_021F3E1C:
bl ov00_021F955C
@ -14291,7 +14291,7 @@ _021F3E24:
add r0, sp, #0xad
mov r1, #0x100
str r4, [sp]
bl sub_020D168C
bl OS_SNPrintf
bl ov00_021F955C
str r4, [r0, #0x204]
_021F3E44:
@ -14365,7 +14365,7 @@ ov00_021F3EF4: ; 0x021F3EF4
ldr r3, _021F3F58 ; =_02217ACC
mov r1, #0x100
str ip, [sp, #0x20]
bl sub_020D168C
bl OS_SNPrintf
add sp, sp, #0x24
ldmia sp!, {pc}
.balign 4, 0
@ -14676,7 +14676,7 @@ _021F4380:
ldr r2, _021F44C0 ; =_02217A64
add r0, sp, #0x20
mov r1, #0x200
bl sub_020D168C
bl OS_SNPrintf
mov r6, r0
cmp r8, #1
mov r7, #1
@ -14688,7 +14688,7 @@ _021F43B8:
ldr r2, _021F44C4 ; =_02217B50
mov r0, r5
mov r1, #0x10
bl sub_020D168C
bl OS_SNPrintf
mov r4, r0
add r0, r6, r4
add r0, r0, #1
@ -14852,7 +14852,7 @@ ov00_021F45E0: ; 0x021F45E0
add r0, sp, #8
mov r1, #0x200
str r4, [sp, #4]
bl sub_020D168C
bl OS_SNPrintf
mov r4, r0
add r2, sp, #8
add r1, sp, #9
@ -20350,7 +20350,7 @@ _021F9200:
ldr r2, _021F94D4 ; =_02217A64
add r0, sp, #0x10
mov r1, #0xc
bl sub_020D168C
bl OS_SNPrintf
bl ov00_021F955C
mov r4, r0
bl ov00_021F955C

View File

@ -23868,7 +23868,7 @@ ov13_0223A2B0: ; 0x0223A2B0
str r2, [sp, #4]
ldrb r2, [r3, #0x4c0]
ldrb r3, [r3, #0x4c1]
bl sub_020D164C
bl OS_SPrintf
add sp, sp, #8
ldmia sp!, {r3, pc}
.balign 4, 0
@ -23889,7 +23889,7 @@ ov13_0223A2F0: ; 0x0223A2F0
str r2, [sp, #4]
ldrb r2, [r3, #0x4f0]
ldrb r3, [r3, #0x4f1]
bl sub_020D164C
bl OS_SPrintf
add sp, sp, #8
ldmia sp!, {r3, pc}
.balign 4, 0
@ -23911,7 +23911,7 @@ ov13_0223A330: ; 0x0223A330
str r2, [sp, #4]
ldrb r2, [ip, #0x4c4]
ldrb r3, [r3, #0x401]
bl sub_020D164C
bl OS_SPrintf
add sp, sp, #8
ldmia sp!, {r3, pc}
.balign 4, 0
@ -23933,7 +23933,7 @@ ov13_0223A374: ; 0x0223A374
str r2, [sp, #4]
ldrb r2, [ip, #0x4c8]
ldrb r3, [r3, #0x401]
bl sub_020D164C
bl OS_SPrintf
add sp, sp, #8
ldmia sp!, {r3, pc}
.balign 4, 0
@ -23955,7 +23955,7 @@ ov13_0223A3B8: ; 0x0223A3B8
str r2, [sp, #4]
ldrb r2, [ip, #0x4cc]
ldrb r3, [r3, #0x401]
bl sub_020D164C
bl OS_SPrintf
add sp, sp, #8
ldmia sp!, {r3, pc}
.balign 4, 0
@ -30318,7 +30318,7 @@ _0223F770:
ldr r2, _0223F7FC ; =0x0224593C
str r0, [r3, #0x84]
add r0, sp, #0x20
bl sub_020D164C
bl OS_SPrintf
add r0, sp, #0x20
bl sub_020D8448
add sp, sp, #0xe8

View File

@ -5336,7 +5336,7 @@ ov38_02220810: ; 0x02220810
mov r3, #2
mov r1, #0x21
str r3, [sp]
bl sub_020D168C
bl OS_SNPrintf
ldmia sp!, {r3, pc}
.balign 4, 0
_0222082C: .word 0x02225E08

View File

@ -1963,7 +1963,7 @@ ov45_02232B24: ; 0x02232B24
ldr r2, [sp, #0x20]
mov r1, r4
add r3, r3, #4
bl sub_020D16B4
bl OS_VSNPrintf
add r0, sp, #0
bl ov45_02232B9C
mov r1, r0
@ -3154,7 +3154,7 @@ ov45_02233BC8: ; 0x02233BC8
add r3, r4, #4
str r0, [sp, #4]
str r0, [sp, #0xc]
bl sub_020D16B4
bl OS_VSNPrintf
ldr r3, [sp, #8]
add r5, r0, #1
cmp r5, r3
@ -3181,7 +3181,7 @@ _02233C4C:
ldr r2, [sp, #0x24]
mov r1, r5
add r3, r4, #4
bl sub_020D16B4
bl OS_VSNPrintf
ldr r1, [sp, #4]
add r0, sp, #4
add r1, r1, r5

View File

@ -0,0 +1,28 @@
#include <stdarg.h>
#include <nitro.h>
int OS_SPrintf(char * dest, const char * format, ...) {
int ret;
va_list va;
va_start(va, format);
ret = OS_VSPrintf(dest, format, va);
va_end(va);
return ret;
}
int OS_VSPrintf(char * dest, const char * format, va_list va) {
return OS_VSNPrintf(dest, 0x7FFFFFFF, format, va);
}
int OS_SNPrintf(char * dest, u32 len, const char * format, ...) {
int ret;
va_list va;
va_start(va, format);
ret = OS_VSNPrintf(dest, len, format, va);
va_end(va);
return ret;
}
int OS_VSNPrintf(char * dest, u32 len, const char * format, va_list va) {
return STD_TVSNPrintf(dest, len, format, va);
}

View File

@ -43,53 +43,6 @@ _021E167C:
.public OS_InitIrqTable
arm_func_start sub_020D164C
sub_020D164C: ; 0x020D164C
stmdb sp!, {r0, r1, r2, r3}
stmdb sp!, {r3, lr}
add r2, sp, #0xc
bic r2, r2, #3
ldr r1, [sp, #0xc]
add r2, r2, #4
bl sub_020D1674
ldmia sp!, {r3, lr}
add sp, sp, #0x10
bx lr
arm_func_end sub_020D164C
arm_func_start sub_020D1674
sub_020D1674: ; 0x020D1674
ldr ip, _020D1688 ; =sub_020D16B4
mov r3, r2
mov r2, r1
mvn r1, #0x80000000
bx ip
.align 2, 0
_020D1688: .word sub_020D16B4
arm_func_end sub_020D1674
arm_func_start sub_020D168C
sub_020D168C: ; 0x020D168C
stmdb sp!, {r0, r1, r2, r3}
stmdb sp!, {r3, lr}
add r3, sp, #0x10
bic r3, r3, #3
ldr r2, [sp, #0x10]
add r3, r3, #4
bl sub_020D16B4
ldmia sp!, {r3, lr}
add sp, sp, #0x10
bx lr
arm_func_end sub_020D168C
arm_func_start sub_020D16B4
sub_020D16B4: ; 0x020D16B4
ldr ip, _020D16BC ; =sub_020E3F44
bx ip
.align 2, 0
_020D16BC: .word sub_020E3F44
arm_func_end sub_020D16B4
arm_func_start sub_020D16C0
sub_020D16C0: ; 0x020D16C0
ldr r1, _020D16D4 ; =0x021E167C
@ -23192,8 +23145,8 @@ _020E3F28:
ldmia sp!, {r4, pc}
arm_func_end sub_020E3EEC
arm_func_start sub_020E3F44
sub_020E3F44: ; 0x020E3F44
arm_func_start STD_TVSNPrintf
STD_TVSNPrintf: ; 0x020E3F44
stmdb sp!, {r3, r4, r5, r6, r7, r8, sb, sl, fp, lr}
sub sp, sp, #0x30
mov sb, r2
@ -23817,7 +23770,7 @@ _020E47A8:
ldmia sp!, {r3, r4, r5, r6, r7, r8, sb, sl, fp, pc}
.align 2, 0
_020E47BC: .word 0xCCCCCCCD
arm_func_end sub_020E3F44
arm_func_end STD_TVSNPrintf
.rodata

View File

@ -8942,7 +8942,7 @@ sub_0209FE28: ; 0x0209FE28
mov r0, r5
mov r1, #0x15
add r3, sp, #0x29
bl sub_020D168C
bl OS_SNPrintf
add sp, sp, #0x40
ldmia sp!, {r4, r5, r6, pc}
.align 2, 0
@ -13289,7 +13289,7 @@ sub_020A35FC: ; 0x020A35FC
ldrb r3, [sp, #0xc]
str r3, [sp, #8]
ldrb r3, [sp, #0xf]
bl sub_020D168C
bl OS_SNPrintf
mov r0, r4
add sp, sp, #0x14
ldmia sp!, {r3, r4, pc}

View File

@ -7,5 +7,6 @@
#include <nitro/os.h>
#include <nitro/fs.h>
#include <nitro/mi.h>
#include <nitro/std.h>
#endif //NITRO_H_

View File

@ -9,5 +9,6 @@
#include <nitro/os/interrupt.h>
#include <nitro/os/systemCall.h>
#include <nitro/os/spinLock.h>
#include <nitro/os/printf.h>
#endif //NITRO_OS_H_

View File

@ -0,0 +1,12 @@
#ifndef NITRO_OS_PRINTF_H_
#define NITRO_OS_PRINTF_H_
#include <stdarg.h>
#include <nitro/std/string.h>
int OS_SPrintf(char * dest, const char * format, ...);
int OS_SNPrintf(char * dest, u32 len, const char * format, ...);
int OS_VSPrintf(char * dest, const char * format, va_list va);
int OS_VSNPrintf(char * dest, u32 len, const char * format, va_list va);
#endif //NITRO_OS_PRINTF_H_

6
lib/include/nitro/std.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef NITRO_STD_H_
#define NITRO_STD_H_
#include <nitro/std/string.h>
#endif //NITRO_STD_H_

View File

@ -0,0 +1,8 @@
#ifndef NITRO_STD_STRING_H_
#define NITRO_STD_STRING_H_
#include <stdarg.h>
int STD_TVSNPrintf(char * dest, u32 len, const char * format, va_list va);
#endif //NITRO_STD_STRING_H_

25
lib/include/stdarg.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef MSL_STDARG_H
#define MSL_STDARG_H
#ifdef __cplusplus
namespace std {
extern "C" {
#endif
#ifndef _MSL_VA_LIST_TYPE
#define _MSL_VA_LIST_TYPE char*
#endif //_MSL_VA_LIST_TYPE
#ifndef _MSL_VA_LIST_DEFINED
typedef _MSL_VA_LIST_TYPE va_list;
#define _MSL_VA_LIST_DEFINED
#endif
#define va_start(list, arg) ({ list = (va_list)(((u32)&(arg) & ~3) + 4); })
#define va_end(list) ((void)0)
#ifdef __cplusplus
}
}
#endif
#endif //MSL_STDARG_H

View File

@ -253,6 +253,7 @@ Static main
Object os_irqTable.o
Object os_interrupt.o
Object os_spinLock.o
Object os_printf.o
Object nitro.o
Object msl.o
}