diff --git a/Makefile b/Makefile index b9d26d2a5..42186ce22 100644 --- a/Makefile +++ b/Makefile @@ -116,6 +116,7 @@ CFLAGS = -DVERSION=$(VERSION) \ -woff 581,649,819,820,821,838,852 \ -w2 \ -I src/include \ + $(OPT_LVL) \ $(MIPSISET) C_FILES := $(shell find src/gvars src/boot src/lib src/game src/inflate src/mpconfigs src/mpstrings/$(ROMID) src/firingrange src/filenames src/textureconfig -name '*.c') @@ -332,7 +333,7 @@ $(B_DIR)/files/G%Z: $(E_DIR)/files/G%Z # Lang $(B_DIR)/files/lang/L%.o: src/files/lang/$(ROMID)/%.c @mkdir -p $(B_DIR)/files/lang - $(IDOCC) -c $(CFLAGS) $< -o $@ $(OPT_LVL) + $(IDOCC) -c $(CFLAGS) $< -o $@ $(B_DIR)/files/L%.elf: $(B_DIR)/files/lang/L%.o TOOLCHAIN=$(TOOLCHAIN) tools/mksimpleelf $< $@ @@ -394,37 +395,37 @@ $(B_DIR)/copyright.o: $(B_DIR)/copyright.bin $(B_DIR)/boot/%.o: src/boot/%.c @mkdir -p $(dir $@) - /usr/bin/env python3 tools/asmpreproc/asm-processor.py -O2 $< | $(IDOCC) -c $(CFLAGS) tools/asmpreproc/include-stdin.c -o $@ $(OPT_LVL) + /usr/bin/env python3 tools/asmpreproc/asm-processor.py -O2 $< | $(IDOCC) -c $(CFLAGS) tools/asmpreproc/include-stdin.c -o $@ /usr/bin/env python3 tools/asmpreproc/asm-processor.py -O2 $< --post-process $@ --assembler "$(TOOLCHAIN)-as -march=vr4300 -mabi=32" --asm-prelude tools/asmpreproc/prelude.s $(B_DIR)/lib/ultra/libc/llcvt.o: src/lib/ultra/libc/llcvt.c @mkdir -p $(dir $@) - /usr/bin/env python3 tools/asmpreproc/asm-processor.py -O2 $< | $(IDOCC) -c $(CFLAGS) tools/asmpreproc/include-stdin.c -o $@ $(OPT_LVL) + /usr/bin/env python3 tools/asmpreproc/asm-processor.py -O2 $< | $(IDOCC) -c $(CFLAGS) tools/asmpreproc/include-stdin.c -o $@ /usr/bin/env python3 tools/asmpreproc/asm-processor.py -O2 $< --post-process $@ --assembler "$(TOOLCHAIN)-as -march=vr4300 -mabi=32" --asm-prelude tools/asmpreproc/prelude.s tools/patchmips3 $@ || rm $@ $(B_DIR)/lib/ultra/libc/ll.o: src/lib/ultra/libc/ll.c @mkdir -p $(dir $@) - $(IDOCC) -c $(CFLAGS) $< -o $@ $(OPT_LVL) + $(IDOCC) -c $(CFLAGS) $< -o $@ tools/patchmips3 $@ || rm $@ $(B_DIR)/lib/%.o: src/lib/%.c @mkdir -p $(dir $@) - /usr/bin/env python3 tools/asmpreproc/asm-processor.py -O2 $< | $(IDOCC) -c $(CFLAGS) tools/asmpreproc/include-stdin.c -o $@ $(OPT_LVL) + /usr/bin/env python3 tools/asmpreproc/asm-processor.py -O2 $< | $(IDOCC) -c $(CFLAGS) tools/asmpreproc/include-stdin.c -o $@ /usr/bin/env python3 tools/asmpreproc/asm-processor.py -O2 $< --post-process $@ --assembler "$(TOOLCHAIN)-as -march=vr4300 -mabi=32" --asm-prelude tools/asmpreproc/prelude.s $(B_DIR)/game/%.o: src/game/%.c @mkdir -p $(dir $@) - /usr/bin/env python3 tools/asmpreproc/asm-processor.py -O2 $< | $(IDOCC) -c $(CFLAGS) tools/asmpreproc/include-stdin.c -o $@ $(OPT_LVL) + /usr/bin/env python3 tools/asmpreproc/asm-processor.py -O2 $< | $(IDOCC) -c $(CFLAGS) tools/asmpreproc/include-stdin.c -o $@ /usr/bin/env python3 tools/asmpreproc/asm-processor.py -O2 $< --post-process $@ --assembler "$(TOOLCHAIN)-as -march=vr4300 -mabi=32" --asm-prelude tools/asmpreproc/prelude.s $(B_DIR)/%.o: src/%.c @mkdir -p $(dir $@) - $(IDOCC) -c $(CFLAGS) $< -o $@ $(OPT_LVL) + $(IDOCC) -c $(CFLAGS) $< -o $@ $(B_DIR)/%.o: src/%.s @mkdir -p $(dir $@) - $(IDOAS) $(CFLAGS) $< -o $@ $(OPT_LVL) + $(IDOAS) $(CFLAGS) $< -o $@ extract: ROMID=$(ROMID) tools/extract diff --git a/src/include/PR/os_libc.h b/src/include/PR/os_libc.h index 9e47c45c0..5418a4820 100644 --- a/src/include/PR/os_libc.h +++ b/src/include/PR/os_libc.h @@ -21,7 +21,7 @@ /*---------------------------------------------------------------------* Copyright (C) 1998 Nintendo. (Originated by SGI) - + $RCSfile: os_libc.h,v $ $Revision: 1.3 $ $Date: 1999/07/13 01:43:47 $ diff --git a/src/include/PR/os_misc.h b/src/include/PR/os_misc.h index b6755f370..cddbf366e 100644 --- a/src/include/PR/os_misc.h +++ b/src/include/PR/os_misc.h @@ -63,6 +63,36 @@ typedef struct { /* 34 */ char length; } printf_struct; +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) + /* Miscellaneous OS functions */ void osInitialize(void); diff --git a/src/lib/ultra/libc/sprintf.c b/src/lib/ultra/libc/sprintf.c index 956188ca8..88c42906e 100644 --- a/src/lib/ultra/libc/sprintf.c +++ b/src/lib/ultra/libc/sprintf.c @@ -32,3 +32,21 @@ glabel sprintf /* 13708: 00000000 */ nop /* 1370c: 00000000 */ nop ); + +// Mismatch: +// Goal takes v0 from _Printf and copies it to v1 but leaves v0 unmodified. +// The below copies v0 to v1 then back to v0 for the return. +//int sprintf(char *dst, const char *fmt, ...) +//{ +// int ans; +// va_list ap; +// +// va_start(ap, fmt); +// ans = _Printf(proutSprintf, dst, fmt, ap); +// +// if (ans >= 0) { +// dst[ans] = 0; +// } +// +// return ans; +//}