Skip to content

Commit

Permalink
Year of the Pikmin
Browse files Browse the repository at this point in the history
Pikmin 1 setup complete
parts 2 and 3 of asm cleanup done
  • Loading branch information
EpochFlame committed Jan 1, 2024
1 parent 3fcd6a1 commit 17220af
Show file tree
Hide file tree
Showing 64 changed files with 12,891 additions and 679 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ Debug
.vs
ctx.c
tools/dtk
tools/powerpc/
.ninja_deps
.ninja_log
objdiff.json
__pycache__
144 changes: 114 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ ifneq ($(findstring MSYS,$(shell uname)),)
WINDOWS := 1
endif

# If 0, tells the console to chill out. (Quiets the make process.)
VERBOSE ?= 0

# If MAPGENFLAG set to 1, tells LDFLAGS to generate a mapfile, which makes linking take several minutes.
MAPGENFLAG ?= 0

# Use the all-in-one updater after successful build? (Fails on non-windows platforms)
USE_AOI ?= 0

ifeq ($(VERBOSE),0)
QUIET := @
endif
Expand All @@ -16,49 +23,68 @@ endif
#-------------------------------------------------------------------------------

NAME := pikmin
VERSION := usa.1
VERSION ?= usa.1
#VERSION := usa.0

ifeq ($(VERSION), usa.1)
VERNUM = 2
else ifeq ($(VERSION), usa.0)
VERNUM = 1
else
VERNUM = 0
endif

# Use the all-in-one updater after successful build? (Fails on non-windows platforms)
ifeq ($(USE_AOI), 1)
ifeq ($(WINDOWS), 1)
USE_AOI = 1
else
@echo "aoi.exe fails on non-windows platforms."
USE_AOI = 0
endif
else
USE_AOI = 0
endif

BUILD_DIR := build/$(NAME).$(VERSION)

# Inputs
S_FILES := $(wildcard asm/*.s)
C_FILES := $(wildcard src/*.c)
CPP_FILES := $(wildcard src/*.cpp)
CPP_FILES += $(wildcard src/*.cp)
LDSCRIPT := ldscript.lcf
LDSCRIPT := $(BUILD_DIR)/ldscript.lcf
AOI := aoi.exe

# Outputs
DOL := $(BUILD_DIR)/main.dol
ELF := $(DOL:.dol=.elf)
MAP := $(BUILD_DIR)/build.map

ifeq ($(MAPGENFLAG),1)
MAPGEN := -map $(MAP)
endif

include obj_files.mk

O_FILES := $(SYSBOOTUP) $(JAUDIO) $(HVQM4DEC) $(SYSCOMMON) $(SYSDOLPHIN)\
$(COLIN) $(KANDO) $(NAKATA) $(NISHIMURA) $(OGAWA) $(YAMASHITA)\
$(BASE) $(OS) $(DB) $(MTX) $(DVD) $(VI) $(PAD) $(AI) $(AR) $(DSP)\
$(CARD) $(HIO) $(GX) $(RUNTIME) $(MSL_C) $(TRK_MINNOW_DOLPHIN)\
$(AMCEXI2) $(AMCNOTSTUB) $(ODEMUEXI2) $(ODENOTSTUB)
O_FILES := $(SYSBOOTUP) $(JAUDIO) $(HVQM4DEC) $(SYS) $(PLUGPIKI) $(DOLPHIN)
DEPENDS := $($(filter *.o,O_FILES):.o=.d)
DEPENDS += $($(filter *.o,E_FILES):.o=.d)
# If a specific .o file is passed as a target, also process its deps
DEPENDS += $(MAKECMDGOALS:.o=.d)

#-------------------------------------------------------------------------------
# Tools
#-------------------------------------------------------------------------------

MWCC_VERSION := 1.2.5
MWLD_VERSION := 1.2.5

# Compiler versions and flags
$(COLIN): MWCC_VERSION := 1.2.5n
$(KANDO): MWCC_VERSION := 1.2.5n
$(NAKATA): MWCC_VERSION := 1.2.5n
$(NISHIMURA): MWCC_VERSION := 1.2.5n
$(OGAWA): MWCC_VERSION := 1.2.5n
$(YAMASHITA): MWCC_VERSION := 1.2.5n

# Programs
POWERPC ?= tools/powerpc
ifeq ($(WINDOWS),1)
WINE :=
AS := $(DEVKITPPC)/bin/powerpc-eabi-as.exe
AS := $(POWERPC)/powerpc-eabi-as.exe
PYTHON := python
else
WIBO := $(shell command -v wibo 2> /dev/null)
Expand All @@ -67,7 +93,9 @@ else
else
WINE ?= wine
endif
AS := $(DEVKITPPC)/bin/powerpc-eabi-as
# Disable wine debug output for cleanliness
export WINEDEBUG ?= -all
AS := $(POWERPC)/powerpc-eabi-as
PYTHON := python3
endif
COMPILERS ?= tools/mwcc_compiler
Expand All @@ -77,16 +105,34 @@ DTK := tools/dtk
ELF2DOL := $(DTK) elf2dol
SHASUM := $(DTK) shasum

ifneq ($(WINDOWS),1)
TRANSFORM_DEP := tools/transform-dep.py
else
TRANSFORM_DEP := tools/transform-win.py
endif

# Options
INCLUDES := -i include/
INCLUDES := -i include/ -i include/stl/
ASM_INCLUDES := -I include/

ASFLAGS := -mgekko $(ASM_INCLUDES)
LDFLAGS := -map $(MAP) -fp hard -nodefaults
CFLAGS = -Cpp_exceptions off -O4,p -fp hard -proc gekko -nodefaults -RTTI on $(INCLUDES)
ASFLAGS := -mgekko $(ASM_INCLUDES) --defsym version=$(VERNUM)
ifeq ($(VERBOSE),1)
# this set of LDFLAGS outputs warnings.
LDFLAGS := $(MAPGEN) -fp hard -nodefaults
endif
ifeq ($(VERBOSE),0)
# this set of LDFLAGS generates no warnings.
LDFLAGS := $(MAPGEN) -fp hard -nodefaults -w off
endif
LIBRARY_LDFLAGS := -nodefaults -fp hard -proc gekko
CFLAGS := -Cpp_exceptions off -O4,p -fp hard -proc gekko -nodefaults -RTTI on -common on -str noreadonly $(INCLUDES)

$(JAUDIO): CFLAGS += -func_align 32
$(MSL_C): CFLAGS += -fp_contract on
ifeq ($(VERBOSE),0)
# this set of ASFLAGS generates no warnings.
ASFLAGS += -W
# this set of CFLAGS generates no warnings.
CFLAGS += -w off
endif

#-------------------------------------------------------------------------------
# Recipes
Expand All @@ -103,14 +149,17 @@ ALL_DIRS := $(sort $(dir $(O_FILES)))
# Make sure build directory exists before compiling anything
DUMMY != mkdir -p $(ALL_DIRS)

.PHONY: tools
LDSCRIPT := ldscript.lcf

# DOL creation makefile instructions
$(DOL): $(ELF) | $(DTK)
@echo Converting $< to $@
$(QUIET) $(ELF2DOL) $< $@
$(QUIET) $(SHASUM) -c sha1/$(NAME).$(VERSION).sha1
ifneq ($(findstring -map,$(LDFLAGS)),)
$(QUIET) $(PYTHON) tools/calcprogress.py $(DOL) $(MAP)
endif
ifeq ($(USE_AOI),1)
$(WINE) ./aoi.exe
endif

clean:
rm -f -d -r build
Expand All @@ -125,21 +174,56 @@ $(ELF): $(O_FILES) $(LDSCRIPT)
$(QUIET) @echo $(O_FILES) > build/o_files
$(QUIET) $(LD) $(LDFLAGS) -o $@ -lcf $(LDSCRIPT) @build/o_files

%.d.unix: %.d $(TRANSFORM_DEP)
@echo Processing $<
$(QUIET) $(PYTHON) $(TRANSFORM_DEP) $< $@

-include include_link.mk

DEPENDS := $(DEPENDS:.d=.d.unix)
ifneq ($(MAKECMDGOALS), clean)
-include $(DEPENDS)
endif

$(BUILD_DIR)/%.o: %.s
@echo Assembling $<
$(QUIET) mkdir -p $(dir $@)
$(QUIET) $(AS) $(ASFLAGS) -o $@ $<

# for files with capitalized .C extension
$(BUILD_DIR)/%.o: %.C
@echo "Compiling " $<
$(QUIET) mkdir -p $(dir $@)
$(QUIET) $(CC) $(CFLAGS) -c -o $(dir $@) $<

$(BUILD_DIR)/%.o: %.c
@echo "Compiling " $<
$(QUIET) $(CC) $(CFLAGS) -c -o $@ $<
$(QUIET) mkdir -p $(dir $@)
$(QUIET) $(CC) $(CFLAGS) -c -o $(dir $@) $<

$(BUILD_DIR)/%.o: %.cp
@echo "Compiling " $<
$(QUIET) $(CC) $(CFLAGS) -c -o $@ $<

$(QUIET) mkdir -p $(dir $@)
$(QUIET) $(CC) $(CFLAGS) -c -o $(dir $@) $<

$(BUILD_DIR)/%.o: %.cpp
@echo "Compiling " $<
$(QUIET) $(CC) $(CFLAGS) -c -o $@ $<
$(QUIET) mkdir -p $(dir $@)
$(QUIET) $(CC) $(CFLAGS) -c -o $(dir $@) $<

### Extremely lazy recipes for generating context ###
# Example usage: make build/pikmin2.usa/src/plugProjectYamashitaU/farmMgr.h
$(BUILD_DIR)/%.h: %.c
@echo "Compiling and generating context for " $<
$(QUIET) $(CC) $(CFLAGS) -E -c -o $@ $<

$(BUILD_DIR)/%.h: %.cp
@echo "Compiling and generating context for " $<
$(QUIET) $(CC) $(CFLAGS) -E -c -o $@ $<

$(BUILD_DIR)/%.h: %.cpp
@echo "Compiling and generating context for " $<
$(QUIET) $(CC) $(CFLAGS) -E -c -o $@ $<

### Debug Print ###

Expand Down
4 changes: 2 additions & 2 deletions asm/TRK_MINNOW_DOLPHIN/mpc_7xx_603e.s
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
/* 802200E0 0021D040 7F CE 04 A6 */ mfsr r30, 0xe
/* 802200E4 0021D044 7F EF 04 A6 */ mfsr r31, 0xf
/* 802200E8 0021D048 BE 02 01 A8 */ stmw r16, 0x1a8(r2)
/* 802200EC 0021D04C 7D 4C 42 E6 */ mftb r10, 0x10c
/* 802200F0 0021D050 7D 6D 42 E6 */ mftbu r11
/* 802200EC 0021D04C 7D 4C 42 E6 */ .4byte 0x7D4C42E6 # mftb r10, 0x10c
/* 802200F0 0021D050 7D 6D 42 E6 */ .4byte 0x7D6D42E6 # mftbu r11
/* 802200F4 0021D054 7D 90 FA A6 */ mfspr r12, 0x3f0
/* 802200F8 0021D058 7D B1 FA A6 */ mfspr r13, 0x3f1
/* 802200FC 0021D05C 7D DB 02 A6 */ mfspr r14, 0x1b
Expand Down
4 changes: 2 additions & 2 deletions asm/os/OSReset.s
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
.L_801FA164:
/* 801FA164 001F70C4 48 00 00 20 */ b .L_801FA184
.L_801FA168:
/* 801FA168 001F70C8 7C AC 42 E6 */ mftb r5, 0x10c
/* 801FA168 001F70C8 7C AC 42 E6 */ .4byte 0x7CAC42E6 # mftb r5, 0x10c
.L_801FA16C:
/* 801FA16C 001F70CC 7C CC 42 E6 */ mftb r6, 0x10c
/* 801FA16C 001F70CC 7C CC 42 E6 */ .4byte 0x7CCC42E6 # mftb r6, 0x10c
/* 801FA170 001F70D0 7C E5 30 50 */ subf r7, r5, r6
/* 801FA174 001F70D4 28 07 11 24 */ cmplwi r7, 0x1124
/* 801FA178 001F70D8 41 80 FF F4 */ blt .L_801FA16C
Expand Down
8 changes: 4 additions & 4 deletions asm/os/OSTime.s
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
.include "macros.inc"
.section .text, "ax" # 0x80005560 - 0x80221F60
.fn OSGetTime, global
/* 801FD3A0 001FA300 7C 6D 42 E6 */ mftbu r3
/* 801FD3A4 001FA304 7C 8C 42 E6 */ mftb r4, 0x10c
/* 801FD3A8 001FA308 7C AD 42 E6 */ mftbu r5
/* 801FD3A0 001FA300 7C 6D 42 E6 */ .4byte 0x7C6D42E6 # mftbu r3
/* 801FD3A4 001FA304 7C 8C 42 E6 */ .4byte 0x7C8C42E6 # mftb r4, 0x10c
/* 801FD3A8 001FA308 7C AD 42 E6 */ .4byte 0x7CAD42E6 # mftbu r5
/* 801FD3AC 001FA30C 7C 03 28 00 */ cmpw r3, r5
/* 801FD3B0 001FA310 40 82 FF F0 */ bne OSGetTime
/* 801FD3B4 001FA314 4E 80 00 20 */ blr
.endfn OSGetTime

.fn OSGetTick, global
/* 801FD3B8 001FA318 7C 6C 42 E6 */ mftb r3, 0x10c
/* 801FD3B8 001FA318 7C 6C 42 E6 */ .4byte 0x7C6C42E6 # mftb r3, 0x10c
/* 801FD3BC 001FA31C 4E 80 00 20 */ blr
.endfn OSGetTick

Expand Down
Loading

0 comments on commit 17220af

Please sign in to comment.