diff options
| author | Prakxo <87568477+Prakxo@users.noreply.github.com> | 2023-08-15 18:21:42 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-15 10:21:42 -0700 |
| commit | a2deca64d24427d6856dc5e7fc43bde4b1641a43 (patch) | |
| tree | b6566ff3648a5fdab02c57c21b1bb9fab1294ccd | |
| parent | f19df74c6ee597f01c3d7def1fdef105d9bdef92 (diff) | |
aprintf OK (#51)
* m_pause OK
* yeah now it's OK lol
* refactor
* refactor 2
* m_controller OK
* format
* fix size comment in game
* refactor 3
* refactor 4
* refactor 5
* add unused macro
* aprintf OK
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | include/libc/stdarg.h | 46 | ||||
| -rw-r--r-- | include/libc64/aprintf.h | 7 | ||||
| -rw-r--r-- | src/boot/libc64/aprintf.c | 17 | ||||
| -rw-r--r-- | yamls/jp/boot.yaml | 2 |
5 files changed, 70 insertions, 4 deletions
@@ -109,7 +109,7 @@ SPLAT_YAML ?= $(TARGET).$(VERSION).yaml IINC := -Iinclude -Isrc -Ibin/$(VERSION) -I. -IINC += -Ilib/ultralib/include -Ilib/ultralib/include/PR +IINC += -Ilib/ultralib/include -Ilib/ultralib/include/PR -Ilib/ultralib/include/ido ifeq ($(KEEP_MDEBUG),0) RM_MDEBUG = $(OBJCOPY) --remove-section .mdebug $@ diff --git a/include/libc/stdarg.h b/include/libc/stdarg.h new file mode 100644 index 0000000..77b8b88 --- /dev/null +++ b/include/libc/stdarg.h @@ -0,0 +1,46 @@ +#ifndef STDARG_H +#define STDARG_H + +#include "ultra64.h" + +// When building with GCC, use the official vaarg macros to avoid warnings +// and possibly bad codegen. +#ifdef __GNUC__ +#define va_list __builtin_va_list +#define va_start __builtin_va_start +#define va_arg __builtin_va_arg +#define va_end __builtin_va_end +#else + +typedef char *va_list; +#define _FP 1 +#define _INT 0 +#define _STRUCT 2 + +#define _VA_FP_SAVE_AREA 0x10 +#define _VA_ALIGN(p, a) (((unsigned int)(((char *)p) + ((a) > 4 ? (a) : 4) - 1)) & -((a) > 4 ? (a) : 4)) +#define va_start(vp, parmN) (vp = ((va_list)&parmN + sizeof(parmN))) + +#define __va_stack_arg(list, mode) \ + ( \ + ((list) = (char *)_VA_ALIGN(list, __builtin_alignof(mode)) + \ + _VA_ALIGN(sizeof(mode), 4)), \ + (((char *)list) - (_VA_ALIGN(sizeof(mode), 4) - sizeof(mode)))) + +#define __va_double_arg(list, mode) \ + ( \ + (((long)list & 0x1) /* 1 byte aligned? */ \ + ? (list = (char *)((long)list + 7), (char *)((long)list - 6 - _VA_FP_SAVE_AREA)) \ + : (((long)list & 0x2) /* 2 byte aligned? */ \ + ? (list = (char *)((long)list + 10), (char *)((long)list - 24 - _VA_FP_SAVE_AREA)) \ + : __va_stack_arg(list, mode)))) + +#define va_arg(list, mode) ((mode *)(((__builtin_classof(mode) == _FP && \ + __builtin_alignof(mode) == sizeof(double)) \ + ? __va_double_arg(list, mode) \ + : __va_stack_arg(list, mode))))[-1] +#define va_end(__list) + +#endif /* __GNUC__ */ + +#endif /* STDARG_H */ diff --git a/include/libc64/aprintf.h b/include/libc64/aprintf.h index 282caa3..2477117 100644 --- a/include/libc64/aprintf.h +++ b/include/libc64/aprintf.h @@ -2,8 +2,11 @@ #define LIBC64_APRINTF_H #include "ultra64.h" +#include "lib/ultralib/src/libc/xstdio.h" -// void vaprintf(); -// void aprintf(); +typedef void* (*PrintCallback)(void*, const char*, size_t); + +s32 vaprintf(PrintCallback* pfn, const char* fmt, va_list ap); +s32 aprintf(PrintCallback* func, const char* fmt, ...); #endif diff --git a/src/boot/libc64/aprintf.c b/src/boot/libc64/aprintf.c new file mode 100644 index 0000000..f2bc0c1 --- /dev/null +++ b/src/boot/libc64/aprintf.c @@ -0,0 +1,17 @@ +#include "libc64/aprintf.h" + +s32 vaprintf(PrintCallback* func, const char* fmt, va_list ap) { + return _Printf((outfun*)*func, (char*)func, fmt, ap); +} + +s32 aprintf(PrintCallback* func, const char* fmt, ...) { + s32 ret; + va_list args; + va_start(args, fmt); + + ret = vaprintf(func, fmt, args); + + va_end(args); + + return ret; +} diff --git a/yamls/jp/boot.yaml b/yamls/jp/boot.yaml index 09c82fa..a2b2ff3 100644 --- a/yamls/jp/boot.yaml +++ b/yamls/jp/boot.yaml @@ -38,7 +38,7 @@ - [0x007D70, asm, boot/libc64/qrand] - [0x007F30, c, boot/libc64/__osMalloc] - [0x008C50, asm, boot/libc64/sprintf] - - [0x008D20, asm, boot/libc64/aprintf] + - [0x008D20, c, boot/libc64/aprintf] - [0x008D80, asm, boot/libc64/sleep] # libultra |
