Skip to content

Commit 135d46a

Browse files
committed
rel: Add multi-version support
1 parent 71b0a32 commit 135d46a

File tree

8 files changed

+185
-61
lines changed

8 files changed

+185
-61
lines changed

ttyd-tools/rel/Makefile

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,31 @@ include $(DEVKITPPC)/gamecube_rules
1616
export ELF2REL := $(TTYDTOOLS)/bin/elf2rel
1717
export GCIPACK := python $(TTYDTOOLS)/gcipack/gcipack.py
1818

19+
ifeq ($(VERSION),)
20+
all: us jp eu
21+
us:
22+
@$(MAKE) --no-print-directory VERSION=us
23+
jp:
24+
@$(MAKE) --no-print-directory VERSION=jp
25+
eu:
26+
@$(MAKE) --no-print-directory VERSION=eu
27+
28+
clean:
29+
@$(MAKE) --no-print-directory clean_target VERSION=us
30+
@$(MAKE) --no-print-directory clean_target VERSION=eu
31+
@$(MAKE) --no-print-directory clean_target VERSION=jp
32+
33+
.PHONY: all clean us jp eu
34+
else
35+
1936
#---------------------------------------------------------------------------------
2037
# TARGET is the name of the output
2138
# BUILD is the directory where object files & intermediate files will be placed
2239
# SOURCES is a list of directories containing source code
2340
# INCLUDES is a list of directories containing extra header files
2441
#---------------------------------------------------------------------------------
25-
TARGET := $(notdir $(CURDIR))
26-
BUILD := build
42+
TARGET := $(notdir $(CURDIR)).$(VERSION)
43+
BUILD := build.$(VERSION)
2744
SOURCES := source
2845
DATA := data
2946
INCLUDES := include
@@ -34,10 +51,20 @@ INCLUDES := include
3451

3552
MACHDEP = -mno-sdata -mgcn -DGEKKO -mcpu=750 -meabi -mhard-float
3653

37-
CFLAGS = -nostdlib -ffunction-sections -fdata-sections -g -O3 -Wall $(MACHDEP) $(INCLUDE)
54+
CFLAGS = -nostdlib -ffreestanding -ffunction-sections -fdata-sections -g -O3 -Wall $(MACHDEP) $(INCLUDE)
3855
CXXFLAGS = -fno-exceptions -fno-rtti -std=gnu++17 $(CFLAGS)
3956

40-
LDFLAGS = -r -s -e _prolog -u _prolog -u _epilog -u _unresolved -Wl,--gc-sections -nostartfiles -g $(MACHDEP) -Wl,-Map,$(notdir $@).map
57+
LDFLAGS = -r -e _prolog -u _prolog -u _epilog -u _unresolved -Wl,--gc-sections -nostdlib -g $(MACHDEP) -Wl,-Map,$(notdir $@).map
58+
59+
# Platform options
60+
ifeq ($(VERSION),us)
61+
$(CFLAGS) += -DTTYD_US
62+
else ifeq ($(VERSION),jp)
63+
$(CFLAGS) += -DTTYD_JP
64+
else ifeq ($(VERSION),eu)
65+
$(CFLAGS) += -DTTYD_EU
66+
endif
67+
4168

4269
#---------------------------------------------------------------------------------
4370
# any extra libraries we wish to link with the project
@@ -90,7 +117,7 @@ export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES)))
90117

91118
# For REL linking
92119
export LDFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.ld)))
93-
export MAPFILE := $(CURDIR)/include/ttyd.lst
120+
export MAPFILE := $(CURDIR)/include/ttyd.$(VERSION).lst
94121
export BANNERFILE := $(CURDIR)/banner.raw
95122
export ICONFILE := $(CURDIR)/icon.raw
96123

@@ -109,16 +136,16 @@ export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
109136
-L$(LIBOGC_LIB)
110137

111138
export OUTPUT := $(CURDIR)/$(TARGET)
112-
.PHONY: $(BUILD) clean
139+
.PHONY: $(BUILD) clean_target
113140

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

119146
#---------------------------------------------------------------------------------
120-
clean:
121-
@echo clean ...
147+
clean_target:
148+
@echo clean ... $(VERSION)
122149
@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol $(OUTPUT).rel $(OUTPUT).gci
123150

124151
#---------------------------------------------------------------------------------
@@ -129,8 +156,8 @@ DEPENDS := $(OFILES:.o=.d)
129156
#---------------------------------------------------------------------------------
130157
# main targets
131158
#---------------------------------------------------------------------------------
132-
$(OUTPUT).gci: $(OUTPUT).rel
133-
$(OUTPUT).rel: $(OUTPUT).elf
159+
$(OUTPUT).gci: $(OUTPUT).rel $(BANNERFILE) $(ICONFILE)
160+
$(OUTPUT).rel: $(OUTPUT).elf $(MAPFILE)
134161
$(OUTPUT).elf: $(LDFILES) $(OFILES)
135162

136163
$(OFILES_SOURCES) : $(HFILES)
@@ -157,3 +184,4 @@ $(OFILES_SOURCES) : $(HFILES)
157184
#---------------------------------------------------------------------------------
158185
endif
159186
#---------------------------------------------------------------------------------
187+
endif

ttyd-tools/rel/include/mod.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
#pragma once
22

3+
#include "timer.h"
4+
5+
#include <cstdint>
6+
37
namespace mod {
48

59
class Mod
610
{
711
public:
12+
Mod();
813
void init();
914

1015
private:
1116
void updateEarly();
1217
void draw();
1318

1419
private:
20+
Timer<uint32_t> mPalaceSkipTimer;
21+
bool mPaused = false;
22+
1523
void (*mPFN_makeKey_trampoline)() = nullptr;
1624
char mDisplayBuffer[256];
1725
};

ttyd-tools/rel/include/timer.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#pragma once
2+
3+
namespace mod {
4+
5+
template<typename ValueType>
6+
class Timer
7+
{
8+
public:
9+
Timer() {}
10+
11+
void start()
12+
{
13+
mRunning = true;
14+
}
15+
void stop()
16+
{
17+
mRunning = false;
18+
}
19+
void tick()
20+
{
21+
if (mRunning)
22+
{
23+
++mValue;
24+
}
25+
}
26+
void setValue(const ValueType &value)
27+
{
28+
mValue = value;
29+
}
30+
ValueType getValue()
31+
{
32+
return mValue;
33+
}
34+
35+
private:
36+
bool mRunning = false;
37+
ValueType mValue;
38+
};
39+
40+
}

ttyd-tools/rel/include/ttyd.lst renamed to ttyd-tools/rel/include/ttyd.us.lst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// incomplete
33
80005ff8:makeKey
44

5-
8026a0b8:_sprintf
6-
75
// memory.o
86
// unused:smartGetWorkPtr
97
8002f33c:smartTexObj

ttyd-tools/rel/include/ttyd/fontmgr.h

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,44 @@ namespace ttyd::fontmgr {
44

55
extern "C" {
66

7-
// fontmgrInit
8-
// fontmgrTexSetup
7+
void fontmgrInit();
8+
void fontmgrTexSetup();
99
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
10+
void FontDrawStart_alpha(uint8_t alpha);
11+
void FontDrawEdge();
12+
void FontDrawEdgeOff();
13+
void FontDrawRainbowColor();
14+
void FontDrawRainbowColorOff();
15+
void FontDrawNoise();
16+
void FontDrawNoiseOff();
17+
void FontDrawColorIDX(uint32_t idx);
18+
void FontDrawColor(uint8_t color[4]);
19+
void FontDrawColor_();
20+
uint32_t FontGetDrawColor();
21+
void FontDrawScale(float scale);
22+
void FontDrawScaleVec(float scale[3]);
23+
void FontDrawCode(float x, float y, uint16_t code);
24+
void FontDrawCodeMtx(float matrix[3][4], uint16_t code);
25+
void FontDrawString(float x, float y, const char *text);
26+
void FontDrawStringPitch(float x, float y, float pitch, const char *text);
27+
void FontDrawStringVecPitch(float position[3], float pitch, const char *text);
28+
void FontDrawStringMtx(float matrix[3][4], const char *text);
29+
void FontDrawStringCenterMtx(float matrix[3][4], const char *text);
30+
void FontDrawStringShake(float x, float y, const char *text);
3131
void FontDrawMessage(int x, int y, const char *message);
32-
// FontDrawMessageMtx
33-
// hankakuSearch
34-
// kanjiSearch
35-
// kanjiGetWidth
36-
// FontGetMessageWidthLine
37-
// FontGetMessageWidth
38-
// HSV2RGB
32+
void FontDrawMessageMtx(float matrix[3][4], const char *message);
33+
uint16_t FontGetMessageWidthLine(const char *message, uint16_t *outLines);
34+
uint16_t FontGetMessageWidth(const char *message);
3935

40-
// JUTFontSetup
41-
// JUTFont_Free
42-
// JUTFont_CodeToGlyph
43-
// JUTFont_DrawStart
44-
// _JUTFont_DrawPos
36+
uint16_t hankakuSearch(uint8_t code);
37+
uint16_t kanjiSearch(uint16_t code);
38+
uint8_t kanjiGetWidth(uint16_t code);
39+
uint32_t HSV2RGB(uint8_t hsv[3]);
40+
41+
void JUTFontSetup(uint32_t index);
42+
uint16_t JUTFont_CodeToGlyph(uint16_t code);
43+
void JUTFont_DrawStart(uint8_t color[4]);
44+
uint8_t _JUTFont_DrawPos(uint16_t glyph, int16_t x, int16_t y);
4545

4646
}
4747

ttyd-tools/rel/source/cxx.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ void *operator new(std::size_t size)
44
{
55
return ttyd::memory::__memAlloc(0, size);
66
}
7+
void *operator new[](std::size_t size)
8+
{
9+
return ttyd::memory::__memAlloc(0, size);
10+
}
711
void operator delete(void *ptr)
812
{
913
return ttyd::memory::__memFree(0, ptr);
10-
}
14+
}
15+
void operator delete[](void *ptr)
16+
{
17+
return ttyd::memory::__memFree(0, ptr);
18+
}

ttyd-tools/rel/source/cxx.ld

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Symbols for us to be able to call global constructors and destructors */
2-
_ctors_start = LOADADDR(.ctors);
2+
_ctors_start = ADDR(.ctors);
33
_ctors_end = _ctors_start + SIZEOF(.ctors);
4-
_dtors_start = LOADADDR(.dtors);
4+
_dtors_start = ADDR(.dtors);
55
_dtors_end = _dtors_start + SIZEOF(.dtors);

ttyd-tools/rel/source/mod.cpp

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ void main()
1818
mod->init();
1919
}
2020

21+
Mod::Mod()
22+
{
23+
24+
}
25+
2126
void Mod::init()
2227
{
2328
gMod = this;
@@ -26,26 +31,60 @@ void Mod::init()
2631
{
2732
gMod->updateEarly();
2833
});
29-
}
3034

31-
extern "C" {
32-
33-
extern void _sprintf(const char *fmt, ...);
35+
// Initialize typesetting early
36+
ttyd::fontmgr::fontmgrTexSetup();
37+
patch::hookFunction(ttyd::fontmgr::fontmgrTexSetup, [](){});
38+
}
3439

40+
static uint16_t getInput()
41+
{
42+
#ifdef TTYD_US
43+
return *reinterpret_cast<uint16_t *>(0x803CA398);
44+
#else
45+
#error getInput() not implemented for this version
46+
#endif
3547
}
3648

49+
static uint32_t getThreadExecState()
50+
{
51+
#ifdef TTYD_US
52+
return *reinterpret_cast<uint32_t *>(0x8041E940);
53+
#else
54+
#error getThreadExecState() not implemented for this version
55+
#endif
56+
}
3757

3858
void Mod::updateEarly()
3959
{
4060
// Check for font load
41-
if (*reinterpret_cast<void **>(0x8041E978) != nullptr)
61+
ttyd::dispdrv::dispEntry(ttyd::dispdrv::DisplayLayer_Dbg3d, 0, [](uint8_t layerId, void *user)
62+
{
63+
reinterpret_cast<Mod *>(user)->draw();
64+
}, this);
65+
66+
// Palace skip timing code
67+
if (getThreadExecState() == 4)
68+
{
69+
// Reset upon pausing
70+
mPalaceSkipTimer.stop();
71+
mPalaceSkipTimer.setValue(0);
72+
mPaused = true;
73+
}
74+
else if (getThreadExecState() == 0 && mPaused)
4275
{
43-
ttyd::dispdrv::dispEntry(ttyd::dispdrv::DisplayLayer_Dbg3d, 0, [](uint8_t layerId, void *user)
44-
{
45-
reinterpret_cast<Mod *>(user)->draw();
46-
}, this);
76+
// Start when unpausing
77+
mPalaceSkipTimer.start();
78+
mPaused = false;
4779
}
48-
80+
81+
if (getInput() & 0x0400)
82+
{
83+
// Stop when pressing A or X
84+
mPalaceSkipTimer.stop();
85+
}
86+
mPalaceSkipTimer.tick();
87+
4988
// Call original function
5089
mPFN_makeKey_trampoline();
5190
}
@@ -56,8 +95,11 @@ void Mod::draw()
5695
float *marioPos = *reinterpret_cast<float **>(r13 + 0x19E0) + 35;
5796
float *marioVel = *reinterpret_cast<float **>(r13 + 0x19E0) + 31;
5897

59-
_sprintf(mDisplayBuffer, "Pos: %.2f %.2f %.2f\r\nSpdY: %.2f", marioPos[0], marioPos[1], marioPos[2], marioVel[0]);
98+
sprintf(mDisplayBuffer, "Pos: %.2f %.2f %.2f\r\nSpdY: %.2f\r\nPST: %lu", marioPos[0], marioPos[1], marioPos[2], marioVel[0], mPalaceSkipTimer.getValue());
6099
ttyd::fontmgr::FontDrawStart();
100+
uint32_t color = 0xFFFFFFFF;
101+
ttyd::fontmgr::FontDrawColor(reinterpret_cast<uint8_t *>(&color));
102+
ttyd::fontmgr::FontDrawEdge();
61103
ttyd::fontmgr::FontDrawMessage(-272, -120, mDisplayBuffer);
62104
}
63105

0 commit comments

Comments
 (0)