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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ docs/doxygen/
*.png~
*.dol
*.Identifier
*.dol
F3DEX3/*/*.code
F3DEX3/*/*.data
wadextract/
Expand Down
62 changes: 2 additions & 60 deletions .make_hackeroot.mk
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,6 @@ endif
COMPRESSION ?= yaz
COMPRESSION_TYPE ?= $(shell echo $(COMPRESSION) | tr '[:lower:]' '[:upper:]')

# Platform compatibility flags
# Default value: (nothing)
TARGET ?=
ifeq ($(TARGET),wad)
CFLAGS := -fno-reorder-blocks -fno-optimize-sibling-calls
CPP_DEFINES := -DCONSOLE_WIIVC
REVISION := 0
REVISION := 0
else ifeq ($(TARGET),iso)
CFLAGS := -fno-reorder-blocks -fno-optimize-sibling-calls
CPP_DEFINES := -DCONSOLE_GC
else
REVISION := 15
endif

# Set PACKAGE_NAME define for printing commit name
ifeq ($(origin PACKAGE_NAME), undefined)
PACKAGE_NAME := "$(shell git log -1 --pretty=%s | tr -d '()`"\n' | tr -d "'" | sed 's/\"/\\\"/g')"
Expand Down Expand Up @@ -127,11 +112,6 @@ F3DEX3_DIR = F3DEX3/$(F3DEX3_BASE_DIR)
FLIPS := tools/Flips/flips
GZINJECT := tools/gzinject/gzinject

# Temporary measure to avoid issues on ISO builds (same for `CFLAGS_IDO`).
# The real fix would be having the proper fixes in the N64 emulator itself
# but this requires some time to figure it out.
CC_IDO := tools/ido_recomp/$(DETECTED_OS)/5.3/cc

#### Files ####

# Config file used for building ISOs.
Expand All @@ -142,45 +122,6 @@ BASEROM_PATCH ?= baseroms/$(VERSION)/baserom.z64

#### Build Rules ####

# Build the codebase to inject in a WAD file (for Wii VC)
# Steps:
# - check if there's the common-key.bin file
# - build and compress the rom
# - inject the binary in the wad file (and apply patches)
# - remove temporary folders
wad:
$(call print_no_args,Patching WAD...)
ifeq ("$(wildcard baseroms/$(VERSION)/common-key.bin)", "")
$(error Please provide the common-key.bin file.)
endif
$(V)$(MAKE) compress TARGET=wad
$(V)$(GZINJECT) -a inject -r 1 -k baseroms/$(VERSION)/common-key.bin -w baseroms/$(VERSION)/basewad.wad -m $(ROMC) -o $(WAD) -t "HackerOoT" -i NHOE -p tools/gzinject/patches/NACE.gzi -p tools/gzinject/patches/gz_default_remap.gzi
$(V)$(RM) -r wadextract/
$(call print_no_args,Success!)

# Build the codebase to inject in a ISO file (for GameCube)
# Steps:
# - build and compress the rom
# - create the dma config file
# - extract the iso
# - copy the rom and dma config file to the extracted iso folder
# - remove any unnecessary files
# - apply the modifications on the emulator binary
# - pack the iso
# - remove temporary folders
iso:
$(V)$(MAKE) compress TARGET=iso
$(call print_no_args,Patching ISO...)
$(V)$(PYTHON) tools/gc_utility.py -v $(VERSION) -c $(COMPRESSION)
$(V)$(GZINJECT) -a extract -s baseroms/$(VERSION)/baseiso.iso
$(V)cp $(BUILD_DIR)/$(DMA_CONFIG_FILE) isoextract/zlj_f.tgc/$(DMA_CONFIG_FILE)
$(V)cp $(ROMC) isoextract/zlj_f.tgc/zlj_f.n64
$(V)$(RM) -r isoextract/S_*.tgc/ isoextract/zlj_f.tgc/*.thp
$(V)$(FLIPS) --apply tools/gamecube.bps isoextract/zlj_f.tgc/main.dol isoextract/zlj_f.tgc/main.dol
$(V)$(GZINJECT) -a pack -s $(ISO)
$(V)$(RM) -r isoextract/
$(call print_no_args,Success!)

# Create a BPS patch for the built rom
# Steps:
# - run Flips and create the patch
Expand Down Expand Up @@ -223,7 +164,7 @@ verify:
$(V)$(MAKE) rom
@md5sum $(ROM)

.PHONY: wad iso patch create_f3dex3_patches verify
.PHONY: patch create_f3dex3_patches verify

$(F3DEX3_DIR)/f3dzex2.code:
$(V)dd bs=1 if=$(BASEROM_DIR)/baserom-decompressed.z64 of=$@ skip=$(UCODE_CODE_OFFSET) count=$(UCODE_CODE_SIZE) status=none
Expand All @@ -236,6 +177,7 @@ $(F3DEX3_DIR)/F3DEX3%.code: $(F3DEX3_DIR)/F3DEX3%.code.bps $(F3DEX3_DIR)/f3dzex2

$(F3DEX3_DIR)/F3DEX3%.data: $(F3DEX3_DIR)/F3DEX3%.data.bps $(F3DEX3_DIR)/f3dzex2.data
$(V)$(FLIPS) --apply $(F3DEX3_DIR)/F3DEX3$*.data.bps $(F3DEX3_DIR)/f3dzex2.data $@

### SummerCart64 Settings ###

# path to the deployer program
Expand Down
106 changes: 106 additions & 0 deletions .make_wii-vc.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Example usage:
# - make wad VERSION=ntsc-1.2
# - make iso VERSION=ntsc-1.2
#
# if building a mod for the GameCube, you will need to build this: https://github.com/Yanis002/oot-gc/tree/oot_gcc_compat
# and place the build in the baseroms folder (see `DOL` below)

## Tools

# You can get gzinject here https://github.com/PracticeROM/gzinject
GZINJECT ?= tools/gzinject/gzinject

COPY ?= cp -v

# GameCube:
# This tool generates a file that the (modified) emulator can read
# to figure out which parts of the rom to cache.
# It outputs file indices from the rom and the location and the size of `gDmaDataTable`.
GEN_DMA_CONFIG := tools/generate_dma_config.py

# GameCube:
# This tool generates a file that the (modified) emulator can read
# to figure out where some of the N64 functions are to apply the proper hacks
# to make the game run properly.
# By default, the emulator will compute a checksum and it tries to find functions based on
# the calculated checksum and the size of the function, though this can fail completely
# since other compilers like GCC can change these values, this system is a workaround for that.
# Note: this is only useful when building with GCC.
GEN_LIB_CONFIG := tools/generate_lib_config.py

# Wii
WAD_NAME ?= "HackerOoT"
WAD_ID ?= NHOE
WAD_REGION ?= $(REGION)

## Files

BASEWAD := baseroms/baserom-$(WAD_REGION).wad
COMMON_KEY := baseroms/common-key.bin
WAD := $(ROM:.z64=.wad)

# for ISOs we pick the MQ-JP one for all versions and instead patch the emulator
BASEISO := baseroms/baserom.iso
ISO := $(ROM:.z64=.iso)
DMA_CONFIG_FILE := dma_config.bin
LIB_CONFIG_FILE := lib_config.bin

# set to 1 to inject in MQ
MQ_INJECT ?= 0

ifeq ($(MQ_INJECT),1)
ROM_NAME := urazlj_f
else
ROM_NAME := zlj_f
endif

# the emulator replacement dol, can be empty skip this step
DOL := baseroms/oot-gc.dol

## Flags

# wad or iso to make a compatible gcc build
TARGET ?=

ifeq ($(COMPILER),gcc)
ifneq ($(TARGET),)
# TARGET_GC disables `.set gp=64` in exceptasm.s and the 3ms audio delay in `audio_thread_manager.c`
CFLAGS += -fno-reorder-blocks -fno-optimize-sibling-calls -fno-toplevel-reorder -DTARGET_GC -DWAD_REGION=REGION_$(WAD_REGION)
CPPFLAGS += -fno-reorder-blocks -fno-optimize-sibling-calls -fno-toplevel-reorder -DTARGET_GC -DWAD_REGION=REGION_$(WAD_REGION)
CCASFLAGS += -DTARGET_GC -DWAD_REGION=$(WAD_REGION)

$(BUILD_DIR)/src/audio/internal/seqplayer.o: OPTFLAGS := -O1
endif
endif

ifeq ($(TARGET),)
TARGET := n64
endif

## Targets

wad:
$(V)$(MAKE) compress TARGET=wad
$(V)$(GZINJECT) -a inject -t $(WAD_NAME) -i $(WAD_ID) -k $(COMMON_KEY) -m $(ROMC) -w $(BASEWAD) -o $(WAD) -p gzi/$(WAD_REGION).gzi -p gzi/controller.gzi
$(V)$(RM) -r wadextract/

# for ISOs we need to do things manually since we want to remove
# the useless files that increase the size of the file by a lot
iso:
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: test again gamecube builds

$(V)$(MAKE) compress TARGET=iso
$(V)$(GZINJECT) -a extract -s $(BASEISO)
$(V)$(PYTHON) $(GEN_DMA_CONFIG) -v $(VERSION)
$(V)$(COPY) $(BUILD_DIR)/$(DMA_CONFIG_FILE) isoextract/zlj_f.tgc/$(DMA_CONFIG_FILE)
ifneq ($(COMPILER),ido)
$(V)$(PYTHON) $(GEN_LIB_CONFIG) -v $(VERSION)
$(V)$(COPY) $(BUILD_DIR)/$(LIB_CONFIG_FILE) isoextract/zlj_f.tgc/$(LIB_CONFIG_FILE)
endif
$(V)$(COPY) $(ROMC) isoextract/zlj_f.tgc/$(ROM_NAME).n64
ifneq ($(DOL),)
$(V)$(COPY) $(DOL) isoextract/zlj_f.tgc/main.dol
endif
$(V)$(RM) -r isoextract/S_*.tgc/ isoextract/zlj_f.tgc/*.thp
$(V)$(GZINJECT) -a pack -s $(ISO)
$(V)$(RM) -r isoextract/

.PHONY: wad iso
46 changes: 2 additions & 44 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,6 @@ SEQ_CPPFLAGS := -D_LANGUAGE_ASEQ -DMML_VERSION=MML_VERSION_OOT $(CPP_DEFINES) -
SBCFLAGS := --matching
SFCFLAGS := --matching

CFLAGS += $(CPP_DEFINES)
CPPFLAGS += $(CPP_DEFINES)
CFLAGS_IDO += $(CPP_DEFINES)

# Extra debugging steps
ifeq ($(DEBUG_OBJECTS),1)
OBJDUMP_CMD = @$(OBJDUMP) $(OBJDUMP_FLAGS) $@ > $(@:.o=.s)
Expand Down Expand Up @@ -382,12 +378,11 @@ SPEC := spec/spec
SPEC_INCLUDES := $(wildcard spec/*.inc)

# HackerOoT files
WAD := $(ROM:.z64=.wad)
ISO := $(ROM:.z64=.iso)
BPS := $(ROM:.z64=.bps)
UCODE_PATCHES := $(wildcard $(F3DEX3_DIR)/*.bps)
UCODE_FILES := $(foreach f,$(UCODE_PATCHES:.bps=),$f)
UCODE_O_FILES := $(foreach f,$(UCODE_FILES),$(BUILD_DIR)/$f.o)
-include .make_wii-vc.mk

SRC_DIRS := $(shell find src -type d)
UNDECOMPILED_DATA_DIRS := $(shell find data -type d)
Expand Down Expand Up @@ -524,44 +519,6 @@ ifeq ($(COMPILER),gcc)
$(BUILD_DIR)/src/%.o: CFLAGS += -fexec-charset=utf-8
$(BUILD_DIR)/src/libultra/libc/ll.o: OPTFLAGS := -Ofast
$(BUILD_DIR)/src/overlays/%.o: CFLAGS += -fno-merge-constants -mno-explicit-relocs -mno-split-addresses

## HackerOoT overrides ##

$(BUILD_DIR)/src/overlays/actors/ovl_Item_Shield/%.o: OPTFLAGS := -O2
$(BUILD_DIR)/src/overlays/actors/ovl_En_Part/%.o: OPTFLAGS := -O2
$(BUILD_DIR)/src/overlays/actors/ovl_Item_B_Heart/%.o: OPTFLAGS := -O0
$(BUILD_DIR)/src/overlays/actors/ovl_Bg_Mori_Hineri/%.o: OPTFLAGS := -O0
Comment on lines -530 to -533
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: test again if this is necessary


# library overrides
ifeq ($(TARGET),iso)
MIPS_VERSION_IDO := -mips2
CFLAGS_IDO += -G 0 -non_shared -fullwarn -verbose -Xcpluscomm $(INC) -Wab,-r4300_mul -woff 516,609,649,838,712
$(BUILD_DIR)/src/libultra/io/viswapbuf.o: OPTFLAGS := -O2
$(BUILD_DIR)/src/libultra/io/viswapbuf.o: MIPS_VERSION := $(MIPS_VERSION_IDO)
$(BUILD_DIR)/src/libultra/io/viswapbuf.o: CFLAGS := $(CFLAGS_IDO)
$(BUILD_DIR)/src/libultra/io/viswapbuf.o: CC := $(CC_IDO)
$(BUILD_DIR)/src/libultra/gu/sinf.o: OPTFLAGS := -O2
$(BUILD_DIR)/src/libultra/gu/sinf.o: MIPS_VERSION := $(MIPS_VERSION_IDO)
$(BUILD_DIR)/src/libultra/gu/sinf.o: CFLAGS := $(CFLAGS_IDO)
$(BUILD_DIR)/src/libultra/gu/sinf.o: CC := $(CC_IDO)
$(BUILD_DIR)/src/libultra/gu/cosf.o: OPTFLAGS := -O2
$(BUILD_DIR)/src/libultra/gu/cosf.o: MIPS_VERSION := $(MIPS_VERSION_IDO)
$(BUILD_DIR)/src/libultra/gu/cosf.o: CFLAGS := $(CFLAGS_IDO)
$(BUILD_DIR)/src/libultra/gu/cosf.o: CC := $(CC_IDO)
$(BUILD_DIR)/src/libultra/gu/perspective.o: OPTFLAGS := -O2
$(BUILD_DIR)/src/libultra/gu/perspective.o: MIPS_VERSION := $(MIPS_VERSION_IDO)
$(BUILD_DIR)/src/libultra/gu/perspective.o: CFLAGS := $(CFLAGS_IDO)
$(BUILD_DIR)/src/libultra/gu/perspective.o: CC := $(CC_IDO)
$(BUILD_DIR)/src/libultra/os/getmemsize.o: OPTFLAGS := -O1
$(BUILD_DIR)/src/libultra/os/getmemsize.o: MIPS_VERSION := $(MIPS_VERSION_IDO)
$(BUILD_DIR)/src/libultra/os/getmemsize.o: CFLAGS := $(CFLAGS_IDO)
$(BUILD_DIR)/src/libultra/os/getmemsize.o: CC := $(CC_IDO)
$(BUILD_DIR)/src/libultra/os/aisetnextbuf.o: OPTFLAGS := -O1
$(BUILD_DIR)/src/libultra/os/aisetnextbuf.o: MIPS_VERSION := $(MIPS_VERSION_IDO)
$(BUILD_DIR)/src/libultra/os/aisetnextbuf.o: CFLAGS := $(CFLAGS_IDO)
$(BUILD_DIR)/src/libultra/os/aisetnextbuf.o: CC := $(CC_IDO)
endif

endif

#### Main Targets ###
Expand Down Expand Up @@ -654,6 +611,7 @@ $(ROM): $(ELF)
@$(PRINT) "${GREEN}Rom Path: $(BLUE)$(ROM)$(NO_COL)\n"
@$(PRINT) "${GREEN}Build Author: $(BLUE)$(PACKAGE_AUTHOR)$(NO_COL)\n"
@$(PRINT) "${GREEN}Commit Author: $(BLUE)$(PACKAGE_COMMIT_AUTHOR)$(NO_COL)\n"
@$(PRINT) "${GREEN}Target: $(BLUE)$(TARGET)$(NO_COL)\n"
ifeq ($(TESTSUITE_MODE),1)
@$(PRINT) "${GREEN}Made with HackerTestSuite$(NO_COL)\n"
endif
Expand Down
6 changes: 6 additions & 0 deletions gzi/JP.gzi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# default gz patches for NACJ
0000 00000000 00000001
# use 8MB memory
0304 00002EB0 60000000
# allocate 32MB for rom
0304 0005BF44 3C807200
6 changes: 6 additions & 0 deletions gzi/US.gzi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# default gz patches for NACE
0000 00000000 00000001
# use 8MB memory
0304 00002EB0 60000000
# allocate 32MB for rom
0304 0005BFD4 3C807200
9 changes: 9 additions & 0 deletions gzi/controller.gzi
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# gz standard remapping for NACE and NACJ
0000 00000000 00000001
# apply d-pad remappings
0302 0016BAF0 00000800
0302 0016BAF4 00000400
0302 0016BAF8 00000200
0302 0016BAFC 00000100
# apply c-stick remapping
0302 0016BB04 00000020
12 changes: 5 additions & 7 deletions include/config/config_safeguards.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,16 @@
/*****************
* config_graphics.h
*/
//! TODO: implement better Wii VC compatibility
#ifdef CONSOLE_WIIVC
#undef ENABLE_F3DEX3
//! TODO: implement better Wii VC compatibility for Motion Blur and F3DEX3
#ifdef TARGET_GC
#undef ENABLE_MOTION_BLUR

#define ENABLE_F3DEX3 false
#define ENABLE_MOTION_BLUR false
#endif

#ifdef CONSOLE_GC
#undef ENABLE_F3DEX3
#define ENABLE_F3DEX3 false

#undef AUDIO_DELAY
#define AUDIO_DELAY false
#endif

#if ENABLE_PROFILER && !ENABLE_HACKER_DEBUG
Expand Down
2 changes: 1 addition & 1 deletion src/audio/internal/heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ void AudioHeap_LoadFilter(s16* filter, s32 lowPassCutoff, s32 highPassCutoff) {
}

// Write back the cache line for this filter
#if defined(CONSOLE_WIIVC) || defined(CONSOLE_GC)
#ifdef TARGET_GC
osWritebackDCache(filter, 8 * sizeof(s16));
#else
asm("cache %0, (%1)" ::"i"(CACH_PD | C_HWBINV), "r"(filter));
Expand Down
3 changes: 3 additions & 0 deletions src/libultra/os/exceptasm.s
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#if (defined __GNUC__) && !(defined TARGET_GC)
.set gp=64
#endif
#include "ultra64/asm.h"
#include "ultra64/regdef.h"
#include "ultra64/R4300.h"
Expand Down
10 changes: 5 additions & 5 deletions src/libultra/os/thread.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "ultra64.h"
#include "attributes.h"

NO_REORDER __OSThreadTail __osThreadTail = { NULL, OS_PRIORITY_THREADTAIL };
NO_REORDER OSThread* __osRunQueue = (OSThread*)&__osThreadTail;
NO_REORDER OSThread* __osActiveQueue = (OSThread*)&__osThreadTail;
NO_REORDER OSThread* __osRunningThread = NULL;
NO_REORDER OSThread* __osFaultedThread = NULL;
SECTION_DATA NO_REORDER __OSThreadTail __osThreadTail = { NULL, OS_PRIORITY_THREADTAIL };
SECTION_DATA NO_REORDER OSThread* __osRunQueue = (OSThread*)&__osThreadTail;
SECTION_DATA NO_REORDER OSThread* __osActiveQueue = (OSThread*)&__osThreadTail;
SECTION_DATA NO_REORDER OSThread* __osRunningThread = NULL;
SECTION_DATA NO_REORDER OSThread* __osFaultedThread = NULL;

void __osDequeueThread(register OSThread** queue, register OSThread* thread) {
register OSThread* pred = (OSThread*)queue;
Expand Down
6 changes: 2 additions & 4 deletions src/makerom/rom_header.s
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
/* 0x18 */ PADDING(8)
/* 0x20 */ ROM_NAME("THE LEGEND OF ZELDA")
/* 0x34 */ PADDING(7)
#if OOT_NTSC || ((defined CONSOLE_WIIVC) || (defined CONSOLE_GC))
#if OOT_NTSC || (defined TARGET_GC)
/* 0x3B */ MEDIUM(CARTRIDGE_EXPANDABLE)
#else
/* 0x3B */ MEDIUM(CARTRIDGE)
#endif
/* 0x3C */ GAME_ID("ZL")
#if (defined CONSOLE_WIIVC) || (defined CONSOLE_GC)
/* 0x3E */ REGION(US)
#elif OOT_REGION == REGION_NULL
#if OOT_REGION == REGION_NULL
/* 0x3E */ REGION(FREE)
#elif OOT_REGION == REGION_US
/* 0x3E */ REGION(US)
Expand Down
Loading
Loading