Skip to content

Commit

Permalink
refresh 4
Browse files Browse the repository at this point in the history
  • Loading branch information
n64 committed Dec 2, 2019
1 parent a7c423c commit 04732af
Show file tree
Hide file tree
Showing 729 changed files with 21,676 additions and 37,386 deletions.
30 changes: 30 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
Refresh #4
1.) Label screen_transition.c (#737)
2.) Revamp macros (#738)
3.) Simplify the cake makefile logic (#739)
4.) Move zbuffer to C (#742)
5.) Audio blob endian/64-bit fixes (#740)
6.) Ub fixes (#745)
7.) process_level_music_dynamics: slightly better stack and regalloc (#746)
8.) move level order specific definitions out to levels/level_defines.h (#743)
9.) Renamed some mislabelled sound effects (#748)
10.) Very minor white space fixes in Mario.c (#752)
11.) Renamed GRAVITY to OBJ_PHYSICS (#755)
12.) Use defined macros instead of literal values for interactions in behavior_data.c (#754)
13.) iQue Player console detection + full support (#756)
14.) Fix Goddard Mario head for little endian etc. (#757)
15.) Small bits of audio doc (#749)
16.) Update diff script (#750)
17.) Nicer format for course/dialog text, enum for dialog IDs (#753)
18.) first-diff: store most recent mtime during check (#759)
19.) Use Lights1 struct for light values (#760)
20.) Detect mips64-elf in diff.py (#761)
21.) Name display lists in gd renderer.c (#764)
22.) Document a variety of PU type crashes. (#765)
23.) Label object_behaviors. (#716)
24.) Update swoop.inc.c (#767)
25.) Label tilting_pyramid.inc.c (#768)
26.) Label red_coin.inc.c (#770)
27.) Use more level defines (#758)
28.) Named Mario actions 6, 7, and 8 and noted causes of hands-free holding glitch (#769)

Refresh #3
1.) Small bits of sound sample labelling
2.) Append 'b' to fopen calls in n64graphics to satisfy Windows
Expand Down
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -2089,7 +2089,7 @@ INCLUDE_FILE_PATTERNS =
# recursively expanded use the := operator instead of the = operator.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

PREDEFINED = NON_MATCHING
PREDEFINED = NON_MATCHING AVOID_UB

# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
# tag can be used to specify a list of macro names that should be expanded. The
Expand Down
10 changes: 0 additions & 10 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ pipeline {
sh 'make -j4 VERSION=us'
}
}
stage('Build J Source, NON_MATCHING') {
steps {
sh 'make -j4 VERSION=jp NON_MATCHING=1'
}
}
stage('Build U Source, NON_MATCHING') {
steps {
sh 'make -j4 VERSION=us NON_MATCHING=1'
}
}
}
environment {
QEMU_IRIX = credentials('qemu-irix')
Expand Down
123 changes: 75 additions & 48 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,39 @@ default: all

### Build Options ###

# These options can either be changed by modifying the makefile, or
# by building with 'make SETTING=value'. 'make clean' may be required.

# Version of the game to build
VERSION ?= us
# Graphics microcode used
GRUCODE ?= f3d_old
# If COMPARE is 1, check the output sha1sum when building 'all'
COMPARE ?= 1
# If NON_MATCHING is 1, define the NON_MATCHING macro when building
# If NON_MATCHING is 1, define the NON_MATCHING and AVOID_UB macros when building (recommended)
NON_MATCHING ?= 0
# If ENDIAN_IND is 1, enable non-matching code changes that try to ensure
# endianness independence
ENDIAN_IND ?= 0
# Build for the N64 (turn this off for ports)
TARGET_N64 ?= 1

# Release

ifeq ($(VERSION),jp)
VERSION_CFLAGS := -DVERSION_JP=1
VERSION_CFLAGS := -DVERSION_JP
VERSION_ASFLAGS := --defsym VERSION_JP=1
GRUCODE_CFLAGS := -DF3D_OLD
GRUCODE_ASFLAGS := --defsym F3D_OLD=1
TARGET := sm64.jp
else
ifeq ($(VERSION),us)
VERSION_CFLAGS := -DVERSION_US=1
VERSION_CFLAGS := -DVERSION_US
VERSION_ASFLAGS := --defsym VERSION_US=1
GRUCODE_CFLAGS := -DF3D_OLD
GRUCODE_ASFLAGS := --defsym F3D_OLD=1
TARGET := sm64.us
else
ifeq ($(VERSION),eu)
$(warning Building EU is experimental and is prone to breaking. Try at your own risk.)
VERSION_CFLAGS := -DVERSION_EU=1
VERSION_CFLAGS := -DVERSION_EU
VERSION_ASFLAGS := --defsym VERSION_EU=1
GRUCODE_CFLAGS := -DF3D_NEW
GRUCODE_ASFLAGS := --defsym F3D_NEW=1
Expand All @@ -50,13 +52,13 @@ endif
# Microcode

ifeq ($(GRUCODE),f3dex) # Fast3DEX
GRUCODE_CFLAGS := -DF3DEX_GBI=1
GRUCODE_CFLAGS := -DF3DEX_GBI
GRUCODE_ASFLAGS := --defsym F3DEX_GBI_SHARED=1 --defsym F3DEX_GBI=1
TARGET := $(TARGET).f3dex
COMPARE := 0
else
ifeq ($(GRUCODE), f3dex2) # Fast3DEX2
GRUCODE_CFLAGS := -DF3DEX_GBI_2=1
GRUCODE_CFLAGS := -DF3DEX_GBI_2
GRUCODE_ASFLAGS := --defsym F3DEX_GBI_SHARED=1 --defsym F3DEX_GBI_2=1
TARGET := $(TARGET).f3dex2
COMPARE := 0
Expand All @@ -69,7 +71,7 @@ ifeq ($(GRUCODE),f3d_new) # Fast3D 2.0H (Shindou)
else
ifeq ($(GRUCODE),f3dzex) # Fast3DZEX (2.0J / Animal Forest - Dōbutsu no Mori)
$(warning Fast3DZEX is experimental. Try at your own risk.)
GRUCODE_CFLAGS := -DF3DEX_GBI_2=1
GRUCODE_CFLAGS := -DF3DEX_GBI_2
GRUCODE_ASFLAGS := --defsym F3DEX_GBI_SHARED=1 --defsym F3DZEX_GBI=1
TARGET := $(TARGET).f3dzex
COMPARE := 0
Expand All @@ -78,13 +80,12 @@ endif
endif
endif

ifeq ($(NON_MATCHING),1)
VERSION_CFLAGS := $(VERSION_CFLAGS) -DNON_MATCHING=1
COMPARE := 0
ifeq ($(TARGET_N64),0)
NON_MATCHING := 1
endif

ifeq ($(ENDIAN_IND),1)
VERSION_CFLAGS := $(VERSION_CFLAGS) -DENDIAN_IND=1
ifeq ($(NON_MATCHING),1)
VERSION_CFLAGS := $(VERSION_CFLAGS) -DNON_MATCHING -DAVOID_UB
COMPARE := 0
endif

Expand Down Expand Up @@ -132,8 +133,8 @@ ACTOR_DIR := actors
LEVEL_DIRS := $(patsubst levels/%,%,$(dir $(wildcard levels/*/header.h)))

# Directories containing source files
SRC_DIRS := src src/engine src/game src/audio src/menu src/buffers actors levels text bin data assets
ASM_DIRS := asm lib sound
SRC_DIRS := src src/engine src/game src/audio src/menu src/buffers actors levels bin data assets
ASM_DIRS := asm lib
BIN_DIRS := bin bin/$(VERSION)

ULTRA_SRC_DIRS := lib/src lib/src/math
Expand Down Expand Up @@ -191,10 +192,10 @@ GODDARD_O_FILES := $(foreach file,$(GODDARD_C_FILES),$(BUILD_DIR)/$(file:.c=.o))
# Automatic dependency files
DEP_FILES := $(O_FILES:.o=.d) $(ULTRA_O_FILES:.o=.d) $(GODDARD_O_FILES:.o=.d) $(BUILD_DIR)/$(LD_SCRIPT).d

# Files with NON_MATCHING ifdefs
NON_MATCHING_C_FILES != grep -rl NON_MATCHING $(wildcard src/audio/*.c) $(wildcard src/game/*.c)
NON_MATCHING_O_FILES = $(foreach file,$(NON_MATCHING_C_FILES),$(BUILD_DIR)/$(file:.c=.o))
NON_MATCHING_DEP = $(BUILD_DIR)/src/audio/non_matching_dep
# Files with GLOBAL_ASM blocks
GLOBAL_ASM_C_FILES != grep -rl 'GLOBAL_ASM(' $(wildcard src/audio/*.c) $(wildcard src/game/*.c)
GLOBAL_ASM_O_FILES = $(foreach file,$(GLOBAL_ASM_C_FILES),$(BUILD_DIR)/$(file:.c=.o))
GLOBAL_ASM_DEP = $(BUILD_DIR)/src/audio/non_matching_dep

# Segment elf files
SEG_FILES := $(SEGMENT_ELF_FILES) $(ACTOR_ELF_FILES) $(LEVEL_ELF_FILES)
Expand All @@ -218,23 +219,29 @@ endif

AS := $(CROSS)as
CC := $(QEMU_IRIX) -silent -L $(IRIX_ROOT) $(IRIX_ROOT)/usr/bin/cc
CPP := cpp -P
CPP := cpp -P -Wno-trigraphs
LD := $(CROSS)ld
AR := $(CROSS)ar
OBJDUMP := $(CROSS)objdump
OBJCOPY := $(CROSS)objcopy
PYTHON := python3

INCLUDE_CFLAGS := -I include -I include/libc -I $(BUILD_DIR) -I $(BUILD_DIR)/include -I src -I .
ifeq ($(TARGET_N64),1)
TARGET_CFLAGS := -nostdinc -I include/libc -DTARGET_N64
CC_CFLAGS := -fno-builtin
endif

INCLUDE_CFLAGS := -I include -I $(BUILD_DIR) -I $(BUILD_DIR)/include -I src -I .

# Check code syntax with host compiler
CC_CHECK := gcc -fsyntax-only -fsigned-char -nostdinc -fno-builtin $(INCLUDE_CFLAGS) -std=gnu90 -Wall -Wextra -Wno-format-security -DNON_MATCHING $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -DTARGET_N64
CC_CHECK := gcc -fsyntax-only -fsigned-char $(CC_CFLAGS) $(TARGET_CFLAGS) $(INCLUDE_CFLAGS) -std=gnu90 -Wall -Wextra -Wno-format-security -DNON_MATCHING -DAVOID_UB $(VERSION_CFLAGS) $(GRUCODE_CFLAGS)

ASFLAGS := -march=vr4300 -mabi=32 -I include -I $(BUILD_DIR) $(VERSION_ASFLAGS) $(GRUCODE_ASFLAGS)
CFLAGS = -Wab,-r4300_mul -non_shared -G 0 -Xcpluscomm -Xfullwarn $(OPT_FLAGS) -signed $(INCLUDE_CFLAGS) $(VERSION_CFLAGS) $(MIPSISET) $(GRUCODE_CFLAGS) -DTARGET_N64
CFLAGS = -Wab,-r4300_mul -non_shared -G 0 -Xcpluscomm -Xfullwarn -signed $(OPT_FLAGS) $(TARGET_CFLAGS) $(INCLUDE_CFLAGS) $(VERSION_CFLAGS) $(MIPSISET) $(GRUCODE_CFLAGS)
OBJCOPYFLAGS := --pad-to=0x800000 --gap-fill=0xFF
SYMBOL_LINKING_FLAGS := $(addprefix -R ,$(SEG_FILES))
LDFLAGS := -T undefined_syms.txt -T $(BUILD_DIR)/$(LD_SCRIPT) -Map $(BUILD_DIR)/sm64.$(VERSION).map --no-check-sections $(SYMBOL_LINKING_FLAGS)
ENDIAN_BITWIDTH := $(BUILD_DIR)/endian-and-bitwidth

ifeq ($(shell getconf LONG_BIT), 32)
# Work around memory allocation bug in QEMU
Expand Down Expand Up @@ -306,21 +313,26 @@ $(BUILD_DIR)/include/text_strings.h: include/text_strings.h.in
$(BUILD_DIR)/include/text_menu_strings.h: include/text_menu_strings.h.in
$(TEXTCONV) charmap_menu.txt $< $@

$(BUILD_DIR)/text/%.inc.c: text/$(VERSION)/%.c.in
$(TEXTCONV) charmap.txt $< $@

ifeq ($(VERSION),eu)
SRC_DIRS += text/de text/en text/fr
TEXT_DIRS := text/de text/us text/fr

# EU encoded text inserted into individual segment 0x19 files
$(BUILD_DIR)/bin/$(VERSION)/translation_de.o: $(BUILD_DIR)/text/de/dialog.inc.c $(BUILD_DIR)/text/de/level.inc.c $(BUILD_DIR)/text/de/star.inc.c
$(BUILD_DIR)/bin/$(VERSION)/translation_en.o: $(BUILD_DIR)/text/en/dialog.inc.c $(BUILD_DIR)/text/en/level.inc.c $(BUILD_DIR)/text/en/star.inc.c
$(BUILD_DIR)/bin/$(VERSION)/translation_fr.o: $(BUILD_DIR)/text/fr/dialog.inc.c $(BUILD_DIR)/text/fr/level.inc.c $(BUILD_DIR)/text/fr/star.inc.c
$(BUILD_DIR)/bin/eu/translation_en.o: $(BUILD_DIR)/text/us/define_text.inc.c
$(BUILD_DIR)/bin/eu/translation_de.o: $(BUILD_DIR)/text/de/define_text.inc.c
$(BUILD_DIR)/bin/eu/translation_fr.o: $(BUILD_DIR)/text/fr/define_text.inc.c

else
TEXT_DIRS := text/$(VERSION)

# non-EU encoded text inserted into segment 0x02
$(BUILD_DIR)/bin/segment2.o: $(BUILD_DIR)/text/debug.inc.c $(BUILD_DIR)/text/dialog.inc.c $(BUILD_DIR)/text/level.inc.c $(BUILD_DIR)/text/star.inc.c
$(BUILD_DIR)/bin/segment2.o: $(BUILD_DIR)/text/$(VERSION)/define_text.inc.c
endif

ALL_DIRS := $(BUILD_DIR) $(addprefix $(BUILD_DIR)/,$(SRC_DIRS) $(ASM_DIRS) $(GODDARD_SRC_DIRS) $(ULTRA_SRC_DIRS) $(ULTRA_ASM_DIRS) $(ULTRA_BIN_DIRS) $(BIN_DIRS) $(TEXTURE_DIRS) $(SOUND_SAMPLE_DIRS) $(addprefix levels/,$(LEVEL_DIRS)) include) $(MIO0_DIR) $(addprefix $(MIO0_DIR)/,$(VERSION)) $(SOUND_BIN_DIR) $(SOUND_BIN_DIR)/sequences/$(VERSION)
$(BUILD_DIR)/text/%/define_text.inc.c: text/define_text.inc.c text/%/courses.h text/%/dialogs.h
$(CPP) $(VERSION_CFLAGS) $< -o $@ -I text/$*/
$(TEXTCONV) charmap.txt $@ $@

ALL_DIRS := $(BUILD_DIR) $(addprefix $(BUILD_DIR)/,$(SRC_DIRS) $(ASM_DIRS) $(GODDARD_SRC_DIRS) $(ULTRA_SRC_DIRS) $(ULTRA_ASM_DIRS) $(ULTRA_BIN_DIRS) $(BIN_DIRS) $(TEXTURE_DIRS) $(TEXT_DIRS) $(SOUND_SAMPLE_DIRS) $(addprefix levels/,$(LEVEL_DIRS)) include) $(MIO0_DIR) $(addprefix $(MIO0_DIR)/,$(VERSION)) $(SOUND_BIN_DIR) $(SOUND_BIN_DIR)/sequences/$(VERSION)

# Make sure build directory exists before compiling anything
DUMMY != mkdir -p $(ALL_DIRS)
Expand Down Expand Up @@ -390,17 +402,24 @@ $(BUILD_DIR)/%.table: %.aiff
$(BUILD_DIR)/%.aifc: $(BUILD_DIR)/%.table %.aiff
$(VADPCM_ENC) -c $^ $@

$(SOUND_BIN_DIR)/sound_data.ctl: sound/sound_banks/ $(SOUND_BANK_FILES) $(SOUND_SAMPLE_AIFCS)
$(PYTHON) tools/assemble_sound.py $(BUILD_DIR)/sound/samples/ sound/sound_banks/ $(SOUND_BIN_DIR)/sound_data.ctl $(SOUND_BIN_DIR)/sound_data.tbl $(VERSION_CFLAGS)
$(ENDIAN_BITWIDTH): tools/determine-endian-bitwidth.c
$(CC) -c $(CFLAGS) -o $@.dummy2 $< 2>$@.dummy1; true
grep -o 'msgbegin --endian .* --bitwidth .* msgend' $@.dummy1 > $@.dummy2
head -n1 <$@.dummy2 | cut -d' ' -f2-5 > $@
@rm $@.dummy1
@rm $@.dummy2

$(SOUND_BIN_DIR)/sound_data.ctl: sound/sound_banks/ $(SOUND_BANK_FILES) $(SOUND_SAMPLE_AIFCS) $(ENDIAN_BITWIDTH)
$(PYTHON) tools/assemble_sound.py $(BUILD_DIR)/sound/samples/ sound/sound_banks/ $(SOUND_BIN_DIR)/sound_data.ctl $(SOUND_BIN_DIR)/sound_data.tbl $(VERSION_CFLAGS) $$(cat $(ENDIAN_BITWIDTH))

$(SOUND_BIN_DIR)/sound_data.tbl: $(SOUND_BIN_DIR)/sound_data.ctl
touch $@
@true

$(SOUND_BIN_DIR)/sequences.bin: $(SOUND_BANK_FILES) sound/sequences.json sound/sequences/ sound/sequences/$(VERSION)/ $(SOUND_SEQUENCE_FILES)
$(PYTHON) tools/assemble_sound.py --sequences $@ $(SOUND_BIN_DIR)/bank_sets sound/sound_banks/ sound/sequences.json $(SOUND_SEQUENCE_FILES) $(VERSION_CFLAGS)
$(SOUND_BIN_DIR)/sequences.bin: $(SOUND_BANK_FILES) sound/sequences.json sound/sequences/ sound/sequences/$(VERSION)/ $(SOUND_SEQUENCE_FILES) $(ENDIAN_BITWIDTH)
$(PYTHON) tools/assemble_sound.py --sequences $@ $(SOUND_BIN_DIR)/bank_sets sound/sound_banks/ sound/sequences.json $(SOUND_SEQUENCE_FILES) $(VERSION_CFLAGS) $$(cat $(ENDIAN_BITWIDTH))

$(SOUND_BIN_DIR)/bank_sets: $(SOUND_BIN_DIR)/sequences.bin
touch $@
@true

$(SOUND_BIN_DIR)/%.m64: $(SOUND_BIN_DIR)/%.o
$(OBJCOPY) -j .rodata $< -O binary $@
Expand All @@ -411,6 +430,11 @@ $(SOUND_BIN_DIR)/%.o: $(SOUND_BIN_DIR)/%.s
$(SOUND_BIN_DIR)/%.s: $(SOUND_BIN_DIR)/%
printf ".section .data\n\n.incbin \"$<\"\n" > $@

$(BUILD_DIR)/levels/scripts.o: $(BUILD_DIR)/include/level_headers.h

$(BUILD_DIR)/include/level_headers.h: levels/level_headers.h.in
$(CPP) -I . levels/level_headers.h.in | $(PYTHON) tools/output_level_headers.py > $(BUILD_DIR)/include/level_headers.h

$(BUILD_DIR)/assets/mario_anim_data.c: $(wildcard assets/anims/*.inc.c)
$(PYTHON) tools/mario_anims_converter.py > $@

Expand All @@ -420,7 +444,6 @@ $(BUILD_DIR)/assets/demo_data.c: assets/demo_data.json $(wildcard assets/demos/*
# Source code
$(BUILD_DIR)/src/goddard/%.o: OPT_FLAGS := -g
$(BUILD_DIR)/src/goddard/%.o: MIPSISET := -mips1
$(NON_MATCHING_O_FILES): CC := $(PYTHON) tools/asm_processor/build.py $(CC) -- $(AS) $(ASFLAGS) --
$(BUILD_DIR)/src/audio/%.o: OPT_FLAGS := -O2 -Wo,-loopunroll,0
$(BUILD_DIR)/src/audio/load.o: OPT_FLAGS := -O2 -framepointer -Wo,-loopunroll,0
$(BUILD_DIR)/lib/src/%.o: OPT_FLAGS :=
Expand All @@ -438,16 +461,20 @@ $(BUILD_DIR)/lib/src/_Ldtob.o: OPT_FLAGS := -O3
$(BUILD_DIR)/lib/src/_Printf.o: OPT_FLAGS := -O3
endif

# Rebuild files with '#ifdef NON_MATCHING' when that macro changes.
$(NON_MATCHING_O_FILES): $(NON_MATCHING_DEP).$(NON_MATCHING)
$(NON_MATCHING_DEP).$(NON_MATCHING):
@rm -f $(NON_MATCHING_DEP).*
ifeq ($(NON_MATCHING),0)
$(GLOBAL_ASM_O_FILES): CC := $(PYTHON) tools/asm_processor/build.py $(CC) -- $(AS) $(ASFLAGS) --
endif

# Rebuild files with 'GLOBAL_ASM' if the NON_MATCHING flag changes.
$(GLOBAL_ASM_O_FILES): $(GLOBAL_ASM_DEP).$(NON_MATCHING)
$(GLOBAL_ASM_DEP).$(NON_MATCHING):
@rm -f $(GLOBAL_ASM_DEP).*
touch $@

$(BUILD_DIR)/lib/src/math/%.o: lib/src/math/%.c
@$(CC_CHECK) -MMD -MP -MT $@ -MF $(BUILD_DIR)/lib/src/math/$*.d $<
$(CC) -c $(CFLAGS) -o $@ $<
tools/patch_libultra_math $@ || rm $@
tools/patch_libultra_math $@

$(BUILD_DIR)/%.o: %.c
@$(CC_CHECK) -MMD -MP -MT $@ -MF $(BUILD_DIR)/$*.d $<
Expand All @@ -462,7 +489,7 @@ $(BUILD_DIR)/%.o: %.s
$(AS) $(ASFLAGS) -MD $(BUILD_DIR)/$*.d -o $@ $<

$(BUILD_DIR)/$(LD_SCRIPT): $(LD_SCRIPT)
$(CPP) $(VERSION_CFLAGS) -MMD -MP -MT $@ -MF $@.d -I include/ -DBUILD_DIR=$(BUILD_DIR) -o $@ $<
$(CPP) $(VERSION_CFLAGS) -MMD -MP -MT $@ -MF $@.d -I include/ -I . -DBUILD_DIR=$(BUILD_DIR) -o $@ $<

$(BUILD_DIR)/libultra.a: $(ULTRA_O_FILES)
$(AR) rcs -o $@ $(ULTRA_O_FILES)
Expand All @@ -483,7 +510,7 @@ $(BUILD_DIR)/$(TARGET).objdump: $(ELF)


.PHONY: all clean distclean default diff test load libultra
.PRECIOUS: $(BUILD_DIR)/bin/%.elf $(SOUND_BIN_DIR)/%.ctl $(SOUND_BIN_DIR)/%.tbl $(SOUND_SAMPLE_TABLES) $(SOUND_BIN_DIR)/%.s $(BUILD_DIR)/%
.PRECIOUS: $(BUILD_DIR)/bin/%.elf $(SOUND_BIN_DIR)/%.ctl $(SOUND_BIN_DIR)/%.tbl $(SOUND_SAMPLE_TABLES) $(SOUND_BIN_DIR)/%.s $(BUILD_DIR)/%
.DELETE_ON_ERROR:

# Remove built-in rules, to improve performance
Expand Down
Loading

0 comments on commit 04732af

Please sign in to comment.