diff --git a/Makefile b/Makefile index 35ebff72c..d38f53da3 100644 --- a/Makefile +++ b/Makefile @@ -194,7 +194,7 @@ $(B_DIR)/game.o: src/game/game.c python tools/asmpreproc/asm-processor.py -O2 $< | $(QEMU_IRIX) -silent -L $(IRIX_ROOT) $(IRIX_ROOT)/usr/bin/cc -c $(CFLAGS) tools/asmpreproc/include-stdin.c -o $@ -O2 python tools/asmpreproc/asm-processor.py -O2 $< --post-process $@ --assembler "$(TOOLCHAIN)-as -march=vr4300 -mabi=32" --asm-prelude tools/asmpreproc/prelude.s -$(B_DIR)/game.elf: $(B_DIR)/game.o $(B_DIR)/library.o $(B_DIR)/setup.o +$(B_DIR)/game.elf: $(B_DIR)/game.o $(B_DIR)/library.o $(B_DIR)/setup.o $(B_DIR)/gvars.o $(TOOLCHAIN)-ld -T ld/game.ld -o $@ $(B_DIR)/ucode/game.bin: $(B_DIR)/game.elf @@ -203,6 +203,23 @@ $(B_DIR)/ucode/game.bin: $(B_DIR)/game.elf dd if="$@" of="$@.tmp" bs=1808864 count=1 mv "$@.tmp" "$@" +################################################################################ +# gVars + +gvars: $(B_DIR)/ucode/gvars.bin + +$(B_DIR)/gvars.o: src/gvars.c + mkdir -p $(B_DIR)/ucode + python tools/asmpreproc/asm-processor.py -O2 $< | $(QEMU_IRIX) -silent -L $(IRIX_ROOT) $(IRIX_ROOT)/usr/bin/cc -c $(CFLAGS) tools/asmpreproc/include-stdin.c -o $@ -O2 + python tools/asmpreproc/asm-processor.py -O2 $< --post-process $@ --assembler "$(TOOLCHAIN)-as -march=vr4300 -mabi=32" --asm-prelude tools/asmpreproc/prelude.s + +$(B_DIR)/gvars.elf: $(B_DIR)/gvars.o + $(TOOLCHAIN)-ld -T ld/gvars.ld -o $@ + +$(B_DIR)/ucode/gvars.bin: $(B_DIR)/gvars.elf + mkdir -p $(B_DIR)/ucode + $(TOOLCHAIN)-objcopy $< $@ -O binary + ################################################################################ # Test related diff --git a/ld/game.ld b/ld/game.ld index 00178f72f..275d9d3ec 100644 --- a/ld/game.ld +++ b/ld/game.ld @@ -18,6 +18,11 @@ SECTIONS build/ntsc-final/setup.o (.data); } + .gvars 0x80099fc0 : AT(SIZEOF(.game) + SIZEOF(.library) + SIZEOF(.setup)) { + build/ntsc-final/gvars.o (.text); + build/ntsc-final/gvars.o (.data); + } + /DISCARD/ : { * (.MIPS.abiflags); * (.options); @@ -27,6 +32,5 @@ SECTIONS * (.gptab.bss); * (.gptab.data); * (.reginfo); - * (.setup.data); } } diff --git a/ld/gvars.ld b/ld/gvars.ld new file mode 100644 index 000000000..da5193447 --- /dev/null +++ b/ld/gvars.ld @@ -0,0 +1,22 @@ +/*OUTPUT_FORMAT ("elf32-bigmips")*/ +OUTPUT_ARCH (mips) + +SECTIONS +{ + .gvars 0x80099fc0 : AT(0) { + build/ntsc-final/gvars.o (.text); + build/ntsc-final/gvars.o (.data); + } + + /DISCARD/ : { + * (.MIPS.abiflags); + * (.options); + * (.gnu.attributes); + * (.pdr); + * (.mdebug); + * (.gptab.bss); + * (.gptab.data); + * (.reginfo); + * (.setup.data); + } +} diff --git a/src/game/game.c b/src/game/game.c index d06a964c4..d85ccf7d9 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -1,4 +1,6 @@ -#include +#include "ultra64.h" +#include "src/include/constants.h" +#include "src/include/gvars.h" GLOBAL_ASM( glabel func0f000000 @@ -87881,16 +87883,11 @@ glabel func0f04dbfc /** * @cmd 0002 */ -GLOBAL_ASM( -glabel func0f04dc3c -/* f04dc3c: 3c03800a */ lui $v1,0x800a -/* f04dc40: 24639fc0 */ addiu $v1,$v1,-24640 -/* f04dc44: 8c6e0438 */ lw $t6,0x438($v1) -/* f04dc48: 00001025 */ or $v0,$zero,$zero -/* f04dc4c: 25cf0003 */ addiu $t7,$t6,0x3 -/* f04dc50: 03e00008 */ jr $ra -/* f04dc54: ac6f0438 */ sw $t7,0x438($v1) -); +bool aiLabel(void) +{ + g_Vars.aioffset += 3; + return false; +} /** * @cmd 0003 diff --git a/src/gvars.c b/src/gvars.c new file mode 100644 index 000000000..185fa9fa5 --- /dev/null +++ b/src/gvars.c @@ -0,0 +1,11 @@ +#include "ultra64.h" +#include "src/include/gvars.h" + +/** + * This is a workaround for me not being to figure out why ld is ignoring the + * memory address location in game.ld. It puts gvars immediately after setup, + * which means it comes 0xf1a0 earlier than it should. So we pad it out here. + */ +u8 padding[0xf1a0]; + +struct g_vars g_Vars; diff --git a/src/include/constants.h b/src/include/constants.h index 2fb348949..3083d5165 100644 --- a/src/include/constants.h +++ b/src/include/constants.h @@ -1,6 +1,11 @@ #define FALSE 0 #define TRUE 1 +#define false 0 +#define true 1 + +#define bool u8 + #define ACTION_SCAN 0x01 #define ACTION_UNDER_COVER 0x02 #define ACTION_GRENADE_STOP 0x03 diff --git a/src/include/gvars.h b/src/include/gvars.h new file mode 100644 index 000000000..e8febe581 --- /dev/null +++ b/src/include/gvars.h @@ -0,0 +1,343 @@ +#include "ultra64.h" + +struct g_vars { + // Known member names based on debug strings: + //g_Vars.PaksNeedsReInit + //g_Vars.FourMeg2Player + //g_Vars.playersperm[0] + //g_Vars.playersperm[1] + //g_Vars.PropState.propznum + //g_Vars.PropState + //g_Vars.antiplayernum + //g_Vars.antiradaron + //g_Vars.antibodynum + //g_Vars.antiheadnum + //g_Vars.coopfriendlyfire + //g_Vars.coopradaron + + /*0000*/ u32 unk0000; + /*0004*/ u32 unk0004; + /*0008*/ u32 unk0008; + /*000c*/ u32 unk000c; + /*0010*/ u32 unk0010; + /*0014*/ u32 unk0014; + /*0018*/ u32 unk0018; + /*001c*/ u32 unk001c; + /*0020*/ u32 unk0020; + /*0024*/ u32 unk0024; + /*0028*/ u32 unk0028; + /*002c*/ u32 unk002c; + /*0030*/ u32 unk0030; + /*0034*/ u32 unk0034; + /*0038*/ u32 unk0038; + /*003c*/ u32 unk003c; + /*0040*/ u32 unk0040; + /*0044*/ u32 unk0044; + /*0048*/ u32 unk0048; + /*004c*/ u32 unk004c; + /*0050*/ u32 unk0050; + /*0054*/ u32 unk0054; + /*0058*/ u32 unk0058; + /*005c*/ u32 unk005c; + /*0060*/ u32 unk0060; + /*0064*/ u32 unk0064; + /*0068*/ u32 unk0068; + /*006c*/ u32 unk006c; + /*0070*/ u32 unk0070; + /*0074*/ u32 unk0074; + /*0078*/ u32 unk0078; + /*007c*/ u32 unk007c; + /*0080*/ u32 unk0080; + /*0084*/ u32 unk0084; + /*0088*/ u32 unk0088; + /*008c*/ u32 unk008c; + /*0090*/ u32 unk0090; + /*0094*/ u32 unk0094; + /*0098*/ u32 unk0098; + /*009c*/ u32 unk009c; + /*00a0*/ u32 unk00a0; + /*00a4*/ u32 unk00a4; + /*00a8*/ u32 unk00a8; + /*00ac*/ u32 unk00ac; + /*00b0*/ u32 unk00b0; + /*00b4*/ u32 unk00b4; + /*00b8*/ u32 unk00b8; + /*00bc*/ u32 unk00bc; + /*00c0*/ u32 unk00c0; + /*00c4*/ u32 unk00c4; + /*00c8*/ u32 unk00c8; + /*00cc*/ u32 unk00cc; + /*00d0*/ u32 unk00d0; + /*00d4*/ u32 unk00d4; + /*00d8*/ u32 unk00d8; + /*00dc*/ u32 unk00dc; + /*00e0*/ u32 unk00e0; + /*00e4*/ u32 unk00e4; + /*00e8*/ u32 unk00e8; + /*00ec*/ u32 unk00ec; + /*00f0*/ u32 unk00f0; + /*00f4*/ u32 unk00f4; + /*00f8*/ u32 unk00f8; + /*00fc*/ u32 unk00fc; + /*0100*/ u32 unk0100; + /*0104*/ u32 unk0104; + /*0108*/ u32 unk0108; + /*010c*/ u32 unk010c; + /*0110*/ u32 unk0110; + /*0114*/ u32 unk0114; + /*0118*/ u32 unk0118; + /*011c*/ u32 unk011c; + /*0120*/ u32 unk0120; + /*0124*/ u32 unk0124; + /*0128*/ u32 unk0128; + /*012c*/ u32 unk012c; + /*0130*/ u32 unk0130; + /*0134*/ u32 unk0134; + /*0138*/ u32 unk0138; + /*013c*/ u32 unk013c; + /*0140*/ u32 unk0140; + /*0144*/ u32 unk0144; + /*0148*/ u32 unk0148; + /*014c*/ u32 unk014c; + /*0150*/ u32 unk0150; + /*0154*/ u32 unk0154; + /*0158*/ u32 unk0158; + /*015c*/ u32 unk015c; + /*0160*/ u32 unk0160; + /*0164*/ u32 unk0164; + /*0168*/ u32 unk0168; + /*016c*/ u32 unk016c; + /*0170*/ u32 unk0170; + /*0174*/ u32 unk0174; + /*0178*/ u32 unk0178; + /*017c*/ u32 unk017c; + /*0180*/ u32 unk0180; + /*0184*/ u32 unk0184; + /*0188*/ u32 unk0188; + /*018c*/ u32 unk018c; + /*0190*/ u32 unk0190; + /*0194*/ u32 unk0194; + /*0198*/ u32 unk0198; + /*019c*/ u32 unk019c; + /*01a0*/ u32 unk01a0; + /*01a4*/ u32 unk01a4; + /*01a8*/ u32 unk01a8; + /*01ac*/ u32 unk01ac; + /*01b0*/ u32 unk01b0; + /*01b4*/ u32 unk01b4; + /*01b8*/ u32 unk01b8; + /*01bc*/ u32 unk01bc; + /*01c0*/ u32 unk01c0; + /*01c4*/ u32 unk01c4; + /*01c8*/ u32 unk01c8; + /*01cc*/ u32 unk01cc; + /*01d0*/ u32 unk01d0; + /*01d4*/ u32 unk01d4; + /*01d8*/ u32 unk01d8; + /*01dc*/ u32 unk01dc; + /*01e0*/ u32 unk01e0; + /*01e4*/ u32 unk01e4; + /*01e8*/ u32 unk01e8; + /*01ec*/ u32 unk01ec; + /*01f0*/ u32 unk01f0; + /*01f4*/ u32 unk01f4; + /*01f8*/ u32 unk01f8; + /*01fc*/ u32 unk01fc; + /*0200*/ u32 unk0200; + /*0204*/ u32 unk0204; + /*0208*/ u32 unk0208; + /*020c*/ u32 unk020c; + /*0210*/ u32 unk0210; + /*0214*/ u32 unk0214; + /*0218*/ u32 unk0218; + /*021c*/ u32 unk021c; + /*0220*/ u32 unk0220; + /*0224*/ u32 unk0224; + /*0228*/ u32 unk0228; + /*022c*/ u32 unk022c; + /*0230*/ u32 unk0230; + /*0234*/ u32 unk0234; + /*0238*/ u32 unk0238; + /*023c*/ u32 unk023c; + /*0240*/ u32 unk0240; + /*0244*/ u32 unk0244; + /*0248*/ u32 unk0248; + /*024c*/ u32 unk024c; + /*0250*/ u32 unk0250; + /*0254*/ u32 unk0254; + /*0258*/ u32 unk0258; + /*025c*/ u32 unk025c; + /*0260*/ u32 unk0260; + /*0264*/ u32 unk0264; + /*0268*/ u32 unk0268; + /*026c*/ u32 unk026c; + /*0270*/ u32 unk0270; + /*0274*/ u32 unk0274; + /*0278*/ u32 unk0278; + /*027c*/ u32 unk027c; + /*0280*/ u32 unk0280; + /*0284*/ u32 unk0284; + /*0288*/ u32 unk0288; + /*028c*/ u32 unk028c; + /*0290*/ u32 unk0290; + /*0294*/ u32 unk0294; + /*0298*/ u32 unk0298; + /*029c*/ u32 unk029c; + /*02a0*/ u32 unk02a0; + /*02a4*/ u32 unk02a4; + /*02a8*/ u32 unk02a8; + /*02ac*/ u32 unk02ac; + /*02b0*/ u32 unk02b0; + /*02b4*/ u32 unk02b4; + /*02b8*/ u32 unk02b8; + /*02bc*/ u32 unk02bc; + /*02c0*/ u32 unk02c0; + /*02c4*/ u32 unk02c4; + /*02c8*/ u32 unk02c8; + /*02cc*/ u32 unk02cc; + /*02d0*/ u32 unk02d0; + /*02d4*/ u32 unk02d4; + /*02d8*/ u32 unk02d8; + /*02dc*/ u32 unk02dc; + /*02e0*/ u32 unk02e0; + /*02e4*/ u32 unk02e4; + /*02e8*/ u32 unk02e8; + /*02ec*/ u32 unk02ec; + /*02f0*/ u32 unk02f0; + /*02f4*/ u32 unk02f4; + /*02f8*/ u32 unk02f8; + /*02fc*/ u32 unk02fc; + /*0300*/ u32 unk0300; + /*0304*/ u32 unk0304; + /*0308*/ u32 unk0308; + /*030c*/ u32 unk030c; + /*0310*/ u32 unk0310; + /*0314*/ u32 unk0314; + /*0318*/ u32 unk0318; + /*031c*/ u32 unk031c; + /*0320*/ u32 unk0320; + /*0324*/ u32 unk0324; + /*0328*/ u32 unk0328; + /*032c*/ u32 unk032c; + /*0330*/ u32 unk0330; + /*0334*/ u32 unk0334; + /*0338*/ u32 unk0338; + /*033c*/ u32 unk033c; + /*0340*/ u32 unk0340; + /*0344*/ u32 unk0344; + /*0348*/ u32 unk0348; + /*034c*/ u32 unk034c; + /*0350*/ u32 unk0350; + /*0354*/ u32 unk0354; + /*0358*/ u32 unk0358; + /*035c*/ u32 unk035c; + /*0360*/ u32 unk0360; + /*0364*/ u32 unk0364; + /*0368*/ u32 unk0368; + /*036c*/ u32 unk036c; + /*0370*/ u32 unk0370; + /*0374*/ u32 unk0374; + /*0378*/ u32 unk0378; + /*037c*/ u32 unk037c; + /*0380*/ u32 unk0380; + /*0384*/ u32 unk0384; + /*0388*/ u32 unk0388; + /*038c*/ u32 unk038c; + /*0390*/ u32 unk0390; + /*0394*/ u32 unk0394; + /*0398*/ u32 unk0398; + /*039c*/ u32 unk039c; + /*03a0*/ u32 unk03a0; + /*03a4*/ u32 unk03a4; + /*03a8*/ u32 unk03a8; + /*03ac*/ u32 unk03ac; + /*03b0*/ u32 unk03b0; + /*03b4*/ u32 unk03b4; + /*03b8*/ u32 unk03b8; + /*03bc*/ u32 unk03bc; + /*03c0*/ u32 unk03c0; + /*03c4*/ u32 unk03c4; + /*03c8*/ u32 unk03c8; + /*03cc*/ u32 unk03cc; + /*03d0*/ u32 unk03d0; + /*03d4*/ u32 unk03d4; + /*03d8*/ u32 unk03d8; + /*03dc*/ u32 unk03dc; + /*03e0*/ u32 unk03e0; + /*03e4*/ u32 unk03e4; + /*03e8*/ u32 unk03e8; + /*03ec*/ u32 unk03ec; + /*03f0*/ u32 unk03f0; + /*03f4*/ u32 unk03f4; + /*03f8*/ u32 unk03f8; + /*03fc*/ u32 unk03fc; + /*0400*/ u32 unk0400; + /*0404*/ u32 unk0404; + /*0408*/ u32 unk0408; + /*040c*/ u32 unk040c; + /*0410*/ u32 unk0410; + /*0414*/ u32 unk0414; + /*0418*/ u32 unk0418; + /*041c*/ u32 unk041c; + /*0420*/ u32 unk0420; + /*0424*/ u32 unk0424; + /*0428*/ u32 unk0428; + /*042c*/ u32 unk042c; + /*0430*/ u32 unk0430; + /*0434*/ u32 unk0434; + /*0438*/ u32 aioffset; + /*043c*/ u32 unk043c; + /*0440*/ u32 unk0440; + /*0444*/ u32 unk0444; + /*0448*/ u32 unk0448; + /*044c*/ u32 unk044c; + /*0450*/ u32 unk0450; + /*0454*/ u32 unk0454; + /*0458*/ u32 unk0458; + /*045c*/ u32 unk045c; + /*0460*/ u32 unk0460; + /*0464*/ u32 unk0464; + /*0468*/ u32 unk0468; + /*046c*/ u32 unk046c; + /*0470*/ u32 unk0470; + /*0474*/ u32 unk0474; + /*0478*/ u32 unk0478; + /*047c*/ u32 unk047c; + /*0480*/ u32 unk0480; + /*0484*/ u32 unk0484; + /*0488*/ u32 unk0488; + /*048c*/ u32 unk048c; + /*0490*/ u32 unk0490; + /*0494*/ u32 unk0494; + /*0498*/ u32 unk0498; + /*049c*/ u32 unk049c; + /*04a0*/ u32 unk04a0; + /*04a4*/ u32 unk04a4; + /*04a8*/ u32 unk04a8; + /*04ac*/ u32 unk04ac; + /*04b0*/ u32 unk04b0; + /*04b4*/ u32 unk04b4; + /*04b8*/ u32 unk04b8; + /*04bc*/ u32 unk04bc; + /*04c0*/ u32 unk04c0; + /*04c4*/ u32 unk04c4; + /*04c8*/ u32 unk04c8; + /*04cc*/ u32 unk04cc; + /*04d0*/ u32 unk04d0; + /*04d4*/ u32 unk04d4; + /*04d8*/ u32 unk04d8; + /*04dc*/ u32 unk04dc; + /*04e0*/ u32 unk04e0; + /*04e4*/ u32 unk04e4; + /*04e8*/ u32 unk04e8; + /*04ec*/ u32 unk04ec; + /*04f0*/ u32 unk04f0; + /*04f4*/ u32 unk04f4; + /*04f8*/ u32 unk04f8; + /*04fc*/ u32 unk04fc; + /*0500*/ u32 unk0500[0x87a6]; + + // len 0x22398 +}; + +extern struct g_vars g_Vars;