Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuki-4ys committed Sep 16, 2023
0 parents commit 4d8005c
Show file tree
Hide file tree
Showing 14 changed files with 1,666 additions and 0 deletions.
210 changes: 210 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
BASE_RAWCODE_ADDR = 0x808E9AF0

#DISC_ID = RMCJ
#DISC_ID = RMCE
DISC_ID = RMCP
#DISC_ID = RMCK

ifeq ($(DISC_ID), RMCE)
BASE_LE_BIN = $(ROOT_DIR)/template/lecode-USA.bin
else
ifeq ($(DISC_ID), RMCP)
BASE_LE_BIN = $(ROOT_DIR)/template/lecode-PAL.bin
else
ifeq ($(DISC_ID), RMCJ)
BASE_LE_BIN = $(ROOT_DIR)/template/lecode-JAP.bin
else
ifeq ($(DISC_ID), RMCK)
BASE_LE_BIN = $(ROOT_DIR)/template/lecode-KOR.bin
endif
endif
endif
endif

# Get directory Makefile runs from
ROOT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))

#---------------------------------------------------------------------------------
# Clear the implicit built in rules
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPPC)),)
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
endif

include $(DEVKITPPC)/gamecube_rules

#---------------------------------------------------------------------------------
# rules for generating lecode-XXX.bin from .rawcode
#---------------------------------------------------------------------------------

%.bin: %.rawcode
py $(ROOT_DIR)/rawcode_2_lecode.py $(BASE_LE_BIN) $< $(BASE_RAWCODE_ADDR) $@

%.rawcode: %.elf
@echo "extracting code from $(notdir $<) ... $(notdir $@)"
@$(OBJCOPY) -O binary -S $< $@

#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# GCI_BUILD is the GCI patch builder YAML config
#---------------------------------------------------------------------------------
TARGET := $(notdir $(CURDIR))
BUILD := build
SOURCES := source source_$(DISC_ID)
DATA := data data_$(DISC_ID)
INCLUDES :=

#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------

CFLAGS = -g -Og -Wall $(MACHDEP) $(INCLUDE) -ffunction-sections -fno-builtin -nodefaultlibs -nostdlib -nostartfiles -D$(DISC_ID)
CXXFLAGS = $(CFLAGS)

LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map -nostartfiles -T $(ROOT_DIR)/linker_$(DISC_ID).ld

#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
#LIBS := -logc -lm
LIBS :=

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS :=

#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------

export OUTPUT := $(CURDIR)/$(TARGET)

export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))

export DEPSDIR := $(CURDIR)/$(BUILD)

#---------------------------------------------------------------------------------
# automatically build a list of object files for our project
#---------------------------------------------------------------------------------
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))

#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
export LD := $(CC)
else
export LD := $(CXX)
endif

export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o)
export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)

export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES)))

#---------------------------------------------------------------------------------
# build a list of include paths
#---------------------------------------------------------------------------------
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD) \
-I$(LIBOGC_INC)

#---------------------------------------------------------------------------------
# build a list of library paths
#---------------------------------------------------------------------------------
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
-L$(LIBOGC_LIB)

export OUTPUT := $(CURDIR)/$(TARGET)
.PHONY: $(BUILD) clean

#---------------------------------------------------------------------------------
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile

#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) lecode-JAP.elf lecode-JAP.rawcode lecode-JAP.bin
#---------------------------------------------------------------------------------
else

DEPENDS := $(OFILES:.o=.d)

#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------

ifeq ($(DISC_ID), RMCE)
lecode-USA.bin: lecode-USA.rawcode
lecode-USA.rawcode: lecode-USA.elf
lecode-USA.elf: $(OFILES)
else
ifeq ($(DISC_ID), RMCP)
lecode-PAL.bin: lecode-PAL.rawcode
lecode-PAL.rawcode: lecode-PAL.elf
lecode-PAL.elf: $(OFILES)
else
ifeq ($(DISC_ID), RMCJ)
lecode-JAP.bin: lecode-JAP.rawcode
lecode-JAP.rawcode: lecode-JAP.elf
lecode-JAP.elf: $(OFILES)
else
ifeq ($(DISC_ID), RMCK)
lecode-KOR.bin: lecode-KOR.rawcode
lecode-KOR.rawcode: lecode-KOR.elf
lecode-KOR.elf: $(OFILES)
endif
endif
endif
endif

$(OFILES_SOURCES) : $(HFILES)

#---------------------------------------------------------------------------------
# This rule links in binary data with the .bin extension
#---------------------------------------------------------------------------------
%.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
$(bin2o)

#---------------------------------------------------------------------------------
# This rule links in binary data with the .szs extension
#---------------------------------------------------------------------------------
%.szs.o : %.szs
#---------------------------------------------------------------------------------
@echo $(notdir $<)
$(bin2o)

#---------------------------------------------------------------------------------
# This rule links in binary data with the .gct extension
#---------------------------------------------------------------------------------
%.gct.o : %.gct
#---------------------------------------------------------------------------------
@echo $(notdir $<)
$(bin2o)

-include $(DEPENDS)

#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
47 changes: 47 additions & 0 deletions linker_RMCE.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
ENTRY(__main)
SECTIONS
{
.text 0x808E9AF0 : {
*(.text.__main);
*(.text*);
}
myGlobalVarPtr = 0x80000CC0;
OSReport = 0x801a2530;
strcmp = 0x8001273c;
Egg__Heap__Alloc = 0x80229490;
DVDConvertPathToEntryNum = 0x8015deac;
DvdArchive__ripFile = 0x80514c7c;
DVDFastOpen = 0x8015e1b4;
DVDReadPrio = 0x8015e794;
DVDClose = 0x8015e4c8;
memcpy = 0x80005f34;
memcmp = 0x8000e7b4;
strncpy = 0x80012680;
sprintf = 0x80010ecc;
NETCalcCRC32 = 0x801d1c00;
strlen = 0x800206f4;
ControlLoader__Load = 0x805ba2cc;
ISFS_Open = 0x8016adbc;
ISFS_Close = 0x8016b2e4;
OSLaunchTitle = 0x801ad960;
bmg_func = 0x805d840c;
IOS_Open = 0x80193858;
IOS_Close = 0x80193a38;
MultiDvdArchive__clear = 0x805267cc;
IOS_IoctlAsync = 0x801940b8;
IOS_IoctlvAsync = 0x8019445c;
IOS_OpenAsync = 0x80193740;
IOS_CloseAsync = 0x80193978;
DCFlushRange = 0x801a158c;
VIResetDimmingCount = 0x801bb00c;
Egg__ExpHeap__create = 0x80226744;
sSystem__Q23EGG10BaseSystem = 0x80382bd8;
nw4r__ut__List_GetNext = 0x800af0e0;
RACEDATA = 0x809B8F68;
SubtractTimers = 0x808423FC;
trackMusicSpeedUpPatch4PlusCLwzAddr = 0x809BDC10;
Egg__Heap__Free = 0x80229800;
ISFS_Read = 0x8016b15c;
menu_pointer = 0x809bd508;
lecodeEntry = 0x808dd6b0;
}
48 changes: 48 additions & 0 deletions linker_RMCJ.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
ENTRY(__main)
SECTIONS
{
.text 0x808E9AF0 : {
*(.text.__main);
*(.text*);
}
myGlobalVarPtr = 0x80000CC0;
OSReport = 0x801A24F0;
strcmp = 0x800131C0;
Egg__Heap__Alloc = 0x80229734;
DVDConvertPathToEntryNum = 0x8015DE6C;
DvdArchive__ripFile = 0x80518a70;
DVDFastOpen = 0x8015E174;
DVDReadPrio = 0x8015E754;
DVDClose = 0x8015E488;
memcpy = 0x80005F34;
memcmp = 0x8000F238;
strncpy = 0x80013104;
sprintf = 0x80011950;
strcmp = 0x800131c0;
NETCalcCRC32 = 0x801d1bc0;
strlen = 0x80021178;
ControlLoader__Load = 0x805c25e0;
ISFS_Open = 0x8016ad7c;
ISFS_Close = 0x8016b2a4;
OSLaunchTitle = 0x801AD920;
bmg_func = 0x805F85CC;
IOS_Open = 0x80193818;
IOS_Close = 0x801939f8;
MultiDvdArchive__clear = 0x8052a5c0;
IOS_IoctlAsync = 0x80194078;
IOS_IoctlvAsync = 0x8019441c;
IOS_OpenAsync = 0x80193700;
IOS_CloseAsync = 0x80193938;
DCFlushRange = 0x801a154c;
VIResetDimmingCount = 0x801bafcc;
Egg__ExpHeap__create = 0x802269e8;
sSystem__Q23EGG10BaseSystem = 0x803868e0;
nw4r__ut__List_GetNext = 0x800af0a0;
RACEDATA = 0x809BC788;
SubtractTimers = 0x807EDECC;
trackMusicSpeedUpPatch4PlusCLwzAddr = 0x809C18B0;
Egg__Heap__Free = 0x80229aa4;
ISFS_Read = 0x8016b11c;
menu_pointer = 0x809C0E98;
lecodeEntry = 0x808dd6b0;
}
47 changes: 47 additions & 0 deletions linker_RMCP.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
ENTRY(__main)
SECTIONS
{
.text 0x808E9AF0 : {
*(.text.__main);
*(.text*);
}
myGlobalVarPtr = 0x80000CC0;
OSReport = 0x801a25d0;
strcmp = 0x8001329c;
Egg__Heap__Alloc = 0x80229814;
DVDConvertPathToEntryNum = 0x8015df4c;
DvdArchive__ripFile = 0x805190f0;
DVDFastOpen = 0x8015e254;
DVDReadPrio = 0x8015e834;
DVDClose = 0x8015e568;
memcpy = 0x80005F34;
memcmp = 0x8000f314;
strncpy = 0x800131e0;
sprintf = 0x80011a2c;
NETCalcCRC32 = 0x801d1ca0;
strlen = 0x80021254;
ControlLoader__Load = 0x805c2c60;
ISFS_Open = 0x8016ae5c;
ISFS_Close = 0x8016b384;
OSLaunchTitle = 0x801ada00;
bmg_func = 0x805f8cf0;
IOS_Open = 0x801938f8;
IOS_Close = 0x80193ad8;
MultiDvdArchive__clear = 0x8052ac40;
IOS_IoctlAsync = 0x80194158;
IOS_IoctlvAsync = 0x801944fc;
IOS_OpenAsync = 0x801937e0;
IOS_CloseAsync = 0x80193a18;
DCFlushRange = 0x801a162c;
VIResetDimmingCount = 0x801bb0ac;
Egg__ExpHeap__create = 0x80226ac8;
sSystem__Q23EGG10BaseSystem = 0x80386f60;
nw4r__ut__List_GetNext = 0x800af180;
RACEDATA = 0x809bd728;
SubtractTimers = 0x807ee860;
trackMusicSpeedUpPatch4PlusCLwzAddr = 0x809C2850;
Egg__Heap__Free = 0x80229B84;
ISFS_Read = 0x8016b1fc;
menu_pointer = 0x809c1e38;
lecodeEntry = 0x808dd6b0;
}
Loading

0 comments on commit 4d8005c

Please sign in to comment.