Compare commits
1 Commits
cleanup/se
...
agent/w092
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dca1837457 |
@@ -53,9 +53,9 @@ Progress
|
||||
<!-- progress:start -->
|
||||
| Decompiled | Matched | Linked | Data |
|
||||
|:---:|:---:|:---:|:---:|
|
||||
| 85.99% | 76.05% | 56.92% | 86.74% |
|
||||
| 86.34% | 76.29% | 56.92% | 87.18% |
|
||||
|
||||
units 752/1027 complete, functions 11085/12563 matched.
|
||||
units 752/1027 complete, functions 11150/12563 matched.
|
||||
|
||||
decompiled = code with a C/C++ implementation (objdiff fuzzy), matched = byte-exact code, linked = code actually linked into the DOL, data = byte-exact data
|
||||
<!-- progress:end -->
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <revolution/types.h>
|
||||
#include <revolution/mem/allocator.h>
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISTRING_IMPLEMENTATION) || defined(TIZISTRING_IMPLEMENTATION)
|
||||
#include <revolution/kpr.h>
|
||||
#endif
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace textinput {
|
||||
virtual wchar_t* getWCString() const { return mpszString; }
|
||||
|
||||
virtual void setCandidate(wchar_t candidate) { mwcCandidate = candidate; }
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISTRING_IMPLEMENTATION) || defined(TIZISTRING_IMPLEMENTATION)
|
||||
virtual wchar_t getCandidate() const { return mwcCandidate; }
|
||||
#else
|
||||
virtual wchar_t getCandidate() { return mwcCandidate; }
|
||||
@@ -48,7 +48,11 @@ namespace textinput {
|
||||
|
||||
virtual wchar_t getLastWChar();
|
||||
|
||||
#if defined(TISTRING_IMPLEMENTATION) || defined(TIZISTRING_IMPLEMENTATION)
|
||||
protected:
|
||||
#else
|
||||
private:
|
||||
#endif
|
||||
u16 muMaxLength; // 0x04
|
||||
u16 muLength; // 0x06
|
||||
|
||||
@@ -61,7 +65,7 @@ namespace textinput {
|
||||
};
|
||||
|
||||
class KanaStream {
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISTRING_IMPLEMENTATION) || defined(TIZISTRING_IMPLEMENTATION)
|
||||
public:
|
||||
KPRQueue mQueue;
|
||||
wchar_t mPending;
|
||||
@@ -74,13 +78,13 @@ namespace textinput {
|
||||
|
||||
class Decolated : public StringBase {
|
||||
public:
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISTRING_IMPLEMENTATION) || defined(TIZISTRING_IMPLEMENTATION)
|
||||
Decolated(u16 maxLen) : StringBase(maxLen), mCursorStart(0), mCursorEnd(0), mbSustain(false), mTranslateMode(0) { initKanaConverter(); }
|
||||
#else
|
||||
Decolated(u16 maxLen) : StringBase(maxLen), field_0x18(0), field_0x1C(0), field_0x20(0), field_0x24(0) { initKanaConverter(); }
|
||||
#endif
|
||||
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISTRING_IMPLEMENTATION) || defined(TIZISTRING_IMPLEMENTATION)
|
||||
virtual ~Decolated();
|
||||
enum TranslateMode { TM_Direct, TM_Kana, TM_Roman, TM_Hangul };
|
||||
virtual void clear();
|
||||
@@ -103,7 +107,7 @@ namespace textinput {
|
||||
virtual u32 getCursorPos() const;
|
||||
virtual void getCursorPos(u32* start, u32* end);
|
||||
virtual bool canBackSpace();
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISTRING_IMPLEMENTATION) || defined(TIZISTRING_IMPLEMENTATION)
|
||||
virtual bool deleteForward();
|
||||
#else
|
||||
virtual void deleteForward();
|
||||
@@ -161,12 +165,21 @@ namespace textinput {
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(TISTRING_IMPLEMENTATION) || defined(TIZISTRING_IMPLEMENTATION)
|
||||
protected:
|
||||
#else
|
||||
private:
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
#endif
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISTRING_IMPLEMENTATION) || defined(TIZISTRING_IMPLEMENTATION)
|
||||
u32 mCursorStart;
|
||||
u32 mCursorEnd;
|
||||
#if defined(TISTRING_IMPLEMENTATION) || defined(TIZISTRING_IMPLEMENTATION)
|
||||
u8 mbSustain;
|
||||
s32 mTranslateMode;
|
||||
#else
|
||||
bool mbSustain;
|
||||
u32 mTranslateMode;
|
||||
#endif
|
||||
#else
|
||||
u32 field_0x18; // 0x18
|
||||
u32 field_0x1C; // 0x1C
|
||||
@@ -176,7 +189,7 @@ namespace textinput {
|
||||
KanaStream mKanaStream; // 0x28
|
||||
};
|
||||
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISTRING_IMPLEMENTATION) || defined(TIZISTRING_IMPLEMENTATION)
|
||||
class WithAtok : public Decolated {
|
||||
public:
|
||||
WithAtok(u16 maxLength) : Decolated(maxLength) {}
|
||||
|
||||
@@ -20,9 +20,15 @@ namespace textinput {
|
||||
wchar_t KBD_ConvertSmall(wchar_t ch);
|
||||
wchar_t KBD_ConvertAll(wchar_t ch);
|
||||
|
||||
#ifdef TISTRING_IMPLEMENTATION
|
||||
u32 KBD_IsDakuten(wchar_t ch);
|
||||
u32 KBD_IsHandaku(wchar_t ch);
|
||||
u32 KBD_IsSmall(wchar_t ch);
|
||||
#else
|
||||
bool KBD_IsDakuten(wchar_t ch);
|
||||
bool KBD_IsHandaku(wchar_t ch);
|
||||
bool KBD_IsSmall(wchar_t ch);
|
||||
#endif
|
||||
|
||||
bool strcmp(const char* s1, const char* s2);
|
||||
void replaceChar(char* dest, u32 destLen, const char* src, int replaceIdx, char newCh);
|
||||
|
||||
@@ -1,14 +1,102 @@
|
||||
#ifndef TEXTINPUT_ZI_STRING_H
|
||||
#define TEXTINPUT_ZI_STRING_H
|
||||
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
#if defined(TIZISTRING_IMPLEMENTATION)
|
||||
#include "tiString.h"
|
||||
extern "C" {
|
||||
#include <eztx.h>
|
||||
}
|
||||
#elif defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
#include "tiString.h"
|
||||
#include <eztx.h>
|
||||
#endif
|
||||
|
||||
namespace textinput {
|
||||
namespace tistring {
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
#if defined(TIZISTRING_IMPLEMENTATION)
|
||||
class WithZi : public Decolated {
|
||||
public:
|
||||
enum PredictLanguage {
|
||||
PL_0,
|
||||
PL_1,
|
||||
PL_2,
|
||||
PL_3,
|
||||
PL_4,
|
||||
PL_5,
|
||||
PL_6,
|
||||
PL_7,
|
||||
PL_8,
|
||||
PL_9,
|
||||
PL_10,
|
||||
PL_11
|
||||
};
|
||||
|
||||
enum LetterMode {
|
||||
LM_0,
|
||||
LM_1,
|
||||
LM_2,
|
||||
LM_3
|
||||
};
|
||||
|
||||
static u16 ElementBuffer[0x100];
|
||||
static u16 CandidatesBuffer[0x300];
|
||||
static u16 CandidatedWord[0xa00];
|
||||
static u16 LatestWord[0x40];
|
||||
|
||||
virtual ~WithZi();
|
||||
virtual void create(MEMAllocator*);
|
||||
virtual void pushBack(wchar_t);
|
||||
virtual void popBack();
|
||||
virtual void clear();
|
||||
virtual void inputChar(wchar_t);
|
||||
virtual void backSpace();
|
||||
virtual void confirm(const wchar_t*);
|
||||
virtual bool moveCursorRight();
|
||||
virtual bool moveCursorLeft();
|
||||
virtual bool canBackSpace();
|
||||
virtual void EnableKSXFilter(bool);
|
||||
virtual void init();
|
||||
virtual void setInputting(wchar_t);
|
||||
virtual u32 getCurrentNumPredicted();
|
||||
virtual void getPredicted(int, wchar_t*);
|
||||
virtual wchar_t* getCurrentSelected();
|
||||
virtual u16 getInputStringLength();
|
||||
virtual void setSelectedCandidate(s32);
|
||||
virtual bool isFix();
|
||||
virtual void setPredictLaunguage(PredictLanguage);
|
||||
virtual void changeLetterMode(LetterMode);
|
||||
virtual void ChangeDictionaryLanguage(u8);
|
||||
virtual void setCellPhoneHoldingkey(void*);
|
||||
virtual u32 setElementBuffer();
|
||||
virtual u8 getPredictLanguage();
|
||||
void openDictionary(void*, void*);
|
||||
void clearCandidates();
|
||||
void partialConfirmForKR();
|
||||
void update();
|
||||
u32 complementsCandidates_(s32);
|
||||
void setCurrentWord(const wchar_t*);
|
||||
u32 getCurrentInput(wchar_t*, u32);
|
||||
wchar_t* getCurrentInput();
|
||||
|
||||
private:
|
||||
EZTXGetParam mSearch;
|
||||
u32 mSearchState;
|
||||
u8 mbDictionaryOpen;
|
||||
u8 mbContextChanged;
|
||||
u32 mCurrentWordLength;
|
||||
EZTXLanguageEntry* mpDictionaries;
|
||||
void* mpDictionaryWork;
|
||||
u16 mInputLength;
|
||||
u32 mCandidateCount;
|
||||
u32 mOemDictionaryId;
|
||||
u8 mDictionaryLanguage;
|
||||
s32 mSelectedCandidate;
|
||||
PredictLanguage mPredictLanguage;
|
||||
LetterMode mLetterMode;
|
||||
void* mpHoldingKey;
|
||||
u8 mbKoreanPartialConfirm;
|
||||
};
|
||||
#elif defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
class WithZi : public Decolated {
|
||||
public:
|
||||
enum PredictLanguage { PL_Default };
|
||||
|
||||
@@ -130,11 +130,18 @@ typedef struct EZTXGetParam {
|
||||
wchar_t* candidates; // 0x18
|
||||
u8 maxCandidates; // 0x1C
|
||||
wchar_t firstCandidate; // 0x1E
|
||||
#ifndef TIZISTRING_IMPLEMENTATION
|
||||
u8 wordCandidates; // 0x1F
|
||||
#endif
|
||||
|
||||
u8 count; // 0x20
|
||||
u8 letters; // 0x21
|
||||
#ifdef TIZISTRING_IMPLEMENTATION
|
||||
u8 completion;
|
||||
u8* scratch;
|
||||
#else
|
||||
u8* scratch; // 0x22
|
||||
#endif
|
||||
} EZTXGetParam;
|
||||
|
||||
u16 EZTXGetGlobalDataSize();
|
||||
|
||||
495
src/keyboard/tiString.cpp
Normal file
495
src/keyboard/tiString.cpp
Normal file
@@ -0,0 +1,495 @@
|
||||
#define TISTRING_IMPLEMENTATION
|
||||
#include "keyboard/tiString.h"
|
||||
#include "keyboard/tiUtil.h"
|
||||
#include <wchar.h>
|
||||
|
||||
extern "C" {
|
||||
u8 KPRLookAhead(KPRQueue*, wchar_t*, u32);
|
||||
u32 KPRPutChar(KPRQueue*, wchar_t);
|
||||
wchar_t KPRGetChar(KPRQueue*);
|
||||
void KPRClearQueue(KPRQueue*);
|
||||
void KPRInitQueue(KPRQueue*);
|
||||
void KPRSetMode(KPRQueue*, u32);
|
||||
}
|
||||
|
||||
namespace textinput {
|
||||
namespace tistring {
|
||||
Decolated::~Decolated() {}
|
||||
void StringBase::create(MEMAllocator* allocator) {
|
||||
mpAllocator = allocator;
|
||||
mpszString = static_cast<wchar_t*>(MEMAllocFromAllocator(allocator, muMaxLength << 1));
|
||||
wmemset(mpszString, 0, muMaxLength);
|
||||
muLength = 0;
|
||||
mpszTmpString = static_cast<wchar_t*>(MEMAllocFromAllocator(allocator, muMaxLength << 1));
|
||||
wmemset(mpszTmpString, 0, muMaxLength);
|
||||
}
|
||||
|
||||
StringBase::~StringBase() {
|
||||
MEMFreeToAllocator(mpAllocator, mpszString);
|
||||
MEMFreeToAllocator(mpAllocator, mpszTmpString);
|
||||
}
|
||||
|
||||
void StringBase::pushBack(wchar_t ch) {
|
||||
wchar_t buffer[10];
|
||||
buffer[0] = ch;
|
||||
buffer[1] = 0;
|
||||
u32 length = wcslen(buffer);
|
||||
wcsncat(mpszString, buffer, length);
|
||||
muLength++;
|
||||
}
|
||||
|
||||
void StringBase::popBack() {
|
||||
if (muLength != 0) {
|
||||
muLength--;
|
||||
}
|
||||
mpszString[muLength] = 0;
|
||||
}
|
||||
|
||||
bool StringBase::append(const wchar_t* string) {
|
||||
u32 inputLength = wcslen(string);
|
||||
u16 length = getLength();
|
||||
if (inputLength + length > muMaxLength) {
|
||||
return false;
|
||||
}
|
||||
if (string == 0) {
|
||||
return false;
|
||||
}
|
||||
while (*string != 0) {
|
||||
mpszString[muLength] = *string;
|
||||
muLength++;
|
||||
string++;
|
||||
}
|
||||
mpszString[muLength] = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool StringBase::insert(u16 position, const wchar_t* string) {
|
||||
u32 inputLength = wcslen(string);
|
||||
u32 length = getLength();
|
||||
s32 total = (inputLength & 0xffff) + (length & 0xffff);
|
||||
bool success;
|
||||
if (total > muMaxLength) {
|
||||
success = false;
|
||||
} else if (string == 0 || static_cast<u32>(position) > static_cast<u32>(getLength() & 0xffff)) {
|
||||
success = false;
|
||||
} else {
|
||||
wmemset(mpszTmpString, 0, muMaxLength);
|
||||
wcsncpy(mpszTmpString, mpszString + position, (getLength() & 0xffff) - position);
|
||||
muLength = position;
|
||||
mpszString[position] = 0;
|
||||
append(string);
|
||||
append(mpszTmpString);
|
||||
success = true;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
void StringBase::remove(u16 position, u16 count) {
|
||||
u16 length = getLength();
|
||||
if (length != 0 && position <= getLength()) {
|
||||
s32 currentLength = getLength() & 0xffff;
|
||||
s32 end = position + count;
|
||||
if (end >= currentLength) {
|
||||
count = getLength() - position;
|
||||
}
|
||||
wmemset(mpszTmpString, 0, muMaxLength);
|
||||
wcsncpy(mpszTmpString, mpszString + position + count, (getLength() & 0xffff) - (position + count));
|
||||
muLength = position;
|
||||
mpszString[position] = 0;
|
||||
append(mpszTmpString);
|
||||
}
|
||||
}
|
||||
|
||||
void StringBase::replace(u16 position, u16 count, const wchar_t* value) {
|
||||
s32 length = getLength();
|
||||
if (position + count >= length) {
|
||||
count = getLength() - position;
|
||||
}
|
||||
remove(position, count);
|
||||
insert(position, value);
|
||||
}
|
||||
|
||||
void StringBase::set(const wchar_t* string) {
|
||||
clear();
|
||||
append(string);
|
||||
}
|
||||
|
||||
void StringBase::setAt(u16 index, wchar_t ch) {
|
||||
if (muMaxLength <= index) {
|
||||
return;
|
||||
}
|
||||
mpszString[index] = ch;
|
||||
}
|
||||
|
||||
void StringBase::setLength(u16 length) {
|
||||
for (u16 index = length; index < muLength; index++) {
|
||||
setAt(index, 0);
|
||||
}
|
||||
muLength = length;
|
||||
}
|
||||
|
||||
void StringBase::clear() {
|
||||
wmemset(mpszString, 0, muMaxLength);
|
||||
muLength = 0;
|
||||
}
|
||||
|
||||
wchar_t StringBase::getLastWChar() {
|
||||
s32 index = muLength - 1;
|
||||
if (index >= 0) {
|
||||
return mpszString[index];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Decolated::inputChar(wchar_t ch) {
|
||||
if (ch != 0xfffe) {
|
||||
wchar_t input[8];
|
||||
input[4] = 0;
|
||||
input[3] = 0;
|
||||
input[2] = 0;
|
||||
input[1] = 0;
|
||||
input[0] = 0;
|
||||
u16 count;
|
||||
if (static_cast<u32>(mTranslateMode) - 1 > 1) {
|
||||
goto nonKana;
|
||||
}
|
||||
{
|
||||
mKanaStream.mOutput[4] = 0;
|
||||
mKanaStream.mOutput[3] = 0;
|
||||
mKanaStream.mOutput[2] = 0;
|
||||
mKanaStream.mOutput[1] = 0;
|
||||
mKanaStream.mOutput[0] = 0;
|
||||
if (ch == 10 && KPRLookAhead(&mKanaStream.mQueue, 0, 0)) {
|
||||
count = KPRPutChar(&mKanaStream.mQueue, 0xffff) & 0xff;
|
||||
} else {
|
||||
ch = util::toWLower(ch);
|
||||
count = KPRPutChar(&mKanaStream.mQueue, ch) & 0xff;
|
||||
}
|
||||
for (u32 inputIndex = 0; (inputIndex & 0xff) < count; inputIndex++) {
|
||||
input[static_cast<u8>(inputIndex)] = KPRGetChar(&mKanaStream.mQueue);
|
||||
}
|
||||
KPRLookAhead(&mKanaStream.mQueue, mKanaStream.mOutput, 5);
|
||||
goto inputReady;
|
||||
}
|
||||
nonKana:
|
||||
if (mTranslateMode == 3) {
|
||||
input[0] = ch;
|
||||
input[1] = 0;
|
||||
count = 1;
|
||||
mKanaStream.mOutput[0] = 0;
|
||||
} else {
|
||||
count = 1;
|
||||
input[0] = ch;
|
||||
input[1] = 0;
|
||||
}
|
||||
inputReady:
|
||||
setCandidate(0);
|
||||
u32 start;
|
||||
u32 end;
|
||||
getSelected(start, end);
|
||||
if (start == end) {
|
||||
insert(mCursorStart, input);
|
||||
u32 currentCursor = mCursorStart;
|
||||
mCursorStart = currentCursor + static_cast<u16>(count);
|
||||
} else {
|
||||
replace(start, end - start, input);
|
||||
mCursorStart = start + static_cast<u16>(count);
|
||||
}
|
||||
mCursorEnd = mCursorStart;
|
||||
}
|
||||
}
|
||||
|
||||
void Decolated::confirmKana() {
|
||||
inputChar(10);
|
||||
}
|
||||
|
||||
void Decolated::clearKana() {
|
||||
KPRClearQueue(&mKanaStream.mQueue);
|
||||
mKanaStream.mOutput[0] = 0;
|
||||
}
|
||||
|
||||
void Decolated::inputString(const wchar_t* string) {
|
||||
if (string != 0) {
|
||||
const wchar_t* current = string;
|
||||
for (; *current != 0; current++) {
|
||||
inputChar(*current);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Decolated::inputString(const wchar_t* string, TranslateMode mode) {
|
||||
TranslateMode oldMode = static_cast<TranslateMode>(mTranslateMode);
|
||||
if (oldMode != mode) {
|
||||
if (!isKanaFix() && mode == 0) {
|
||||
confirmKana();
|
||||
}
|
||||
mTranslateMode = mode;
|
||||
switch (mode) {
|
||||
case 1:
|
||||
mKanaStream.mQueue.mode = static_cast<KPRMode>(4);
|
||||
break;
|
||||
case 2:
|
||||
mKanaStream.mQueue.mode = static_cast<KPRMode>(8);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
inputString(string);
|
||||
if (mTranslateMode != oldMode) {
|
||||
if (!isKanaFix() && oldMode == 0) {
|
||||
confirmKana();
|
||||
}
|
||||
mTranslateMode = oldMode;
|
||||
switch (oldMode) {
|
||||
case 1:
|
||||
mKanaStream.mQueue.mode = static_cast<KPRMode>(4);
|
||||
break;
|
||||
case 2:
|
||||
mKanaStream.mQueue.mode = static_cast<KPRMode>(8);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Decolated::backSpace() {
|
||||
if (static_cast<u32>(mTranslateMode) - 1 <= 1 && KPRLookAhead(&mKanaStream.mQueue, 0, 0)) {
|
||||
mKanaStream.mQueue.iCount--;
|
||||
u32 count = KPRLookAhead(&mKanaStream.mQueue, 0, 0);
|
||||
mKanaStream.mOutput[count] = 0;
|
||||
} else {
|
||||
wchar_t empty[1];
|
||||
u32 start;
|
||||
u32 end;
|
||||
getSelected(start, end);
|
||||
if (start != end || start != 0) {
|
||||
if (start == end) {
|
||||
if (hasCandidate()) {
|
||||
setCandidate(0);
|
||||
} else {
|
||||
if (mCursorStart != 0) {
|
||||
mCursorStart--;
|
||||
}
|
||||
remove(mCursorStart, 1);
|
||||
}
|
||||
} else {
|
||||
empty[0] = 0;
|
||||
replace(start, end - start, empty);
|
||||
mCursorStart = start;
|
||||
}
|
||||
mCursorEnd = mCursorStart;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Decolated::confirm(const wchar_t* string) {
|
||||
if (string != 0) {
|
||||
insert(mCursorStart, string);
|
||||
u32 length = wcslen(string);
|
||||
mCursorStart += length;
|
||||
mCursorEnd = mCursorStart;
|
||||
}
|
||||
}
|
||||
|
||||
bool Decolated::moveCursorRight() {
|
||||
if (mCursorStart < getLength()) goto moveRight;
|
||||
return mbSustain == 0;
|
||||
moveRight:
|
||||
mCursorStart++;
|
||||
if (mbSustain == 0) {
|
||||
mCursorEnd = mCursorStart;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Decolated::moveCursorLeft() {
|
||||
if (mCursorStart == 0) {
|
||||
return false;
|
||||
}
|
||||
mCursorStart--;
|
||||
if (mbSustain == 0) {
|
||||
mCursorEnd = mCursorStart;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Decolated::setCursorPos(u32 position) {
|
||||
u8 sustain = mbSustain;
|
||||
mCursorStart = position;
|
||||
if (sustain == 0) {
|
||||
mCursorEnd = position;
|
||||
}
|
||||
}
|
||||
|
||||
void Decolated::onSustain() {
|
||||
mbSustain = 1;
|
||||
mCursorEnd = mCursorStart;
|
||||
}
|
||||
|
||||
void Decolated::offSustain() {
|
||||
mbSustain = 0;
|
||||
}
|
||||
|
||||
void Decolated::getCursorPos(u32* start, u32* end) {
|
||||
*start = mCursorStart;
|
||||
*end = mCursorEnd;
|
||||
}
|
||||
|
||||
bool Decolated::canBackSpace() {
|
||||
if (mCursorStart != 0) goto canBackSpaceTrue;
|
||||
if (mCursorStart != 0) goto checkKanaFix;
|
||||
if (mCursorStart == mCursorEnd) goto checkKanaFix;
|
||||
canBackSpaceTrue:
|
||||
return true;
|
||||
checkKanaFix:
|
||||
if (isKanaFix() == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Decolated::deleteForward() {
|
||||
u32 cursor = mCursorStart;
|
||||
if (cursor < getLength()) goto removeChar;
|
||||
return false;
|
||||
removeChar:
|
||||
remove(cursor, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Decolated::getSelected(u32& start, u32& end) {
|
||||
if (mCursorStart > mCursorEnd) {
|
||||
start = mCursorEnd;
|
||||
end = mCursorStart;
|
||||
} else {
|
||||
start = mCursorStart;
|
||||
end = mCursorEnd;
|
||||
}
|
||||
}
|
||||
|
||||
wchar_t Decolated::getWCharAtCursor() {
|
||||
u32 start;
|
||||
u32 end;
|
||||
getSelected(start, end);
|
||||
if (end == 0) {
|
||||
return 0;
|
||||
}
|
||||
return mpszString[end - 1];
|
||||
}
|
||||
|
||||
void Decolated::replaceAtCursor(wchar_t ch) {
|
||||
u32 start;
|
||||
u32 end;
|
||||
getSelected(start, end);
|
||||
if (end != 0) {
|
||||
mpszString[end - 1] = ch;
|
||||
}
|
||||
}
|
||||
|
||||
bool Decolated::isDakuten() {
|
||||
return util::KBD_IsDakuten(getWCharAtCursor());
|
||||
}
|
||||
|
||||
void Decolated::converDakuten() {
|
||||
wchar_t ch = getWCharAtCursor();
|
||||
replaceAtCursor(util::KBD_ConvertDakuten(ch));
|
||||
}
|
||||
|
||||
bool Decolated::isHandaku() {
|
||||
return util::KBD_IsHandaku(getWCharAtCursor());
|
||||
}
|
||||
|
||||
void Decolated::converHandaku() {
|
||||
wchar_t ch = getWCharAtCursor();
|
||||
replaceAtCursor(util::KBD_ConvertHandaku(ch));
|
||||
}
|
||||
|
||||
void Decolated::convertAll() {
|
||||
wchar_t ch = getWCharAtCursor();
|
||||
replaceAtCursor(util::KBD_ConvertAll(ch));
|
||||
}
|
||||
|
||||
bool Decolated::isSmall() {
|
||||
return util::KBD_IsSmall(getWCharAtCursor());
|
||||
}
|
||||
|
||||
void Decolated::converSmall() {
|
||||
wchar_t ch = getWCharAtCursor();
|
||||
replaceAtCursor(util::KBD_ConvertSmall(ch));
|
||||
}
|
||||
|
||||
bool Decolated::atTheBeginningOfASentence() {
|
||||
if (mCursorStart == 0) {
|
||||
return false;
|
||||
}
|
||||
if (getLength() < 1) {
|
||||
return false;
|
||||
}
|
||||
u32 start;
|
||||
u32 end;
|
||||
getSelected(start, end);
|
||||
if (start != end) {
|
||||
return false;
|
||||
}
|
||||
s32 ch = getWCharAtCursor();
|
||||
switch (ch) {
|
||||
case 0x2e:
|
||||
case 0x21:
|
||||
case 0x3f:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Decolated::setTranslateMode(TranslateMode mode) {
|
||||
if (mTranslateMode != mode) {
|
||||
if (!isKanaFix() && mode == 0) {
|
||||
confirmKana();
|
||||
}
|
||||
mTranslateMode = mode;
|
||||
switch (mode) {
|
||||
case 1:
|
||||
mKanaStream.mQueue.mode = static_cast<KPRMode>(4);
|
||||
break;
|
||||
case 2:
|
||||
mKanaStream.mQueue.mode = static_cast<KPRMode>(8);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Decolated::initKanaConverter() {
|
||||
KPRInitQueue(&mKanaStream.mQueue);
|
||||
KPRSetMode(&mKanaStream.mQueue, 0);
|
||||
mKanaStream.mOutput[0] = 0;
|
||||
s32 mode = mTranslateMode;
|
||||
switch (mode) {
|
||||
case 1:
|
||||
mKanaStream.mQueue.mode = static_cast<KPRMode>(4);
|
||||
break;
|
||||
case 2:
|
||||
mKanaStream.mQueue.mode = static_cast<KPRMode>(8);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Decolated::setLength(u16 length) {
|
||||
for (u32 index = length; (index & 0xffff) < muLength; index++) {
|
||||
setAt(static_cast<u16>(index), 0);
|
||||
}
|
||||
muLength = length;
|
||||
if (mCursorStart > length) {
|
||||
mCursorEnd = length;
|
||||
mCursorStart = length;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
601
src/keyboard/tiZiString.cpp
Normal file
601
src/keyboard/tiZiString.cpp
Normal file
@@ -0,0 +1,601 @@
|
||||
#define TIZISTRING_IMPLEMENTATION
|
||||
#include "keyboard/tiZiString.h"
|
||||
#include "keyboard/tiUtil.h"
|
||||
#include "keyboard/tiCpData.h"
|
||||
#include <wchar.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace textinput {
|
||||
namespace tistring {
|
||||
inline Decolated::~Decolated() {}
|
||||
|
||||
struct OEMDictionary {
|
||||
s32 count;
|
||||
s32 offsets[1];
|
||||
};
|
||||
|
||||
u16 WithZi::ElementBuffer[0x100];
|
||||
u16 WithZi::CandidatesBuffer[0x300];
|
||||
u16 WithZi::CandidatedWord[0xa00];
|
||||
u16 WithZi::LatestWord[0x40];
|
||||
|
||||
static const wchar_t kKoreanFinalLetters[12] = {
|
||||
L'y', L'u', L'i', L'o', L'p', L'h', L'j', L'k', L'l', L'b', L'n', L'm'
|
||||
};
|
||||
|
||||
static const wchar_t kKoreanLeadingLetters[16] = L"qwertasdfgzxcv";
|
||||
|
||||
static bool SearchOEMDictionary(u16, u16*, u8, void*);
|
||||
|
||||
static u8 LatinSearchOrder[10] = {3, 3, 2, 1, 4, 7, 6, 5, 8, 0};
|
||||
|
||||
static bool SearchOEMDictionary(u16 index, u16* output, u8 maxLength, void* dictionary) {
|
||||
OEMDictionary* entries = static_cast<OEMDictionary*>(dictionary);
|
||||
if (static_cast<s32>(index) >= entries->count) {
|
||||
return false;
|
||||
}
|
||||
s32 offset = entries->offsets[index];
|
||||
u8* dictionaryBytes = static_cast<u8*>(dictionary);
|
||||
wchar_t* word = reinterpret_cast<wchar_t*>(dictionaryBytes + offset);
|
||||
u32 length = wcslen(word);
|
||||
if (static_cast<u32>(maxLength) <= length) {
|
||||
return false;
|
||||
}
|
||||
wcscpy((wchar_t*)output, word);
|
||||
return true;
|
||||
}
|
||||
|
||||
void WithZi::ChangeDictionaryLanguage(u8 language) {
|
||||
if (mDictionaryLanguage != language) {
|
||||
mDictionaryLanguage = language;
|
||||
if (mOemDictionaryId != 0) {
|
||||
EZTXDetachOEMDict(mOemDictionaryId & 0xff, mpDictionaryWork);
|
||||
}
|
||||
EZTXLanguageEntry* entry;
|
||||
EZTXLanguageEntry* dictionaryTable;
|
||||
s32 entryIndex;
|
||||
s32 baseIndex;
|
||||
u32* dictionaryEntry;
|
||||
u32 attached;
|
||||
entryIndex = -1;
|
||||
baseIndex = 0;
|
||||
dictionaryTable = (EZTXLanguageEntry*)mpDictionaries;
|
||||
entry = dictionaryTable;
|
||||
for (s32 groups = 2; groups != 0; --groups) {
|
||||
for (s32 column = 0; column < 6; ++column) {
|
||||
if (language == entry->language) entryIndex = baseIndex;
|
||||
++entry;
|
||||
++baseIndex;
|
||||
}
|
||||
}
|
||||
if (entryIndex != -1) {
|
||||
dictionaryEntry = reinterpret_cast<u32*>(dictionaryTable[entryIndex].table);
|
||||
if (dictionaryEntry == NULL) goto noDictionary;
|
||||
attached = EZTXAttachOEMDict(
|
||||
(u8*)SearchOEMDictionary, *dictionaryEntry & 0xffff,
|
||||
dictionaryEntry, mpDictionaryWork);
|
||||
mOemDictionaryId = attached & 0xff;
|
||||
goto dictionaryReady;
|
||||
noDictionary:
|
||||
mOemDictionaryId = 0;
|
||||
dictionaryReady:
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WithZi::~WithZi() {
|
||||
MEMFreeToAllocator(mpAllocator, mpDictionaryWork);
|
||||
}
|
||||
|
||||
void WithZi::create(MEMAllocator* allocator) {
|
||||
StringBase::create(allocator);
|
||||
void* globalData = MEMAllocFromAllocator(allocator, EZTXGetGlobalDataSize());
|
||||
EZTXGetGlobalDataSize();
|
||||
mpDictionaryWork = globalData;
|
||||
mOemDictionaryId = 0;
|
||||
init();
|
||||
}
|
||||
|
||||
void WithZi::init() {
|
||||
if (mbDictionaryOpen != 0) {
|
||||
mbContextChanged = 0;
|
||||
clearCandidates();
|
||||
memset(LatestWord, 0, 0x80);
|
||||
LatestWord[0] = 0x20;
|
||||
if (getPredictLanguage() == 1) {
|
||||
update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WithZi::clearCandidates() {
|
||||
if (mbDictionaryOpen != 0) {
|
||||
mInputLength = 0;
|
||||
mCandidateCount = 0;
|
||||
memset(ElementBuffer, 0, 0x1fe);
|
||||
memset(CandidatesBuffer, 0, 0x200);
|
||||
memset(CandidatesBuffer + 0x100, 0, 0x1fe);
|
||||
memset(CandidatesBuffer + 0x200, 0, 0x200);
|
||||
memset(CandidatedWord, 0, 0x1400);
|
||||
memset(&mSearch, 0, sizeof(mSearch) + sizeof(mSearchState));
|
||||
mSearch.language = getPredictLanguage();
|
||||
mSearch.subLanguage = 7;
|
||||
mSearch.getMode = 0;
|
||||
mSearch.context = 1;
|
||||
mSearch.getOptions = 0x81;
|
||||
mSearch.elements = reinterpret_cast<wchar_t*>(ElementBuffer);
|
||||
mSearch.candidates = reinterpret_cast<wchar_t*>(&CandidatesBuffer[0x200]);
|
||||
mSearch.maxCandidates = 0x28;
|
||||
mSearch.elementCount = 0;
|
||||
mSearch.firstCandidate = 0;
|
||||
if (getPredictLanguage() == 1) {
|
||||
mSearch.getMode = 1;
|
||||
mSearch.context = 0x10;
|
||||
}
|
||||
EZTXGetCandidates(&mSearch, mpDictionaryWork);
|
||||
}
|
||||
}
|
||||
|
||||
void WithZi::openDictionary(void* ziDictionary, void* oemDictionary) {
|
||||
EZTXInitialize(ziDictionary, mpDictionaryWork);
|
||||
mbDictionaryOpen = 1;
|
||||
mpDictionaries = static_cast<EZTXLanguageEntry*>(oemDictionary);
|
||||
EZTXSetLatinSearchOrder(LatinSearchOrder, 10, mpDictionaryWork);
|
||||
mOemDictionaryId = 0;
|
||||
}
|
||||
|
||||
void WithZi::pushBack(wchar_t) {}
|
||||
|
||||
void WithZi::popBack() {}
|
||||
|
||||
void WithZi::inputChar(wchar_t character) {
|
||||
if (hasCandidate()) {
|
||||
if (mInputLength != 0) {
|
||||
--mInputLength;
|
||||
CandidatesBuffer[mInputLength] = 0;
|
||||
}
|
||||
mwcCandidate = 0;
|
||||
}
|
||||
CandidatesBuffer[mInputLength] = character;
|
||||
u16 index = mInputLength++;
|
||||
CandidatesBuffer[(index + 1) & 0xffff] = 0;
|
||||
update();
|
||||
}
|
||||
|
||||
void WithZi::setInputting(wchar_t character) {
|
||||
if (hasCandidate()) {
|
||||
if (mInputLength != 0) {
|
||||
--mInputLength;
|
||||
CandidatesBuffer[mInputLength] = 0;
|
||||
}
|
||||
mwcCandidate = 0;
|
||||
}
|
||||
inputChar(character);
|
||||
mwcCandidate = character;
|
||||
}
|
||||
|
||||
void WithZi::backSpace() {
|
||||
if (hasCandidate()) {
|
||||
if (mInputLength != 0) {
|
||||
--mInputLength;
|
||||
CandidatesBuffer[mInputLength] = 0;
|
||||
}
|
||||
mwcCandidate = 0;
|
||||
}
|
||||
else {
|
||||
if (mInputLength != 0) {
|
||||
--mInputLength;
|
||||
CandidatesBuffer[mInputLength] = 0;
|
||||
update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WithZi::confirm(const wchar_t*) {
|
||||
update();
|
||||
}
|
||||
|
||||
bool WithZi::moveCursorRight() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool WithZi::moveCursorLeft() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void WithZi::getPredicted(int index, wchar_t* output) {
|
||||
const wchar_t* candidate = reinterpret_cast<const wchar_t*>(CandidatedWord + index * 0x40);
|
||||
s32 length = 0;
|
||||
while (candidate[length] != 0) {
|
||||
output[length] = candidate[length];
|
||||
++length;
|
||||
}
|
||||
output[length] = 0;
|
||||
}
|
||||
|
||||
wchar_t* WithZi::getCurrentSelected() {
|
||||
if ((mSelectedCandidate < 0) || (mSelectedCandidate >= 0x28)) {
|
||||
return NULL;
|
||||
}
|
||||
return reinterpret_cast<wchar_t*>(CandidatedWord + mSelectedCandidate * 0x40);
|
||||
}
|
||||
|
||||
u32 WithZi::getCurrentInput(wchar_t* output, u32 maxLength) {
|
||||
u16* source;
|
||||
wchar_t* destination;
|
||||
s32 count = 0;
|
||||
if (0x100 < maxLength) {
|
||||
maxLength = 0x100;
|
||||
}
|
||||
source = CandidatesBuffer;
|
||||
destination = output;
|
||||
u32 index = 0;
|
||||
for (index = 0; index < maxLength; index++) {
|
||||
wchar_t character = *source;
|
||||
*destination = character;
|
||||
if (*destination == 0) {
|
||||
break;
|
||||
}
|
||||
if (mLetterMode == LM_2) {
|
||||
*destination = util::toWUpper(*destination);
|
||||
}
|
||||
++count;
|
||||
++source;
|
||||
++destination;
|
||||
}
|
||||
if (mLetterMode == LM_0) {
|
||||
*output = util::toWUpper(*output);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
wchar_t* WithZi::getCurrentInput() {
|
||||
return (wchar_t*)CandidatesBuffer;
|
||||
}
|
||||
|
||||
void WithZi::partialConfirmForKR() {
|
||||
if (mInputLength <= 1) return;
|
||||
bool match;
|
||||
s32 index;
|
||||
const wchar_t* letters;
|
||||
wchar_t value = util::toWLower(CandidatesBuffer[mInputLength - 1]);
|
||||
letters = kKoreanFinalLetters;
|
||||
for (index = 0; index < 12; ++index) {
|
||||
if (value == *letters) {
|
||||
match = true;
|
||||
goto finalLetterChecked;
|
||||
}
|
||||
++letters;
|
||||
}
|
||||
match = false;
|
||||
finalLetterChecked:
|
||||
if (!match) goto keepLastLetter;
|
||||
value = util::toWLower(CandidatesBuffer[mInputLength - 2]);
|
||||
index = 0;
|
||||
letters = kKoreanLeadingLetters;
|
||||
for (; index < 14; ++index) {
|
||||
if (value == *letters) {
|
||||
match = true;
|
||||
goto leadingLetterChecked;
|
||||
}
|
||||
++letters;
|
||||
}
|
||||
match = false;
|
||||
leadingLetterChecked:
|
||||
if (!match) goto keepLastLetter;
|
||||
CandidatesBuffer[0] = CandidatesBuffer[mInputLength - 2];
|
||||
CandidatesBuffer[1] = CandidatesBuffer[mInputLength - 1];
|
||||
mInputLength = 2;
|
||||
goto confirmLetters;
|
||||
keepLastLetter:
|
||||
CandidatesBuffer[0] = CandidatesBuffer[mInputLength - 1];
|
||||
mInputLength = 1;
|
||||
confirmLetters:
|
||||
CandidatesBuffer[mInputLength] = 0;
|
||||
update();
|
||||
}
|
||||
|
||||
void WithZi::update() {
|
||||
if (mbDictionaryOpen == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
mSelectedCandidate = 0;
|
||||
s32 elementCount = static_cast<u16>(setElementBuffer());
|
||||
mSearch.language = getPredictLanguage();
|
||||
mSearch.subLanguage = 7;
|
||||
mSearch.getMode = 0;
|
||||
mSearch.context = 1;
|
||||
mSearch.getOptions = 0x81;
|
||||
mSearch.elements = reinterpret_cast<wchar_t*>(ElementBuffer);
|
||||
mSearch.candidates = reinterpret_cast<wchar_t*>(&CandidatesBuffer[0x200]);
|
||||
mSearch.maxCandidates = 0x28;
|
||||
mSearch.elementCount = static_cast<u8>(elementCount);
|
||||
mSearch.firstCandidate = 0;
|
||||
mSearch.currentWord = 0;
|
||||
mSearch.wordCharCount = 0;
|
||||
mSearch.count = 0;
|
||||
mSearch.letters = 0;
|
||||
mSearch.completion = 0;
|
||||
mSearch.scratch = 0;
|
||||
|
||||
if (getPredictLanguage() == 1) {
|
||||
mSearch.getMode = 1;
|
||||
mSearch.context = 0x11;
|
||||
if (mbKoreanPartialConfirm != 0) {
|
||||
mSearch.context |= 0x20;
|
||||
mSearch.getOptions |= 0x10;
|
||||
}
|
||||
mSearch.currentWord = reinterpret_cast<wchar_t*>(LatestWord);
|
||||
mSearch.wordCharCount = wcslen((wchar_t*)LatestWord);
|
||||
}
|
||||
|
||||
if (elementCount == 0 && mSearch.wordCharCount == 0) {
|
||||
init();
|
||||
}
|
||||
else if (elementCount == 1 &&
|
||||
(0xeff1 <= ElementBuffer[0] && ElementBuffer[0] <= 0xeff9) &&
|
||||
mpHoldingKey != NULL && getPredictLanguage() != 0x12) {
|
||||
CandidatedWord[0] = 0x3e;
|
||||
CandidatedWord[1] = 0;
|
||||
mCandidateCount = 1;
|
||||
u16* output = CandidatedWord + 0x40;
|
||||
for (s32 keyIndex = 1; keyIndex < 16; ++keyIndex) {
|
||||
u16 candidate = static_cast<keyboard::cellphonetype::PaneNameToCharCode*>(mpHoldingKey)->wc[keyIndex - 1];
|
||||
if (candidate != 0) {
|
||||
output[0] = candidate;
|
||||
output[1] = 0;
|
||||
++mCandidateCount;
|
||||
}
|
||||
output += 0x40;
|
||||
}
|
||||
EZTXGetCandidates(&mSearch, mpDictionaryWork);
|
||||
}
|
||||
else {
|
||||
memcpy(&CandidatesBuffer[0x200], CandidatesBuffer, 0x200);
|
||||
ChangeDictionaryLanguage(getPredictLanguage());
|
||||
u32 count = EZTXGetCandidates(&mSearch, mpDictionaryWork) & 0xff;
|
||||
if (getPredictLanguage() == 1 && count == 0x61) {
|
||||
mSearch.firstCandidate = 0x61;
|
||||
mSearch.candidates = reinterpret_cast<wchar_t*>(&CandidatesBuffer[0x2c2]);
|
||||
mSearch.maxCandidates = 199;
|
||||
count = EZTXGetCandidates(&mSearch, mpDictionaryWork) & 0xff;
|
||||
mSearch.firstCandidate = 0;
|
||||
count += 0x61;
|
||||
mSearch.candidates = reinterpret_cast<wchar_t*>(&CandidatesBuffer[0x200]);
|
||||
}
|
||||
if (static_cast<s32>(count) > 0x28) {
|
||||
count = 0x28;
|
||||
}
|
||||
if (getPredictLanguage() == 1 && mbContextChanged != 0 &&
|
||||
(mbContextChanged = 0, mSearch.wordCharCount == 0)) {
|
||||
u32 length = mCurrentWordLength;
|
||||
u32 wordLength = wcslen((wchar_t*)LatestWord) & 0xff;
|
||||
u32 copied;
|
||||
u16* source = LatestWord + wordLength - length;
|
||||
for (copied = 0; copied < length; ++copied) {
|
||||
LatestWord[copied] = source[copied];
|
||||
}
|
||||
LatestWord[copied] = 0;
|
||||
mSearch.wordCharCount = wcslen((wchar_t*)LatestWord);
|
||||
count = EZTXGetCandidates(&mSearch, mpDictionaryWork) & 0xff;
|
||||
}
|
||||
if (count == 0) {
|
||||
if (getPredictLanguage() != 1) {
|
||||
if (getPredictLanguage() == 0x12) {
|
||||
backSpace();
|
||||
return;
|
||||
}
|
||||
count = complementsCandidates_(elementCount);
|
||||
}
|
||||
if (count == 0) return;
|
||||
}
|
||||
memset(CandidatedWord, 0, 0x1400);
|
||||
mCandidateCount = 0;
|
||||
if (elementCount != 0 || mSearch.wordCharCount != 0) {
|
||||
u16* source = reinterpret_cast<u16*>(mSearch.candidates);
|
||||
u16* destination = CandidatedWord;
|
||||
for (s32 index = 0; index < static_cast<s32>(count); index++) {
|
||||
if (getPredictLanguage() == 1) {
|
||||
s32 length = 0;
|
||||
u16* output = destination;
|
||||
for (; *source != 0x20 && *source != 0; source++) {
|
||||
*output++ = *source;
|
||||
++length;
|
||||
}
|
||||
++source;
|
||||
destination[length] = 0;
|
||||
} else if (mPredictLanguage == PL_11) {
|
||||
*destination = *source++;
|
||||
destination[1] = 0;
|
||||
} else if (getPredictLanguage() == 0x12) {
|
||||
u16* output = destination;
|
||||
while (*source >= 0x100) {
|
||||
*output++ = *source++;
|
||||
}
|
||||
} else if (EZTXCopy(reinterpret_cast<wchar_t*>(destination), &mSearch, index & 0xff, mpDictionaryWork) == 0) {
|
||||
goto nextCandidate;
|
||||
}
|
||||
++mCandidateCount;
|
||||
{
|
||||
s32 position = 0;
|
||||
for (u16* candidate = destination; *candidate != 0; ++candidate) {
|
||||
switch (mLetterMode) {
|
||||
case LM_1:
|
||||
*candidate = util::toWLower(*candidate);
|
||||
break;
|
||||
case LM_2:
|
||||
*candidate = util::toWUpper(*candidate);
|
||||
break;
|
||||
case LM_0:
|
||||
if (position == 0) *candidate = util::toWUpper(*candidate);
|
||||
else *candidate = util::toWLower(*candidate);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
++position;
|
||||
}
|
||||
}
|
||||
nextCandidate:
|
||||
destination += 0x40;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
u32 WithZi::complementsCandidates_(s32) {
|
||||
bool useSentinel;
|
||||
u16 value;
|
||||
u16* scan = ElementBuffer;
|
||||
goto scanCheck;
|
||||
scanBody:
|
||||
if (0xeff1 <= value && value <= 0xeff9) {
|
||||
useSentinel = true;
|
||||
goto scanDone;
|
||||
}
|
||||
++scan;
|
||||
scanCheck:
|
||||
value = *scan;
|
||||
if (value != 0) goto scanBody;
|
||||
useSentinel = false;
|
||||
scanDone:
|
||||
if (useSentinel) {
|
||||
CandidatedWord[mInputLength - 1] = 0xfffe;
|
||||
CandidatedWord[mInputLength] = 0;
|
||||
}
|
||||
else {
|
||||
u16* character;
|
||||
u16* destination;
|
||||
u32 length;
|
||||
u16* source;
|
||||
length = 0;
|
||||
destination = CandidatedWord;
|
||||
source = ElementBuffer;
|
||||
character = source;
|
||||
while (*source != 0) {
|
||||
s32 mode = mLetterMode;
|
||||
if (mode == 2) goto modeTwo;
|
||||
if (mode >= 2) goto modeThree;
|
||||
if (mode == 0) goto modeZero;
|
||||
if (mode >= 0) goto modeOne;
|
||||
goto modeDone;
|
||||
modeThree:
|
||||
if (mode >= 4) goto modeDone;
|
||||
goto modeCopy;
|
||||
modeOne:
|
||||
*destination = util::toWLower(*character);
|
||||
goto modeDone;
|
||||
modeTwo:
|
||||
*destination = util::toWUpper(*character);
|
||||
goto modeDone;
|
||||
modeZero:
|
||||
if (length == 0) {
|
||||
*destination = util::toWUpper(*character);
|
||||
}
|
||||
else {
|
||||
*destination = util::toWLower(*character);
|
||||
}
|
||||
goto modeDone;
|
||||
modeCopy:
|
||||
*destination = *character;
|
||||
modeDone:
|
||||
++source;
|
||||
++character;
|
||||
++destination;
|
||||
++length;
|
||||
}
|
||||
CandidatedWord[length] = 0;
|
||||
}
|
||||
mCandidateCount = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 WithZi::setElementBuffer() {
|
||||
u32 count = 0;
|
||||
u16* elements = ElementBuffer;
|
||||
u16* candidates = CandidatesBuffer;
|
||||
memset(elements, 0, 0x1fe);
|
||||
memset(candidates + 0x100, 0, 0x1fe);
|
||||
u16 inputCharacter;
|
||||
while ((inputCharacter = candidates[static_cast<u16>(count)]) != 0 && static_cast<u16>(count) < 0xff) {
|
||||
u16 index = count;
|
||||
elements[index] = inputCharacter;
|
||||
if (getPredictLanguage() == 1) {
|
||||
s32 character = elements[index];
|
||||
if (0x30 <= character && character <= 0x39) elements[index] = character + 0xf300;
|
||||
else if ((0x61 <= character && character <= 0x7a) || (0x41 <= character && character <= 0x5a)) elements[index] += 0xf300;
|
||||
}
|
||||
++count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
bool WithZi::isFix() {
|
||||
return mInputLength == 0;
|
||||
}
|
||||
|
||||
u8 WithZi::getPredictLanguage() {
|
||||
switch (mPredictLanguage) {
|
||||
case 0: return 0x3b;
|
||||
case 1: return 0x40;
|
||||
case 2: return 0x41;
|
||||
case 3: return 0x3a;
|
||||
case 4: return 5;
|
||||
case 5: return 0x3f;
|
||||
case 6: return 0x42;
|
||||
case 7: return 0x2f;
|
||||
case 8: return 0xd;
|
||||
case 9: return 1;
|
||||
case 10: return 0x12;
|
||||
case 11: return 0x12;
|
||||
default: return 0x3b;
|
||||
}
|
||||
}
|
||||
|
||||
void WithZi::setCurrentWord(const wchar_t* word) {
|
||||
if (word == NULL) {
|
||||
LatestWord[0] = 0x20;
|
||||
LatestWord[1] = 0;
|
||||
return;
|
||||
}
|
||||
mbContextChanged = 1;
|
||||
wchar_t* currentWord;
|
||||
u32 sourceOffset;
|
||||
u32 length;
|
||||
s32 copied;
|
||||
length = 0;
|
||||
currentWord = reinterpret_cast<wchar_t*>(LatestWord);
|
||||
for (; *currentWord != 0 && *currentWord != 0x20;
|
||||
currentWord++, ++length) {
|
||||
if (length == 0x3f) {
|
||||
LatestWord[length] = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
copied = 0;
|
||||
sourceOffset = 0;
|
||||
currentWord = const_cast<wchar_t*>(word);
|
||||
for (; *currentWord != 0 && length < 0x3f;) {
|
||||
wchar_t character = word[sourceOffset];
|
||||
++length;
|
||||
++currentWord;
|
||||
++copied;
|
||||
LatestWord[length - 1] = character;
|
||||
++sourceOffset;
|
||||
}
|
||||
LatestWord[length] = 0;
|
||||
mCurrentWordLength = copied;
|
||||
}
|
||||
|
||||
void WithZi::EnableKSXFilter(bool) {}
|
||||
|
||||
bool WithZi::canBackSpace() {
|
||||
return mInputLength != 0;
|
||||
}
|
||||
|
||||
void WithZi::clear() {}
|
||||
|
||||
}
|
||||
}
|
||||
17
tools/decomp-assist/tiString.attempts.md
Normal file
17
tools/decomp-assist/tiString.attempts.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# tiString attempts
|
||||
|
||||
Initial reconstruction uses the sibling tiString and tiUtil headers, real member definitions and compiler-generated vtables. The unit has no string literals; both pools are empty and identical. The normal derived destructor emits its vtable before the base vtable, restoring all 288 data bytes. The extracted target omits the derived destructor body; this additional ordinary destructor will need consideration during the later linking phase.
|
||||
|
||||
## insert
|
||||
1. Separate getLength temporary and typed string indexing: 79/79 instructions, eight scheduling/register differences.
|
||||
2. Precompute a tail pointer before getLength: 76/79 instructions, additional callee-saved register and address lifetime differences.
|
||||
3. Precompute an element index: 79/79, same eight differences.
|
||||
4. Put getLength directly in wcsncpy's length argument: 79/79, zero differences; retained.
|
||||
|
||||
## inputChar
|
||||
1. Remove inherited scratch source's volatile buffer pointer, use an ordinary pointer and u32 count: 126/136. Kana conversion matches; Hangul path folds indexed stores and cursor additions lose two narrowing instructions.
|
||||
2. u16 count and separate newline/ordinary character branches: 126/136, same differences. Compiler folds the equivalent branches; discarded the redundant condition.
|
||||
3. Direct array indexing with no buffer alias, u16 count: 125/136. Hangul output collapses to direct stores and constant count; retained the readable version. Remaining mismatch is the Hangul output indexing/count lifetime and subsequent cursor-add narrowing, not strings or data.
|
||||
|
||||
## character predicates
|
||||
The sibling util declarations return bool, while target callers normalize an integer result. Guarded u32 declarations preserve every other translation unit and make all three predicates 16/16 with zero differences.
|
||||
45
tools/decomp-assist/tiZiString.attempts.md
Normal file
45
tools/decomp-assist/tiZiString.attempts.md
Normal file
@@ -0,0 +1,45 @@
|
||||
# tiZiString attempts
|
||||
|
||||
Created readable members from the extracted object and the existing tiString, tiZiString, tiUtil and tiCpData declarations. No source existed at task start. Replaced old scratch source's raw field casts, fabricated vtables, address labels and casts to an incompatible EZTXGetCandidates prototype. Reused PaneNameToCharCode::wc for holding-key characters; dictionary offsets are the actual serialized OEM dictionary format. Both string pools are empty. All 7680 data bytes match: BSS buffers in original order, ordinary Korean letter tables, ten Latin search-order entries, compiler switch table and vtable. The second Korean lookup table has the target's sixteen wchar_t slots, initialized with its ordinary fourteen-character literal and terminator.
|
||||
|
||||
## destructor
|
||||
1. Normal destructor with only the dictionary allocation release: 29/31 instructions. Base destructor relocation was Decolated, whereas target calls StringBase.
|
||||
2. Supply the ordinary inline Decolated destructor: 31/31, zero differences. Retained; the compiler supplies the additional null test and base destruction.
|
||||
|
||||
## clearCandidates
|
||||
1. Typed EZTX fields and actual CandidatesBuffer subarrays instead of out-of-bounds ElementBuffer aliases: 84/81, 88.5679%. An additional pooled-buffer base register is live.
|
||||
2. Reorder elementCount before firstCandidate as in the target: still 84/81, improved to 91.049385%. Retained.
|
||||
3. Initialize typed elements/candidates pointers before the open-dictionary test: 80/81, 83.34568%, with additional saved registers and changed address lifetimes. Discarded.
|
||||
Remaining: pooled buffer addresses and their register lifetimes; no raw cross-object offset alias is used.
|
||||
|
||||
## partialConfirmForKR
|
||||
1. Explicit grouped comparisons inherited from scratch: 153/147; duplicated one-character fallback and missing loop-index maintenance.
|
||||
2. Ordinary bounded indexed loops with initialized match flag and shared fallback: 148/147; flag lifetime differed.
|
||||
3. Assign match only on loop exit, share fallback via labels: 147/147, 23 register differences.
|
||||
4. Share loop index across both scans: unchanged 23 differences.
|
||||
5. Pointer scans with postincrement: 147/147, 21 differences including scheduling.
|
||||
6. Increment pointers after the unsuccessful comparison: 147/147, twelve differences, all r4/r5 in the second scan. Retained.
|
||||
7. Initialize the second index before assigning its table pointer: unchanged twelve differences. These are allocator tie-breaks.
|
||||
|
||||
## update
|
||||
1. Replace raw EZTX bytes with fields and holding-key offsets with typed records: 441/446, 77.3296%. This exposed incorrect scratch semantics and a wrong parameter-field layout.
|
||||
2. Reset selected candidate, use a zero-extended element count, correct EZTX byte fields, use context |= 0x20 and inclusive element bounds; use a real bounded key-character loop and normal two-argument library call: 455/446. Corrected state/parameter writes and removed the incompatible function-pointer call.
|
||||
3. Replace the manually expanded latest-word copy with an ordinary loop: 456/446.
|
||||
4. Make the zero-extended element count a signed comparison operand: 456/446, 84.84529%.
|
||||
5. Reuse sibling PaneNameToCharCode::wc; preserve the destination base with separate copy cursors; share successful candidate counting and use the target's letter-mode switch: 448/446, 91.4305%. Retained.
|
||||
Remaining: buffer-base lifetimes, phone-loop scheduling, context-copy loop and saved-register allocation. No artificial extra library arguments retained.
|
||||
|
||||
## setElementBuffer
|
||||
1. Typed indices replacing raw byte offsets: 67/65, 88.58462%; an extra index narrowing and secondary buffer base.
|
||||
2. u32 element index rather than u16: 67/65; same count, different shift/narrowing.
|
||||
3. Direct typed indices in condition/body: 66/65, with an extra load of the input character.
|
||||
4. Initialize typed pointers/count before memset and use the condition's loaded character in the body: 65/65, twenty-four instruction differences; 87.815384%. Retained as the closest instruction structure.
|
||||
5. Initialize pointers after memset and keep a u32 masked index: 66/65, 87.49231%. Discarded.
|
||||
Remaining: pooled buffer base setup and callee-saved register assignments, with identical instruction count.
|
||||
|
||||
## setCurrentWord
|
||||
1. Normal element indexing in the existing copy loops: 56/56, twenty-one differences; compiler strength-reduces indexed accesses to moving pointers.
|
||||
2. Load source character then advance length/cursors before storing: 56/56, same differences.
|
||||
3. Unsigned source/destination indices, store via length - 1: 56/56, same differences.
|
||||
4. Remove the now-unused destination index: retained readable implementation; no output change.
|
||||
Remaining: copy-loop address strength reduction, scheduling and caller-register assignments; 86.69643%.
|
||||
Reference in New Issue
Block a user