Skip to content

Commit c02ba1c

Browse files
committed
Add rel demo
1 parent 2bdbf3f commit c02ba1c

File tree

16 files changed

+563
-0
lines changed

16 files changed

+563
-0
lines changed

ttyd-tools/rel/Makefile

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#---------------------------------------------------------------------------------
2+
# Clear the implicit built in rules
3+
#---------------------------------------------------------------------------------
4+
.SUFFIXES:
5+
#---------------------------------------------------------------------------------
6+
ifeq ($(strip $(DEVKITPPC)),)
7+
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
8+
endif
9+
10+
ifeq ($(strip $(TTYDTOOLS)),)
11+
$(error "Please set TTYDTOOLS in your environment. export TTYDTOOLS=<path to>ttyd-tools")
12+
endif
13+
14+
include $(DEVKITPPC)/gamecube_rules
15+
16+
export ELF2REL := $(TTYDTOOLS)/bin/elf2rel
17+
export GCIPACK := python $(TTYDTOOLS)/gcipack/gcipack.py
18+
19+
#---------------------------------------------------------------------------------
20+
# TARGET is the name of the output
21+
# BUILD is the directory where object files & intermediate files will be placed
22+
# SOURCES is a list of directories containing source code
23+
# INCLUDES is a list of directories containing extra header files
24+
#---------------------------------------------------------------------------------
25+
TARGET := $(notdir $(CURDIR))
26+
BUILD := build
27+
SOURCES := source
28+
DATA := data
29+
INCLUDES := include
30+
31+
#---------------------------------------------------------------------------------
32+
# options for code generation
33+
#---------------------------------------------------------------------------------
34+
35+
MACHDEP = -mno-sdata -mgcn -DGEKKO -mcpu=750 -meabi -mhard-float
36+
37+
CFLAGS = -nostdlib -ffunction-sections -fdata-sections -g -O3 -Wall $(MACHDEP) $(INCLUDE)
38+
CXXFLAGS = -fno-exceptions -fno-rtti -std=gnu++17 $(CFLAGS)
39+
40+
LDFLAGS = -r -s -e _prolog -u _prolog -u _epilog -u _unresolved -Wl,--gc-sections -nostartfiles -g $(MACHDEP) -Wl,-Map,$(notdir $@).map
41+
42+
#---------------------------------------------------------------------------------
43+
# any extra libraries we wish to link with the project
44+
#---------------------------------------------------------------------------------
45+
LIBS := -lm
46+
47+
#---------------------------------------------------------------------------------
48+
# list of directories containing libraries, this must be the top level containing
49+
# include and lib
50+
#---------------------------------------------------------------------------------
51+
LIBDIRS :=
52+
53+
#---------------------------------------------------------------------------------
54+
# no real need to edit anything past this point unless you need to add additional
55+
# rules for different file extensions
56+
#---------------------------------------------------------------------------------
57+
ifneq ($(BUILD),$(notdir $(CURDIR)))
58+
#---------------------------------------------------------------------------------
59+
60+
export OUTPUT := $(CURDIR)/$(TARGET)
61+
62+
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
63+
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
64+
65+
export DEPSDIR := $(CURDIR)/$(BUILD)
66+
67+
#---------------------------------------------------------------------------------
68+
# automatically build a list of object files for our project
69+
#---------------------------------------------------------------------------------
70+
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
71+
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
72+
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
73+
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
74+
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
75+
76+
#---------------------------------------------------------------------------------
77+
# use CXX for linking C++ projects, CC for standard C
78+
#---------------------------------------------------------------------------------
79+
ifeq ($(strip $(CPPFILES)),)
80+
export LD := $(CC)
81+
else
82+
export LD := $(CXX)
83+
endif
84+
85+
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
86+
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o)
87+
export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)
88+
89+
export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES)))
90+
91+
# For REL linking
92+
export LDFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.ld)))
93+
export MAPFILE := $(CURDIR)/include/ttyd.lst
94+
export BANNERFILE := $(CURDIR)/banner.raw
95+
export ICONFILE := $(CURDIR)/icon.raw
96+
97+
#---------------------------------------------------------------------------------
98+
# build a list of include paths
99+
#---------------------------------------------------------------------------------
100+
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
101+
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
102+
-I$(CURDIR)/$(BUILD) \
103+
-I$(LIBOGC_INC)
104+
105+
#---------------------------------------------------------------------------------
106+
# build a list of library paths
107+
#---------------------------------------------------------------------------------
108+
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
109+
-L$(LIBOGC_LIB)
110+
111+
export OUTPUT := $(CURDIR)/$(TARGET)
112+
.PHONY: $(BUILD) clean
113+
114+
#---------------------------------------------------------------------------------
115+
$(BUILD):
116+
@[ -d $@ ] || mkdir -p $@
117+
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
118+
119+
#---------------------------------------------------------------------------------
120+
clean:
121+
@echo clean ...
122+
@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol $(OUTPUT).rel $(OUTPUT).gci
123+
124+
#---------------------------------------------------------------------------------
125+
else
126+
127+
DEPENDS := $(OFILES:.o=.d)
128+
129+
#---------------------------------------------------------------------------------
130+
# main targets
131+
#---------------------------------------------------------------------------------
132+
$(OUTPUT).gci: $(OUTPUT).rel
133+
$(OUTPUT).rel: $(OUTPUT).elf
134+
$(OUTPUT).elf: $(LDFILES) $(OFILES)
135+
136+
$(OFILES_SOURCES) : $(HFILES)
137+
138+
# REL linking
139+
%.rel: %.elf
140+
@echo output ... $(notdir $@)
141+
@$(ELF2REL) $< $(MAPFILE)
142+
143+
%.gci: %.rel
144+
@echo packing ... $(notdir $@)
145+
@$(GCIPACK) $< "rel" "Paper Mario" "TTYD Debug Menu" $(BANNERFILE) $(ICONFILE)
146+
147+
#---------------------------------------------------------------------------------
148+
# This rule links in binary data with the .jpg extension
149+
#---------------------------------------------------------------------------------
150+
%.jpg.o %_jpg.h : %.jpg
151+
#---------------------------------------------------------------------------------
152+
@echo $(notdir $<)
153+
$(bin2o)
154+
155+
-include $(DEPENDS)
156+
157+
#---------------------------------------------------------------------------------
158+
endif
159+
#---------------------------------------------------------------------------------

ttyd-tools/rel/banner.raw

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

ttyd-tools/rel/icon.raw

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

ttyd-tools/rel/include/mod.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#pragma once
2+
3+
namespace mod {
4+
5+
class Mod
6+
{
7+
public:
8+
void init();
9+
10+
private:
11+
void updateEarly();
12+
void draw();
13+
14+
private:
15+
void (*mPFN_makeKey_trampoline)() = nullptr;
16+
char mDisplayBuffer[256];
17+
};
18+
19+
}

ttyd-tools/rel/include/patch.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
5+
namespace mod::patch {
6+
7+
void writeBranch(void *ptr, void *destination);
8+
9+
template<typename Func, typename Dest>
10+
Func hookFunction(Func function, Dest destination)
11+
{
12+
uint32_t *instructions = reinterpret_cast<uint32_t *>(function);
13+
14+
uint32_t *trampoline = new uint32_t[2];
15+
// Original instruction
16+
trampoline[0] = instructions[0];
17+
// Branch to original function past hook
18+
writeBranch(&trampoline[1], &instructions[1]);
19+
20+
// Write actual hook
21+
writeBranch(&instructions[0], reinterpret_cast<void *>(static_cast<Func>(destination)));
22+
23+
return reinterpret_cast<Func>(trampoline);
24+
}
25+
26+
}

ttyd-tools/rel/include/ttyd.lst

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// system.o
2+
// incomplete
3+
80005ff8:makeKey
4+
5+
8026a0b8:_sprintf
6+
7+
// memory.o
8+
// unused:smartGetWorkPtr
9+
8002f33c:smartTexObj
10+
8002f378:smartGarbage
11+
8002f540:smartAlloc
12+
8002f878:smartFree
13+
8002f9cc:smartAutoFree
14+
8002fa70:smartReInit
15+
8002fbe0:smartInit
16+
// unused:_mapAllocDump
17+
8002fdc4:_mapFree
18+
8002fe60:_mapAllocTail
19+
8002ff58:_mapAlloc
20+
// 80030048:zz_80030048_
21+
// 80030078:zz_80030078_
22+
800300c4:__memFree
23+
800300f0:__memAlloc
24+
80030154:memClear
25+
80030218:memInit
26+
27+
// fontmgr.o
28+
// unused:JUTFont_Draw
29+
// unused:JUTFont_DrawPos
30+
80074720:_JUTFont_DrawPos
31+
80074bfc:JUTFont_DrawStart
32+
// unused:JUTFont_GetWidth
33+
// unused:JUTFont_GetWidthEntry
34+
80074e90:JUTFont_CodeToGlyph
35+
// unused:JUTFont_Free
36+
80075004:JUTFontSetup
37+
// unused:JUTFont_SetWidth
38+
800752fc:HSV2RGB
39+
80075528:FontGetMessageWidth
40+
8007554c:FontGetMessageWidthLine
41+
8007586c:kanjiGetWidth
42+
800758e4:kanjiSearch
43+
80075904:hankakuSearch
44+
80075928:FontDrawMessageMtx
45+
80075fcc:FontDrawMessage
46+
800766e0:FontDrawStringShake
47+
80076a10:FontDrawStringCenterMtx
48+
// unused:FontDrawStringCenter
49+
80076cdc:FontDrawStringMtx
50+
80077034:FontDrawStringVecPitch
51+
80077368:FontDrawStringPitch
52+
// unused:FontDrawStringVec
53+
800773d0:FontDrawString
54+
80077438:FontDrawCodeMtx
55+
80077594:FontDrawCode
56+
8007773c:FontDrawScaleVec
57+
80077758:FontDrawScale
58+
8007776c:FontGetDrawColor
59+
80077774:FontDrawColor_
60+
800777e0:FontDrawColor
61+
80077844:FontDrawColorIDX
62+
800778b4:FontDrawNoiseOff
63+
800778e0:FontDrawNoise
64+
800779e4:FontDrawRainbowColorOff
65+
80077a08:FontDrawRainbowColor
66+
80077aa8:FontDrawEdgeOff
67+
80077ab4:FontDrawEdge
68+
80077ac0:FontDrawStart_alpha
69+
80077b4c:FontDrawStart
70+
80077bdc:fontmgrTexSetup
71+
80077c08:fontmgrInit
72+
73+
// dispdrv.o
74+
// unused:dispGetEntNum
75+
80010864:dispGetCurWork
76+
8001086c:dispCalcZ
77+
80010900:dispDraw
78+
80010b5c:dispSort
79+
// 80010b90:_sort
80+
80010bc4:dispEntry
81+
80010c64:dispReInit
82+
80010c70:dispInit
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
5+
namespace ttyd::dispdrv {
6+
7+
enum DisplayLayer
8+
{
9+
DisplayLayer_Off = 0,
10+
DisplayLayer_Off2,
11+
DisplayLayer_Shadow,
12+
DisplayLayer_Bg,
13+
DisplayLayer_3d,
14+
DisplayLayer_3deff_A,
15+
DisplayLayer_3dimg,
16+
DisplayLayer_3deff_B,
17+
DisplayLayer_2d,
18+
DisplayLayer_Fade,
19+
DisplayLayer_Fade2,
20+
DisplayLayer_Dbg,
21+
DisplayLayer_Dbg3d,
22+
};
23+
24+
typedef void (*PFN_dispCallback)(uint8_t layerId, void *user);
25+
26+
struct DisplayWork
27+
{
28+
uint8_t layer;
29+
uint8_t renderMode;
30+
uint16_t padding_2;
31+
float unk_4;
32+
PFN_dispCallback callback;
33+
void *user;
34+
} __attribute__((__packed__));
35+
36+
extern "C" {
37+
38+
void dispInit();
39+
void dispReInit();
40+
void dispEntry(uint8_t layerId, uint8_t renderMode, PFN_dispCallback callback, void *user);
41+
void dispSort();
42+
void dispDraw(uint8_t layerId);
43+
// float dispCalcZ(void *vecUnk);
44+
DisplayWork *dispGetCurWork();
45+
46+
}
47+
48+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#pragma once
2+
3+
namespace ttyd::fontmgr {
4+
5+
extern "C" {
6+
7+
// fontmgrInit
8+
// fontmgrTexSetup
9+
void FontDrawStart();
10+
// FontDrawStart_alpha
11+
// FontDrawEdge
12+
// FontDrawEdgeOff
13+
// FontDrawRainbowColor
14+
// FontDrawRainbowColorOff
15+
// FontDrawNoise
16+
// FontDrawNoiseOff
17+
// FontDrawColorIDX
18+
// FontDrawColor
19+
// FontDrawColor_
20+
// FontGetDrawColor
21+
// FontDrawScale
22+
// FontDrawScaleVec
23+
// FontDrawCode
24+
// FontDrawCodeMtx
25+
// FontDrawString
26+
// FontDrawStringPitch
27+
// FontDrawStringVecPitch
28+
// FontDrawStringMtx
29+
// FontDrawStringCenterMtx
30+
// FontDrawStringShake
31+
void FontDrawMessage(int x, int y, const char *message);
32+
// FontDrawMessageMtx
33+
// hankakuSearch
34+
// kanjiSearch
35+
// kanjiGetWidth
36+
// FontGetMessageWidthLine
37+
// FontGetMessageWidth
38+
// HSV2RGB
39+
40+
// JUTFontSetup
41+
// JUTFont_Free
42+
// JUTFont_CodeToGlyph
43+
// JUTFont_DrawStart
44+
// _JUTFont_DrawPos
45+
46+
}
47+
48+
}

0 commit comments

Comments
 (0)