Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 31 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
BASENAME = dkr
BASENAME := dkr
REGION := us
VERSION := v77
NON_MATCHING ?= 0
DEBUG ?= 0

# NM is shorthand for NON_MATCHING
ifneq ($(NM),)
Expand All @@ -10,7 +11,11 @@ endif

# Experimental option for nonmatching builds. GCC may not function identically to ido.
COMPILER ?= ido
$(eval $(call validate-option,NON_MATCHING,ido gcc))

VALID_COMPILERS := ido gcc
ifeq (,$(filter $(COMPILER),$(VALID_COMPILERS)))
$(error Invalid COMPILER: $(COMPILER). Valid options: $(VALID_COMPILERS))
endif

ifneq ($(COMPILER),ido)
NON_MATCHING := 1
Expand Down Expand Up @@ -66,7 +71,7 @@ LIBULTRA_SRC_DIRS += $(LIBULTRA_DIR)/src/libc $(LIBULTRA_DIR)/src/os $(LIBULTRA_

# Files requiring pre/post-processing
GLOBAL_ASM_C_FILES := $(shell $(GREP) GLOBAL_ASM $(SRC_DIR) </dev/null 2>/dev/null)
GLOBAL_ASM_O_FILES := $(foreach file,$(GLOBAL_ASM_C_FILES),$(BUILD_DIR)/$(file).o)
GLOBAL_ASM_O_FILES := $(patsubst %.c,$(BUILD_DIR)/%.c.o,$(GLOBAL_ASM_C_FILES))

SRC_DIRS = $(SRC_DIR) $(LIBULTRA_SRC_DIRS)
SYMBOLS_DIR = ver/symbols
Expand All @@ -92,19 +97,12 @@ RECOMP_DIR := $(TOOLS_DIR)/ido-recomp/$(DETECTED_OS)

# Files

S_FILES = $(foreach dir,$(ASM_DIRS) $(HASM_DIRS),$(wildcard $(dir)/*.s))
C_FILES = $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
BIN_FILES = $(foreach dir,$(BIN_DIRS),$(wildcard $(dir)/*.bin))

O_FILES := $(foreach file,$(S_FILES),$(BUILD_DIR)/$(file).o) \
$(foreach file,$(C_FILES),$(BUILD_DIR)/$(file).o) \
$(foreach file,$(BIN_FILES),$(BUILD_DIR)/$(file).o)

S_FILES := $(wildcard $(addsuffix /*.s,$(ASM_DIRS) $(HASM_DIRS)))
C_FILES := $(wildcard $(addsuffix /*.c,$(SRC_DIRS)))
BIN_FILES := $(wildcard $(addsuffix /*.bin,$(BIN_DIRS)))
O_FILES := $(patsubst %,$(BUILD_DIR)/%.o,$(S_FILES) $(C_FILES) $(BIN_FILES))
O_FILES_LD := $(filter-out $(BUILD_DIR)/asm/assets/assets.s.o, \
$(foreach file,$(S_FILES),$(BUILD_DIR)/$(file).o) \
$(foreach file,$(C_FILES),$(BUILD_DIR)/$(file).o))

find-command = $(shell which $(1) 2>/dev/null)
$(patsubst %,$(BUILD_DIR)/%.o,$(S_FILES) $(C_FILES)))

# Tools

Expand Down Expand Up @@ -274,11 +272,11 @@ $(BUILD_DIR)/$(LIBULTRA_DIR)/%.s.o: OPT_FLAGS := -O1
$(BUILD_DIR)/$(LIBULTRA_DIR)/%.s.o: MIPSISET := -mips2
$(BUILD_DIR)/$(LIBULTRA_DIR)/src/libc/%.s.o: OPT_FLAGS := -O2
$(BUILD_DIR)/$(LIBULTRA_DIR)/src/os/exceptasm.s.o: MIPSISET := -mips3 -32
endif

# Allow dollar sign to be used in var names for this file alone
# It allows us to return the current stack pointer
$(BUILD_DIR)/$(SRC_DIR)/get_stack_pointer.c.o: OPT_FLAGS += -dollar
endif

#Ignore warnings for libultra files
$(BUILD_DIR)/$(LIBULTRA_DIR)/%.c.o: CC_WARNINGS := -w
Expand All @@ -294,7 +292,6 @@ endif
$(GCC_SAFE_FILES): CC := $(CROSS)gcc
$(GCC_SAFE_FILES): CC_WARNINGS :=
$(GCC_SAFE_FILES): MIPSISET := -mips3
$(GCC_SAFE_FILES): OPT_FLAGS := -Os
$(GCC_SAFE_FILES): CFLAGS := -DNDEBUG -DAVOID_UB -DNON_MATCHING $(INCLUDE_CFLAGS) $(C_DEFINES) \
-EB \
-march=vr4300 \
Expand All @@ -319,6 +316,12 @@ $(GCC_SAFE_FILES): CFLAGS := -DNDEBUG -DAVOID_UB -DNON_MATCHING $(INCLUDE_CFLAGS
-falign-functions=16 \
-G 0

ifeq ($(DEBUG),1)
$(GCC_SAFE_FILES): OPT_FLAGS := -O0 -g
else
$(GCC_SAFE_FILES): OPT_FLAGS := -Os
endif

default: all

all: $(VERIFY)
Expand Down Expand Up @@ -427,6 +430,15 @@ $(GLOBAL_ASM_O_FILES): CC := $(ASM_PROCESSOR) $(CC) -- $(AS) $(ASFLAGS) --
$(TARGET).elf: dirs $(LD_SCRIPT) $(O_FILES) | build_assets
@$(PRINT) "$(GREEN)Linking: $(BLUE)$@$(NO_COL)\n"
$(V)$(LD) $(LD_FLAGS) -o $@
# If there's code outside of the first megabyte of data for non Libdragon ipl3, then the game won't work. This is a check to verify that it's not.
ifneq ($(BOOT_CIC),Libdragon)
$(V)bss_addr=$$( $(CROSS)nm $@ | grep main_bss_VRAM | awk '{print $$1}' ); \
if [ $$((0x$$bss_addr)) -ge $$((0x80100000)) ]; then \
echo "Error: BSS start address is 0x$$bss_addr, which is after 0x80100000. Game will not boot."; \
rm $@; \
exit 1; \
fi
endif

ifndef PERMUTER
$(GLOBAL_ASM_O_FILES): $(BUILD_DIR)/%.c.o: %.c | build_assets
Expand Down Expand Up @@ -493,16 +505,12 @@ $(BUILD_DIR)/%.bin.o: %.bin | build_assets
$(call print,Linking Binary:,$<,$@)
$(V)$(LD) -r -b binary -o $@ $<

$(TARGET).bin: $(TARGET).elf | build_assets
$(TARGET).z64: $(TARGET).elf | build_assets
$(call print,Objcopy:,$<,$@)
$(V)$(OBJCOPY) $(OBJCOPYFLAGS) $< $@

$(TARGET).z64: $(TARGET).bin | build_assets
$(call print,CopyRom:,$<,$@)
$(V)$(PYTHON) $(TOOLS_DIR)/python/CopyRom.py $< $@

### Settings
.PHONY: all clean cleanextract default assets
.PHONY: all clean distclean cleanextract default assets
SHELL = /bin/bash -e -o pipefail

-include $(BUILD_DIR)/**/*.d
8 changes: 8 additions & 0 deletions libultra/src/sc/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ static void __scYield(OSSched *s);
s32 D_800DE730[] = { OSMESG_SWAP_BUFFER, OSMESG_SWAP_BUFFER };
s32 gBootBlackoutMesg[] = { OSMESG_SWAP_BUFFER, MESG_SKIP_BUFFER_SWAP };

#ifndef NON_MATCHING
f32 gAudTaskTimer0 = 0;
f32 gAudTaskTimer1 = 0;
f32 gAudTaskTimer2 = 0;
f32 gAudTaskTimer3 = 0;

s32 gRetraceCounter32 = 0;
#endif
s32 gCurRSPTaskCounter = 0;
s32 gCurRDPTaskCounter = 0;
UNUSED s32 D_800DE75C = 0;
Expand Down Expand Up @@ -217,6 +219,7 @@ OSMesgQueue *osScGetInterruptQ(OSSched *sc) {
return &sc->interruptQ;
}

#ifndef NON_MATCHING
/**
* Official Name: osScGetAudioSPStats
*/
Expand All @@ -225,6 +228,7 @@ UNUSED void scGetAudioTaskTimers(f32 *timer0, f32 *timer1, f32 *timer2) {
*timer1 = gAudTaskTimer2;
*timer2 = gAudTaskTimer3;
}
#endif

/***********************************************************************
* Scheduler implementation
Expand Down Expand Up @@ -367,7 +371,9 @@ void __scHandleRetrace(OSSched *sc) {
__scExec(sc, sp, dp);

gRetraceCounter64++;
#ifndef NON_MATCHING
gRetraceCounter32++;
#endif
sc->frameCount+=1; // If you want to make the game 60FPS, change this to 2.

if ((sc->unkTask) && (sc->frameCount >= 2)) {
Expand Down Expand Up @@ -417,6 +423,7 @@ void __scHandleRSP(OSSched *sc)
osLogEvent(l, 510, 3, t, t->state, t->flags);
#endif

#ifndef NON_MATCHING
//Rare seems to have edited this function, most specifically here.
//This should probably have all been behind a debug #ifdef as none of these values are used.
if (t->list.t.type == M_AUDTASK) {
Expand All @@ -435,6 +442,7 @@ void __scHandleRSP(OSSched *sc)
gAudTaskTimer0 = 0.0f;
}
}
#endif

if ((t->state & OS_SC_YIELD)) {
if (osSpTaskYielded(&t->list)) {
Expand Down
149 changes: 149 additions & 0 deletions mods/dkr.custom.ld
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,157 @@ SECTIONS
assets_ROM_END = __romPos;
assets_VRAM_END = .;

.strtab 0 :
{
*(.strtab);
}
.symtab 0 :
{
*(.symtab);
}
.shstrtab 0 :
{
*(.shstrtab);
}
.pdr 0 :
{
*(.pdr);
}
.debug 0 :
{
*(.debug);
}
.line 0 :
{
*(.line);
}
.debug_srcinfo 0 :
{
*(.debug_srcinfo);
}
.debug_sfnames 0 :
{
*(.debug_sfnames);
}
.debug_aranges 0 :
{
*(.debug_aranges);
}
.debug_pubnames 0 :
{
*(.debug_pubnames);
}
.debug_info 0 :
{
*(.debug_info);
}
.debug_abbrev 0 :
{
*(.debug_abbrev);
}
.debug_line 0 :
{
*(.debug_line);
}
.debug_line_end 0 :
{
*(.debug_line_end);
}
.debug_frame 0 :
{
*(.debug_frame);
}
.debug_str 0 :
{
*(.debug_str);
}
.debug_loc 0 :
{
*(.debug_loc);
}
.debug_macinfo 0 :
{
*(.debug_macinfo);
}
.debug_weaknames 0 :
{
*(.debug_weaknames);
}
.debug_funcnames 0 :
{
*(.debug_funcnames);
}
.debug_typenames 0 :
{
*(.debug_typenames);
}
.debug_varnames 0 :
{
*(.debug_varnames);
}
.debug_pubtypes 0 :
{
*(.debug_pubtypes);
}
.debug_ranges 0 :
{
*(.debug_ranges);
}
.debug_addr 0 :
{
*(.debug_addr);
}
.debug_line_str 0 :
{
*(.debug_line_str);
}
.debug_loclists 0 :
{
*(.debug_loclists);
}
.debug_macro 0 :
{
*(.debug_macro);
}
.debug_names 0 :
{
*(.debug_names);
}
.debug_rnglists 0 :
{
*(.debug_rnglists);
}
.debug_str_offsets 0 :
{
*(.debug_str_offsets);
}
.debug_sup 0 :
{
*(.debug_sup);
}
.gnu.attributes 0 :
{
*(.gnu.attributes);
}
.note 0 :
{
*(.note);
}
.comment 0 :
{
*(.comment);
}

/DISCARD/ :
{
*(.reginfo);
*(.MIPS.abiflags);
*(.MIPS.options);
*(.note.gnu.build-id);
*(.interp);
*(.eh_frame);
*(.mdebug);
*(.mdebug.abi32);
*(*);
}
}
2 changes: 2 additions & 0 deletions src/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,12 @@ void cam_init(void) {

WAIT_ON_IOBUSY(stat);

#ifdef ANTI_TAMPER
// 0xB0000578 is a direct read from the ROM as opposed to RAM
if (((D_B0000578 & 0xFFFF) & 0xFFFF) != 0x8965) {
gAntiPiracyViewport = TRUE;
}
#endif

guPerspectiveF(gPerspectiveMatrixF, &perspNorm, CAMERA_DEFAULT_FOV, CAMERA_ASPECT, CAMERA_NEAR, CAMERA_FAR,
CAMERA_SCALE);
Expand Down
13 changes: 9 additions & 4 deletions src/hasm/header.s
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@
.word 0x0000000F /* Clockrate setting */
.ifdef BOOT_6102
.word 0x80000400 /* Entrypoint address */
.else
.ifdef BOOT_Libdragon
.word 0x80000400 /* Entrypoint address */
.else
.word 0x80100400 /* Entrypoint address */
.endif
.endif
.word 0x00001447 /* Revision */

.ifdef BOOT_Libdragon
.word (main_BSS_START - 0x7FFFF400) /* Code size to load */
.word 0x00000000 /* Empty */
.else
.ifdef VERSION_us_v77
.word 0x53D440E7 /* Checksum 1 */
.word 0x7519B011 /* Checksum 2 */
Expand All @@ -29,12 +37,9 @@
.word 0x596E145B /* Checksum 1 */
.word 0xF7D9879F /* Checksum 2 */
.endif
.endif

.ifdef NON_MATCHING
.word main_BSS_START /* Unknown 1 */
.else
.word 0x00000000 /* Unknown 1 */
.endif
.word 0x00000000 /* Unknown 2 */
.ascii "Diddy Kong Racing " /* Internal name */
.word 0x00000000 /* Unknown 3 */
Expand Down
Loading