Compare commits

...

1 Commits

Author SHA1 Message Date
coah
93241d6d99 tiInputForm: convert 11 asm bodies to C (worker 392d5810) 2026-09-30 00:25:06 +00:00
5 changed files with 144 additions and 239 deletions

View File

@@ -351,6 +351,10 @@ namespace textinput {
virtual void setRootPaneScaleFor16x9();
virtual void setRootPaneScaleFor4x3();
#ifdef TIINPUTFORM_IMPLEMENTATION
virtual void onSE(sound::SE seId);
#endif
virtual void visibleSeparator(bool flag);
#if defined(MYTIINPUTFORM_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION)

View File

@@ -72,6 +72,9 @@ namespace textinput {
#ifdef TIINPUTFORM_IMPLEMENTATION
enum TranslateMode { TM_Direct, TM_Kana, TM_Roman, TM_Hangul };
virtual void clear();
virtual void set(const wchar_t* string);
virtual void setLength(u16 length);
void setTranslateMode(TranslateMode mode);
TranslateMode getTranslateMode() const { return static_cast<TranslateMode>(mTranslateMode); }
void inputString(const wchar_t* string, TranslateMode mode);

View File

@@ -82,9 +82,15 @@ namespace textinput {
virtual u32 getEndPos() const;
// todo
#ifdef TIINPUTFORM_IMPLEMENTATION
virtual void setDrawModifyScopeLine(s32 startLine, s32 endLine);
virtual void setDrawCacheScopeLine(s32 startLine, s32 endLine);
virtual void modifyCursorCache(s32 line, u32 position, f32 x, f32 y, f32 width, f32 height);
#else
virtual void setDrawModifyScopeLine();
virtual void setDrawCacheScopeLine();
virtual void modifyCursorCache();
#endif
#ifdef TIINPUTFORM_IMPLEMENTATION
virtual bool isEnableCursorCache() const;
#else

View File

@@ -40,6 +40,15 @@ enum KeyType {
KT_NormalButton
};
class EventHandler : public nw4rmanager::TiEventHandler {
public:
EventHandler(LayoutByNW4R* form) : mpInputForm(form) {}
virtual ~EventHandler();
virtual void onTiEvent(gui::PaneComponent* component, u32 event, Input* input);
private:
LayoutByNW4R* mpInputForm;
};
class AnmPane : public nw4rmanager::AnmPane {
public:
AnmPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer) : nw4rmanager::AnmPane(pane, observer), meState(ANM_Normal) {}
@@ -60,14 +69,7 @@ public:
virtual void onAnmEvent(AnmPaneEvent event);
};
class EventHandler : public nw4rmanager::TiEventHandler {
public:
EventHandler(LayoutByNW4R* form) : mpInputForm(form) {}
virtual ~EventHandler();
virtual void onTiEvent(gui::PaneComponent* component, u32 event, Input* input);
private:
LayoutByNW4R* mpInputForm;
};
nw4r::ut::Color csUnInputedWCharColor(200, 50, 50, 255);
nw4r::ut::Color csCharColor(20, 20, 20, 255);
@@ -922,55 +924,19 @@ void Base::dirtyCacheAll() {
dirtyCursorCache();
dirtyDrawCache();
}
extern "C" asm void initZiString__Q39textinput9inputform4BaseFv() {
nofralloc
stwu r1, -0x10(r1)
mflr r0
stw r0, 0x14(r1)
stw r31, 0xc(r1)
mr r31, r3
lwz r3, 0x16c(r3)
bl clearCandidates__Q39textinput8tistring6WithZiFv
li r0, 0
stb r0, 0x1f4(r31)
lwz r31, 0xc(r1)
lwz r0, 0x14(r1)
mtlr r0
addi r1, r1, 0x10
blr
void Base::initZiString() {
mpZiString->clearCandidates();
mbZuSelected = false;
}
extern "C" asm void resetContextPredict___Q39textinput9inputform4BaseFv() {
nofralloc
stwu r1, -0x10(r1)
mflr r0
li r4, 0
stw r0, 0x14(r1)
stw r31, 0xc(r1)
mr r31, r3
bl getCurrentString__Q39textinput9inputform4BaseFb
lwz r3, 0x16c(r31)
cmpwi r3, 0
beq resetContextPredict_L1
lwz r0, 0x1f0(r31)
cmpwi r0, 8
bne resetContextPredict_L1
li r4, 0
bl setCurrentWord__Q39textinput8tistring6WithZiFPCw
lwz r3, 0x16c(r31)
bl update__Q39textinput8tistring6WithZiFv
lwz r12, 0(r31)
mr r3, r31
lwz r12, 0xd8(r12)
mtctr r12
bctrl
resetContextPredict_L1:
lwz r0, 0x14(r1)
lwz r31, 0xc(r1)
mtlr r0
addi r1, r1, 0x10
blr
void Base::resetContextPredict_() {
getCurrentString(false);
resetPredictionContext();
}
static GXColor kanaBackground = {128, 255, 128, 255};
static GXColor candidateBackground = {255, 210, 12, 255};
const char* csScrollButtonAnimationTarget = lbl_8165C820;
struct InputFormAnimationFile {
u32 id;
char fileName[0x40];
@@ -996,19 +962,19 @@ extern "C" const void* csVisiblePaneUEJ__Q29textinput9inputform[9] = {
0,
0,
0,
lbl_816973A4,
lbl_816973AC,
"N_KOR",
"N_CHN",
0,
0,
};
extern "C" const void* csVisiblePaneKOR__Q29textinput9inputform[9] = {
(const void*)0x00010002,
lbl_816973A4,
"N_KOR",
0,
0,
0,
lbl_816973AC,
"N_CHN",
lbl_8165C8C0,
0,
0,
@@ -1016,11 +982,11 @@ extern "C" const void* csVisiblePaneKOR__Q29textinput9inputform[9] = {
extern "C" const void* csVisiblePaneCHN__Q29textinput9inputform[10] = {
(const void*)0x00010002,
lbl_816973AC,
"N_CHN",
0,
0,
0,
lbl_816973A4,
"N_KOR",
lbl_8165C8C0,
0,
0,
@@ -1084,7 +1050,7 @@ extern "C" const f64 lbl_81694D80 = 4503599627370496.0;
extern "C" const f32 lbl_81694D88 = 15.0f;
extern "C" f32 lbl_81698D1C;
bool mbHyphen;
bool mbHyphen = true;
#pragma push
#pragma section const_type ".data"
@@ -1098,8 +1064,6 @@ struct ButtonAnimations {
const InputFormAnimationFile* files[12];
};
const char* csScrollButtonAnimationTarget = lbl_8165C820;
const ButtonAnimations csButtonAnimations[] = {
{KT_NormalButton, lbl_8165C820, 8, NULL, {
&csAninationFile__Q29textinput9inputform[0], &csAninationFile__Q29textinput9inputform[1],
@@ -1786,20 +1750,21 @@ void LayoutByNW4R::create(MEMAllocator* allocator, EditBuffer* editBuffer) {
mriManager.mpAllocator = allocator;
mriManager.mpInfo = static_cast<Info_*>(MEMAllocFromAllocator(allocator, (mriManager.mMaxLength + 2) * sizeof(Info_)));
mriManager.init();
Info_* selected = &mriManager.mpInfo[mriManager.mpInfo[mriManager.mMaxLength].Next];
Info_* rows = mriManager.mpInfo;
Info_* selected = &rows[rows[mriManager.mMaxLength].Next];
u16 previous = selected->Back;
u16 next = selected->Next;
u16 selectedIndex = mriManager.mpInfo[next].Back;
mriManager.mpInfo[next].Back = previous;
mriManager.mpInfo[previous].Next = next;
u16 selectedIndex = rows[next].Back;
rows[next].Back = previous;
rows[previous].Next = next;
selected->Back = selectedIndex;
selected->Next = selectedIndex;
Info_* listEnd = &mriManager.mpInfo[mriManager.mpInfo[static_cast<u16>(mriManager.mMaxLength + 1)].Back];
Info_* listEnd = &rows[rows[static_cast<u16>(mriManager.mMaxLength + 1)].Back];
next = listEnd->Next;
selected->Back = mriManager.mpInfo[next].Back;
selected->Back = rows[next].Back;
selected->Next = next;
listEnd->Next = selectedIndex;
mriManager.mpInfo[next].Back = selectedIndex;
rows[next].Back = selectedIndex;
selected->StrCount = 0;
selected->DispRowCount = 1;
mpCursorLine = selected;
@@ -2392,31 +2357,9 @@ extern "C" asm void deselectCandidate__Q39textinput9inputform4BaseFv() {
blr
}
extern "C" asm void resetRelation__Q39textinput9inputform4BaseFv() {
nofralloc
stwu r1, -0x10(r1)
mflr r0
stw r0, 0x14(r1)
stw r31, 0xc(r1)
mr r31, r3
lwz r3, 0x1d4(r3)
lwz r12, 0(r3)
lwz r12, 0x6c(r12)
mtctr r12
bctrl
li r0, 0
stb r0, 0x15(r3)
stb r0, 0x16(r3)
lwz r3, 0x168(r31)
lwz r12, 0(r3)
lwz r12, 0x128(r12)
mtctr r12
bctrl
lwz r0, 0x14(r1)
lwz r31, 0xc(r1)
mtlr r0
addi r1, r1, 0x10
blr
void Base::resetRelation() {
mpManager->getHWKeyboard()->resetQuoteState();
mpUnfixString->resetRelation();
}
extern "C" asm void init__Q39textinput9inputform4BaseFv() {
@@ -4528,11 +4471,12 @@ extern "C" asm void __ct__Q39textinput9inputform4BaseFPQ29textinput7Manager() {
extern "C" asm void init__Q29textinput4BaseFv() {
nofralloc
blr
}
void Base::init() {}
namespace inputform {
@@ -4551,13 +4495,14 @@ extern "C" asm void init__Q29textinput4BaseFv() {
extern "C" asm void getLine__Q39textinput10textdrawer4BaseFv() {
nofralloc
lwz r3, 0xa0(r3)
addi r3, r3, 1
blr
}
int textdrawer::Base::getLine() {
return muLine + 1;
}
namespace inputform {
@@ -4586,27 +4531,23 @@ extern "C" asm void getKanaBuffer__Q39textinput8tistring9DecolatedFv() {
extern "C" asm void hasCandidate__Q39textinput8tistring10StringBaseCFv() {
nofralloc
lhz r3, 0x10(r3)
neg r0, r3
or r0, r0, r3
srwi r3, r0, 31
blr
}
extern "C" asm void create__Q39textinput9inputform4BaseFP12MEMAllocator() {
nofralloc
blr
bool tistring::StringBase::hasCandidate() const {
return mwcCandidate != 0;
}
namespace inputform {
void Base::create(MEMAllocator*) {}
extern "C" asm void setVIWidth__Q39textinput10textdrawer4BaseFf() {
nofralloc
stfs f1, 0x98(r3)
@@ -4644,13 +4585,8 @@ f32 textinput::util::Animation::getValue() {
namespace inputform {
extern "C" asm void onSE__Q39textinput9inputform12LayoutByNW4RFQ39textinput5sound2SE() {
nofralloc
lwz r3, 0x22c(r3)
lwz r12, 0(r3)
lwz r12, 0x14(r12)
mtctr r12
bctr
void LayoutByNW4R::onSE(sound::SE seId) {
mpEventObserver->onSE(seId);
}
extern "C" asm void addSender__Q29textinput15CommandReceiverFPQ29textinput13CommandSender() {
nofralloc
@@ -4784,51 +4720,27 @@ u32 textdrawer::Base::getStartPos() const {
}
namespace inputform {
extern "C" asm void set__Q39textinput8tistring9DecolatedFPCw() {
nofralloc
stwu r1, -0x10(r1)
mflr r0
stw r0, 0x14(r1)
stw r31, 0xc(r1)
mr r31, r3
bl set__Q39textinput8tistring10StringBaseFPCw
lwz r12, 0(r31)
mr r3, r31
lwz r12, 0x1c(r12)
mtctr r12
bctrl
clrlwi r0, r3, 16
stw r0, 0x18(r31)
stw r0, 0x1c(r31)
lwz r31, 0xc(r1)
lwz r0, 0x14(r1)
mtlr r0
addi r1, r1, 0x10
blr
}
extern "C" asm void clear__Q39textinput8tistring9DecolatedFv() {
nofralloc
stwu r1, -0x10(r1)
mflr r0
stw r0, 0x14(r1)
stw r31, 0xc(r1)
mr r31, r3
bl clear__Q39textinput8tistring10StringBaseFv
li r0, 0
mr r3, r31
stw r0, 0x18(r31)
stw r0, 0x1c(r31)
stb r0, 0x20(r31)
lwz r12, 0(r31)
lwz r12, 0xb8(r12)
mtctr r12
bctrl
lwz r0, 0x14(r1)
lwz r31, 0xc(r1)
mtlr r0
addi r1, r1, 0x10
blr
void tistring::Decolated::set(const wchar_t* string) {
StringBase::set(string);
u32 length = getLength();
mCursorStart = length;
mCursorEnd = length;
}
namespace inputform {
}
void tistring::Decolated::clear() {
StringBase::clear();
mCursorStart = 0;
mCursorEnd = 0;
mbSustain = false;
initKanaConverter();
}
namespace inputform {
extern "C" asm void init__Q49textinput9inputform4Base14RowInfoManagerFv() {
nofralloc
li r8, 0
@@ -5028,73 +4940,22 @@ create_EditBuffer_L3:
addi r1, r1, 0x20
blr
}
extern "C" asm void __dt__Q39textinput9inputform10EditBufferFv() {
nofralloc
stwu r1, -0x10(r1)
mflr r0
cmpwi r3, 0
stw r0, 0x14(r1)
stw r31, 0xc(r1)
mr r31, r4
stw r30, 8(r1)
mr r30, r3
beq __dt_EditBuffer_L1
lwz r0, 4(r3)
lis r4, __vt__Q39textinput9inputform10EditBuffer@ha
addi r4, r4, __vt__Q39textinput9inputform10EditBuffer@l
cmpwi r0, 0
stw r4, 0(r3)
beq __dt_EditBuffer_L2
mr r3, r0
li r4, -1
lwz r12, 0(r3)
lwz r12, 8(r12)
mtctr r12
bctrl
lwz r3, 0x10(r30)
lwz r4, 4(r30)
bl MEMFreeToAllocator
__dt_EditBuffer_L2:
lwz r3, 8(r30)
cmpwi r3, 0
beq __dt_EditBuffer_L3
lwz r12, 0(r3)
li r4, -1
lwz r12, 8(r12)
mtctr r12
bctrl
lwz r3, 0x10(r30)
lwz r4, 8(r30)
bl MEMFreeToAllocator
__dt_EditBuffer_L3:
lwz r3, 0xc(r30)
cmpwi r3, 0
beq __dt_EditBuffer_L4
lwz r12, 0(r3)
li r4, -1
lwz r12, 8(r12)
mtctr r12
bctrl
lwz r3, 0x10(r30)
lwz r4, 0xc(r30)
bl MEMFreeToAllocator
__dt_EditBuffer_L4:
li r0, 0
cmpwi r31, 0
stw r0, 4(r30)
stw r0, 8(r30)
stw r0, 0xc(r30)
ble __dt_EditBuffer_L1
mr r3, r30
bl __dl__FPv
__dt_EditBuffer_L1:
mr r3, r30
lwz r31, 0xc(r1)
lwz r30, 8(r1)
lwz r0, 0x14(r1)
mtlr r0
addi r1, r1, 0x10
blr
EditBuffer::~EditBuffer() {
if (mpString) {
static_cast<tistring::Decolated*>(mpString)->~Decolated();
MEMFreeToAllocator(mpAllocator, mpString);
}
if (mpUnfixString) {
static_cast<tistring::WithAtok*>(mpUnfixString)->~WithAtok();
MEMFreeToAllocator(mpAllocator, mpUnfixString);
}
if (mpZiString) {
static_cast<tistring::WithZi*>(mpZiString)->~WithZi();
MEMFreeToAllocator(mpAllocator, mpZiString);
}
mpString = NULL;
mpUnfixString = NULL;
mpZiString = NULL;
}
extern "C" asm void updateInputCommon__Q39textinput9inputform12LayoutByNW4RFiUlUlUlPv() {
nofralloc
@@ -5504,7 +5365,6 @@ bool Base::onCursor(CursorPos* cursor) {
glyph.rect.bottom = 0.0f;
glyph.character = candidate;
calcRect(glyph);
static GXColor candidateBackground = {255, 210, 12, 255};
f32 left = glyph.rect.left + GetCursorX();
f32 top = glyph.rect.top + GetCursorY();
f32 right = glyph.rect.right + GetCursorX();
@@ -5567,7 +5427,6 @@ bool Base::onCursor(CursorPos* cursor) {
glyph.character = character;
calcRect(glyph);
if (meLanguage == JP) {
static GXColor kanaBackground = {128, 255, 128, 255};
f32 left = glyph.rect.left + GetCursorX();
f32 top = glyph.rect.top + GetCursorY();
f32 right = glyph.rect.right + GetCursorX();

View File

@@ -59,3 +59,36 @@ Every measured state retained the original 20-string pool. The first gate lacked
- `Base::onCursor`: final centered-space variation initializes the real offset before width locals and puts scale/half-width operands first: 473/473, seven differences. Restored the five-difference version.
- Final clean full gate: GATE PASS; pool IDENTICAL; instruction-exact 206/221 (baseline 175/221); objdiff functions 208/221 (baseline 176/221); code 28300/50656 (baseline 19124/50656); data 868/3772 (baseline 864/3772); zero regressions, forbidden additions and readability warnings. Full build passes and DOL SHA1 is 26116613f624061ba99c8d1a299aaa6efa85670d. Partial result: 46 existing asm bodies remain and data is below 100%. Every remaining report-nonmatching entry has at least three logged source-level attempts.
## Continuation from merged main
- Left/right HWKB guard: zero-case/default-break switch produces 265/264 and 276/275 with an extra branch; explicit if/else yields 263/264 and 274/275, dropping the required branch; integer switch with 0 and 1 cases adds five instructions; negated boolean switch adds boolean normalization and swaps registers; moving the body into default retains the extra branch. Restored the two-difference original.
- Cursor centering continuation: reversed multiplication nesting retained five differences; half-width accumulator moved work before scale query, 17 differences; scale-first accumulator gave seven differences; declaring the offset before widths retained five. Restored best source.
- Space-key Atok continuation: false-case switch gave 604/603 with one extra branch; false initializer plus positive assignment gave 602/603; explicit forward labels retained 603/603 and the same seven block-order differences. Restored best source.
- Data reconstruction: replacing EditBuffer destructor asm with typed C++ is 61/61, diffs 0, and emits its real vtable. EventHandler declaration moved before animation classes restores all three animation/event vtable offsets. Decolated clear/set/setLength overrides and draw-cache method signatures corrected under the unit macro. Moving genuine candidate/kana color definitions to the table group, using ordinary Korean/Chinese pane literals, and restoring the original true hyphen initializer makes every .sdata byte identical. Quick gate passes with zero regressions.
- Layout language continuation: separate name temporary retains 237/237 and 22 root-load scheduling differences; duplicating the pane query across explicit branches gives 252/237; reusing the existing text-name variable with separate if/else retains 237/237 and the same 22 differences. Restored original helper form.
- Continuation void Base::onPressUp(): true case kana guard: src 0x3d8 base 0x3d8 insns 246/246; diffs 2:.
- Continuation void Base::onPressUp(): zero case kana guard: src 0x3dc base 0x3d8 insns 247/246; 17 displayed differing instructions.
- Continuation void Base::onPressUp(): loop kana guard: src 0x3dc base 0x3d8 insns 247/246; 19 displayed differing instructions.
- Continuation void Base::onPressDown(): true case kana guard: src 0x3d8 base 0x3d8 insns 246/246; diffs 2:.
- Continuation void Base::onPressDown(): zero case kana guard: src 0x3dc base 0x3d8 insns 247/246; 17 displayed differing instructions.
- Continuation void Base::onPressDown(): loop kana guard: src 0x3dc base 0x3d8 insns 247/246; 19 displayed differing instructions.
- Continuation void Base::onPressDownHWKB(): local selected index: src 0x428 base 0x438 insns 266/270; 36 displayed differing instructions.
- Continuation void Base::onPressDownHWKB(): initialize selected index: src 0x428 base 0x438 insns 266/270; 36 displayed differing instructions.
- Continuation void Base::onPressDownHWKB(): positive kana switch: src 0x42c base 0x438 insns 267/270; 37 displayed differing instructions.
- Continuation u32 Base::calcCursorPos(: loop declaration: src 0x518 base 0x518 insns 326/326; diffs 81:.
- Continuation u32 Base::calcCursorPos(: scale assignment: src 0x520 base 0x518 insns 328/326; 154 displayed differing instructions.
- Continuation u32 Base::calcCursorPos(: defer vertical coordinate: src 0x51c base 0x518 insns 327/326; 145 displayed differing instructions.
- Continuation u32 Base::isOverRowLimit(: scale assignment: src 0x3b4 base 0x3b8 insns 237/238; 223 displayed differing instructions.
- Continuation u32 Base::isOverRowLimit(: defer scale width: src 0x3b0 base 0x3b8 insns 236/238; 220 displayed differing instructions.
- Continuation u32 Base::isOverRowLimit(: glyph field initialization: src 0x3c0 base 0x3b8 insns 240/238; 196 displayed differing instructions.
- Continuation void Base::onCommand(: fresh fixed string queries: src 0x2020 base 0x2014 insns 2056/2053; 1455 displayed differing instructions.
- Continuation void Base::onCommand(: defer translate mode query: src 0x2020 base 0x2014 insns 2056/2053; 1455 displayed differing instructions.
- Continuation void Base::onCommand(: uncached fixed predicate: src 0x2014 base 0x2014 insns 2053/2053; diffs 1985:.
- Continuation void LayoutByNW4R::create(: cache row-list pointer: src 0x590 base 0x590 insns 356/356; diffs 205:.
- Continuation LayoutByNW4R::create animation switch: first experiment failed to compile because its case scope was wrong; corrected and measured below.
- Continuation void LayoutByNW4R::create(: query animation id from record: src 0x5a4 base 0x590 insns 361/356; 303 displayed differing instructions.
- Animation-pane switch retried with corrected case scope: 357/356; original conditional retained. Cached row-list pointer is retained: 356/356, 205 differences, objdiff 88.91854% versus 88.11798%; no regressions. Removing explicit placement-allocation checks gave 354/356 and was restored.
- Additional cursor experiments: reusing either box-edge variable as the marker offset gave seven differences; a real inline space-centering helper gave ten differences and changed stack temporary order. Restored the five-difference source.
- Nine additional asm conversions are instruction-exact: initZiString 14/14, resetContextPredict_ 27/27, resetRelation 23/23, textinput Base init 1/1, drawer getLine 3/3, StringBase hasCandidate 5/5, inputform Base create allocator overload 1/1, Decolated set 19/19, Decolated clear 20/20. Layout onSE 5/5 and EditBuffer destructor 61/61 are also exact C++. The allocator overload and base initializer faithfully retain their original empty bodies.
- Data limits: ordinary literal pool and .rodata/.sdata/.sdata2 are identical. Vtable relocation comparison now agrees except the reference cursor-cache concatenated symbol. EditBuffer vtable target size includes four trailing bytes and textinput Base vtable includes 28 trailing bytes without relocations; no padding was added. Other zero-filled weak data and anonymous jump-table differences remain.
- Final clean full gate: GATE PASS, pool IDENTICAL, zero regressions/forbidden additions/readability warnings; instruction-exact 206/221 unchanged, objdiff exact 208/221 unchanged, code 28300/50656 unchanged, data 868 -> 908/3772, fuzzy 97.1980 -> 97.2205. Eleven existing asm bodies converted instruction-exact to C++; 41 asm bodies remain. Linking was not changed. The literal pane tables have 100% .rodata and .sdata.