Compare commits
47 Commits
agent/read
...
agent/w092
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
87076add19 | ||
|
|
03836d5db4 | ||
|
|
14b2f5ea29 | ||
|
|
41877f03dc | ||
|
|
bc95aa48e9 | ||
|
|
64018b3b33 | ||
|
|
2748f29a98 | ||
|
|
e6ef163648 | ||
|
|
c765bd2eca | ||
|
|
c65c722932 | ||
|
|
df54d9a348 | ||
|
|
b983deeb07 | ||
|
|
b615148895 | ||
|
|
95c685534e | ||
|
|
68f1674a5d | ||
|
|
5875521928 | ||
|
|
0e4f2c726f | ||
|
|
620a8a6814 | ||
|
|
84972cb9f1 | ||
|
|
54d865f151 | ||
|
|
0e31a5b37c | ||
|
|
8b568557b0 | ||
|
|
19f6c82a98 | ||
|
|
3e81c24a0c | ||
|
|
5e0fbb88f0 | ||
|
|
32da26fae0 | ||
|
|
413e6c483b | ||
|
|
d76c36462f | ||
|
|
f1cc81a228 | ||
|
|
ca4339eece | ||
|
|
0107230f11 | ||
|
|
c77b866ed4 | ||
|
|
550c5f19c1 | ||
|
|
e00d7aefd6 | ||
|
|
92f10a65fa | ||
|
|
e858a9362d | ||
|
|
bd1885f9be | ||
|
|
42647c75c1 | ||
|
|
83a55a20a0 | ||
|
|
46f34f11f5 | ||
|
|
1bc8f49115 | ||
|
|
f055c43c22 | ||
|
|
985bae5d42 | ||
|
|
d4696caeaf | ||
|
|
2b4ed18122 | ||
|
|
02e50d2dc2 | ||
|
|
46d7abf8c0 |
62
.github/workflows/readme-progress.yml
vendored
Normal file
62
.github/workflows/readme-progress.yml
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
name: README progress
|
||||
|
||||
# runs on the self-hosted runner on cole's server so it doesn't use hosted minutes.
|
||||
# only push/schedule/manual triggers, never pull_request, so fork PRs can't reach this machine.
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths-ignore: [README.md]
|
||||
schedule:
|
||||
- cron: "*/30 * * * *"
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: readme-progress
|
||||
cancel-in-progress: true
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
progress:
|
||||
runs-on: [self-hosted, wii-ipl-local]
|
||||
timeout-minutes: 60
|
||||
env:
|
||||
ORIG_APP: /mnt/drive2/projects/wiichannels/wii-ipl/orig/43U/00000008.app
|
||||
TOOL_CACHE: /mnt/drive2/projects/wiichannels/wii-ipl/build
|
||||
NINJA: /home/cole/projects/tests/.venv/bin/ninja
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: main
|
||||
fetch-depth: 1
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
mkdir -p build orig/43U
|
||||
cp "$ORIG_APP" orig/43U/00000008.app
|
||||
[ -d build/compilers ] || cp -a "$TOOL_CACHE/compilers" build/
|
||||
[ -d build/tools ] || cp -a "$TOOL_CACHE/tools" build/
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
python3 configure.py --version 43U
|
||||
"$NINJA"
|
||||
"$NINJA" build/43U/ok
|
||||
|
||||
- name: Report
|
||||
run: build/tools/objdiff-cli report generate -p . -o build/43U/report.json -f json
|
||||
|
||||
- name: Update README
|
||||
run: python3 tools/update_readme_progress.py build/43U/report.json README.md "$GITHUB_SHA"
|
||||
|
||||
- name: Commit
|
||||
run: |
|
||||
if git diff --quiet README.md; then exit 0; fi
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||
git add README.md
|
||||
git commit -m "docs: update progress [skip ci]"
|
||||
git pull --rebase origin main || { git rebase --abort; echo "main moved, next run will update"; exit 0; }
|
||||
git push origin HEAD:main
|
||||
10
README.md
10
README.md
@@ -50,6 +50,16 @@ Supported versions:
|
||||
|
||||
Progress
|
||||
========
|
||||
<!-- progress:start -->
|
||||
| Decompiled | Matched | Linked | Data |
|
||||
|:---:|:---:|:---:|:---:|
|
||||
| 87.60% | 77.28% | 56.92% | 88.22% |
|
||||
|
||||
units 752/1027 complete, functions 11313/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 -->
|
||||
|
||||
| Version | Progress |
|
||||
|-----------------------|------------------------------------------------------------------------------|
|
||||
| [Wii Menu 4.3U][V43U] | [![FuncBadgeV43U]][V43U] [![DecompBadgeV43U]][V43U] [![LinkBadgeV43U]][V43U] |
|
||||
|
||||
20
configure.py
20
configure.py
@@ -1682,11 +1682,11 @@ config.libs = [
|
||||
]
|
||||
),
|
||||
RVLSDKLib("fa", [
|
||||
Object(NonMatching, "fa/pf_clib.c"),
|
||||
Object(NonMatching, "fa/pf_code.c"),
|
||||
Object(NonMatching, "fa/pf_service.c"),
|
||||
Object(NonMatching, "fa/pf_str.c"),
|
||||
Object(NonMatching, "fa/pf_driver.c"),
|
||||
Object(Matching, "fa/pf_clib.c"),
|
||||
Object(Matching, "fa/pf_code.c"),
|
||||
Object(Matching, "fa/pf_service.c"),
|
||||
Object(Matching, "fa/pf_str.c"),
|
||||
Object(Matching, "fa/pf_driver.c"),
|
||||
Object(NonMatching, "fa/pdm_api.c"),
|
||||
Object(NonMatching, "fa/pdm_bpb.c"),
|
||||
Object(NonMatching, "fa/pdm_disk.c"),
|
||||
@@ -1733,15 +1733,15 @@ config.libs = [
|
||||
Object(Matching, "fa/pf_ferror.c"),
|
||||
Object(NonMatching, "fa/pf_finfo.c"),
|
||||
Object(Matching, "fa/pf_flock.c"),
|
||||
Object(NonMatching, "fa/pf_fopen.c"),
|
||||
Object(Matching, "fa/pf_fopen.c"),
|
||||
Object(NonMatching, "fa/pf_format.c"),
|
||||
Object(Matching, "fa/pf_fread.c"),
|
||||
Object(NonMatching, "fa/pf_fseek.c"),
|
||||
Object(Matching, "fa/pf_fseek.c"),
|
||||
Object(NonMatching, "fa/pf_fsetclstlink.c"),
|
||||
Object(NonMatching, "fa/pf_fsexec.c"),
|
||||
Object(NonMatching, "fa/pf_fsfirst.c"),
|
||||
Object(NonMatching, "fa/pf_fsnext.c"),
|
||||
Object(NonMatching, "fa/pf_fstat.c"),
|
||||
Object(Matching, "fa/pf_fsfirst.c"),
|
||||
Object(Matching, "fa/pf_fsnext.c"),
|
||||
Object(Matching, "fa/pf_fstat.c"),
|
||||
Object(Matching, "fa/pf_fsync.c"),
|
||||
Object(Matching, "fa/pf_fwrite.c"),
|
||||
Object(NonMatching, "fa/pf_getdev.c"),
|
||||
|
||||
@@ -61,7 +61,11 @@ namespace ipl {
|
||||
const char* getIconComment(u8 slot, s16 fileNo);
|
||||
|
||||
void initCardThread();
|
||||
#if defined(IPL_MEMORY_CARD_CPP) || defined(IPL_CARD_SEQUENCE_CPP)
|
||||
BOOL shutdownCardThread();
|
||||
#else
|
||||
bool shutdownCardThread();
|
||||
#endif
|
||||
} // namespace memorycard
|
||||
} // namespace ipl
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace textinput {
|
||||
virtual void moveNigaoeButton() {}
|
||||
};
|
||||
|
||||
#ifdef MYTIINPUTFORM_IMPLEMENTATION
|
||||
#if defined(MYTIINPUTFORM_IMPLEMENTATION) || defined(MYTILETTERFORM_IMPLEMENTATION)
|
||||
class ScrollButton;
|
||||
#endif
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace textinput {
|
||||
#endif
|
||||
|
||||
~InputForm();
|
||||
#ifdef MYTIINPUTFORM_IMPLEMENTATION
|
||||
#if defined(MYTIINPUTFORM_IMPLEMENTATION) || defined(MYTILETTERFORM_IMPLEMENTATION)
|
||||
virtual void moveCursorUp();
|
||||
virtual void moveCursorDown();
|
||||
virtual void onCommand(INPUT_COMMAND command, void* data);
|
||||
@@ -131,7 +131,7 @@ namespace textinput {
|
||||
void setEditScrollDown(bool editScrollDown) { mbEditScrollUp = editScrollDown; }
|
||||
void setCloseWithSend(bool closeWithSend) { mbCloseWithSend = closeWithSend; }
|
||||
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(MYTIINPUTFORM_IMPLEMENTATION)
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(MYTIINPUTFORM_IMPLEMENTATION) || defined(MYTILETTERFORM_IMPLEMENTATION)
|
||||
void setEditMode(EditMode editMode);
|
||||
#else
|
||||
void setEditMode(EditMode editMode) { meEditMode = editMode; }
|
||||
@@ -147,8 +147,12 @@ namespace textinput {
|
||||
|
||||
tistring::Decolated* getSendString() { return mpSendString; }
|
||||
|
||||
#ifdef MYTILETTERFORM_IMPLEMENTATION
|
||||
protected:
|
||||
#else
|
||||
private:
|
||||
#ifdef MYTIINPUTFORM_IMPLEMENTATION
|
||||
#endif
|
||||
#if defined(MYTIINPUTFORM_IMPLEMENTATION) || defined(MYTILETTERFORM_IMPLEMENTATION)
|
||||
nw4r::lyt::Pane* mpMemoPane;
|
||||
nw4r::lyt::Pane* mpMemoRootPane;
|
||||
nw4r::lyt::Pane* mpBoundPane;
|
||||
@@ -172,7 +176,7 @@ namespace textinput {
|
||||
nw4r::lyt::Size mDefaultBoundSize; // 0x358
|
||||
Mtx mDrawMtx; // 0x360
|
||||
Mtx mBoundMtx; // 0x390
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(MYTIINPUTFORM_IMPLEMENTATION)
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(MYTIINPUTFORM_IMPLEMENTATION) || defined(MYTILETTERFORM_IMPLEMENTATION)
|
||||
util::Animation mExScrollAnm; // 0x3C0
|
||||
#else
|
||||
u8 /*todo*/ mExScrollAnm[32]; // 0x3C0
|
||||
@@ -186,7 +190,7 @@ namespace textinput {
|
||||
bool mbEditScrollDown; // 0x3EF
|
||||
bool mbCloseWithSend; // 0x3F0
|
||||
u8 padding[3]; // 0x3F1
|
||||
#ifdef MYTIINPUTFORM_IMPLEMENTATION
|
||||
#if defined(MYTIINPUTFORM_IMPLEMENTATION) || defined(MYTILETTERFORM_IMPLEMENTATION)
|
||||
ScrollButton* mpScrollButton;
|
||||
#else
|
||||
undefined4* mpScrollButton;
|
||||
|
||||
@@ -23,6 +23,15 @@ namespace textinput {
|
||||
unk_0x400(0), mbPhotoDraw(false), meType(T_MailAddressSel) {}
|
||||
#endif
|
||||
|
||||
#ifdef MYTILETTERFORM_IMPLEMENTATION
|
||||
virtual ~InputForm();
|
||||
virtual void create(MEMAllocator*, inputform::EditBuffer*);
|
||||
virtual void drawBody();
|
||||
virtual void drawFooter();
|
||||
virtual void open();
|
||||
virtual void close();
|
||||
virtual bool isWholePaneInAnimation();
|
||||
#endif
|
||||
virtual nw4r::lyt::Material* getPhotoPaneMaterial();
|
||||
|
||||
virtual void onPhotoTrig();
|
||||
@@ -38,7 +47,11 @@ namespace textinput {
|
||||
void resizePhotoPane(f32 width, f32 height);
|
||||
|
||||
private:
|
||||
#ifdef MYTILETTERFORM_IMPLEMENTATION
|
||||
bool mbPhotoScaledUp;
|
||||
#else
|
||||
u8 unk_0x400;
|
||||
#endif
|
||||
bool mbPhotoDraw; // 0x401
|
||||
Type meType; // 0x404
|
||||
};
|
||||
|
||||
@@ -48,6 +48,9 @@ namespace textinput {
|
||||
|
||||
class CandidateBoxCaller {
|
||||
public:
|
||||
#ifdef TIINPUTFORM_IMPLEMENTATION
|
||||
CandidateBoxCaller() : mpCandidateBox(NULL) {}
|
||||
#endif
|
||||
// This candidate thing is a bit different from the dwarf
|
||||
class Candidates {
|
||||
public:
|
||||
@@ -74,6 +77,9 @@ namespace textinput {
|
||||
|
||||
class Base : public CommandSender {
|
||||
public:
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
Base(Manager* manager) : mpCandidates(NULL), mpAllocator(NULL), mbOn(false), mbInvalid(true), meLanguage(USA), mpManager(manager) {}
|
||||
#endif
|
||||
virtual ~Base();
|
||||
virtual void create(MEMAllocator* allocator) override;
|
||||
virtual void init() override {}
|
||||
@@ -108,6 +114,9 @@ namespace textinput {
|
||||
|
||||
class EventHandler : public nw4rmanager::TiEventHandler {
|
||||
public:
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
EventHandler(LayoutByNW4R* layout) : mpLayoutByNW4R(layout) {}
|
||||
#endif
|
||||
virtual void onTiEvent(gui::PaneComponent* paneComponent, u32 event, Input* input) override; // 0x18
|
||||
|
||||
LayoutByNW4R* mpLayoutByNW4R; // 0xC
|
||||
@@ -281,6 +290,13 @@ namespace textinput {
|
||||
// TODO
|
||||
class LayoutByNW4R : public Base, public nw4rmanager::Layout, public UIObj::Listener {
|
||||
public:
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
LayoutByNW4R(Manager* manager, nw4r::lyt::MultiArcResourceAccessor* accessor, EventObserver* observer, const char* layoutName)
|
||||
: Base(manager), nw4rmanager::Layout(accessor, layoutName, observer), mEventHandler(this), mpTiString(NULL),
|
||||
mTextArea(0, this, this), mLeftScroll(1, this, this), mRightScroll(2, this, this), mOnOffButton(3, this, this),
|
||||
mTextWindow(4, this, this), mbActive(true) {}
|
||||
const UIOnOffButton& getOnOffButton() const { return mOnOffButton; }
|
||||
#endif
|
||||
virtual ~LayoutByNW4R();
|
||||
virtual void create(MEMAllocator* allocator) override;
|
||||
virtual void init() override;
|
||||
@@ -323,6 +339,9 @@ namespace textinput {
|
||||
virtual void cancelStateFocusIn(); // 0x128
|
||||
virtual void onEvent(UIObj*, u32, void*) override; // 0x12C
|
||||
|
||||
#ifdef TIINPUTFORM_IMPLEMENTATION
|
||||
UITextArea& getTextArea() { return mTextArea; }
|
||||
#endif
|
||||
void onPressedShift(bool shift);
|
||||
void onReleasedShift();
|
||||
void startTurnOn(bool);
|
||||
|
||||
@@ -2,20 +2,20 @@
|
||||
#define TEXTINPUT_CELL_PHONE_H
|
||||
|
||||
#include "tiNw4rManager.h"
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
#include "tiKeyboard.h"
|
||||
#endif
|
||||
|
||||
namespace textinput {
|
||||
namespace keyboard {
|
||||
namespace cellphonetype {
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
class Base : public textinput::keyboard::KeyboardBase {
|
||||
#else
|
||||
class Base {
|
||||
#endif
|
||||
public:
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
enum InputMode {
|
||||
IM_00,
|
||||
IM_01,
|
||||
@@ -29,7 +29,12 @@ namespace textinput {
|
||||
virtual void init() override;
|
||||
virtual void updateFromReceiver(u32, void*) override;
|
||||
virtual void onKey(u32, void*) override;
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
Base(Manager* manager) : mpManager(manager) {}
|
||||
virtual int getType() override;
|
||||
#else
|
||||
virtual void getType() override;
|
||||
#endif
|
||||
virtual void onActive() override;
|
||||
virtual void calc();
|
||||
virtual void draw();
|
||||
@@ -74,7 +79,7 @@ namespace textinput {
|
||||
|
||||
virtual void vt_0x4C();
|
||||
virtual void vt_0x50();
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
virtual void doNumericMode(bool);
|
||||
#else
|
||||
virtual void vt_0x54();
|
||||
@@ -90,8 +95,11 @@ namespace textinput {
|
||||
|
||||
// TODO enum?
|
||||
int getInputType() const;
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
void resetHoldingButton();
|
||||
#endif
|
||||
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
private:
|
||||
u32 mPreviousInputMode;
|
||||
u32 mCurrentInputMode;
|
||||
@@ -104,17 +112,47 @@ namespace textinput {
|
||||
u32 mHoldingButton;
|
||||
void* mpInputModeTable;
|
||||
MEMAllocator* mpAllocator;
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
Manager* mpManager;
|
||||
#else
|
||||
void* mpInputSettings;
|
||||
#endif
|
||||
u32 mInputState;
|
||||
#endif
|
||||
};
|
||||
|
||||
class LayoutByNW4R : public Base, public nw4rmanager::Layout {
|
||||
public:
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
LayoutByNW4R(Manager* manager, nw4r::lyt::MultiArcResourceAccessor* accessor, EventObserver* observer, const char* layoutName)
|
||||
: Base(manager), nw4rmanager::Layout(accessor, layoutName, observer), mpEventHandler(NULL) {}
|
||||
virtual ~LayoutByNW4R();
|
||||
virtual void create(MEMAllocator* allocator);
|
||||
virtual void init();
|
||||
virtual void setCommandReceiver(CommandReceiver* receiver);
|
||||
virtual void updateFromReceiver(u32 command, void* data);
|
||||
virtual void onKey(u32 event, void* data);
|
||||
virtual void setLanguage(Language language);
|
||||
virtual void update();
|
||||
virtual void onActive();
|
||||
virtual void calc();
|
||||
virtual void draw();
|
||||
virtual void changeInputMode(InputMode mode);
|
||||
virtual void setInputMode(InputMode mode);
|
||||
virtual void setUpperCaseJP(bool upper);
|
||||
virtual void setLangKeyActive(bool active);
|
||||
virtual void goSignInputMode();
|
||||
virtual void changePredictLanguage();
|
||||
virtual void setAbcMode(bool abc);
|
||||
virtual void doNumericMode(bool);
|
||||
virtual void setPredictLanguageDialog(predictlang::LayoutByNW4R* dialog);
|
||||
virtual void setSignWindow(signwindow::LayoutByNW4R* window);
|
||||
#else
|
||||
virtual void doNumericMode(bool);
|
||||
virtual void setPredictLanguageDialog(void*);
|
||||
virtual void setSignWindow(void*);
|
||||
#endif
|
||||
virtual void doNumericWithDotMode(bool);
|
||||
virtual void setLineFeedButton(bool);
|
||||
virtual void setPredictLanguageButton(bool);
|
||||
@@ -124,9 +162,31 @@ namespace textinput {
|
||||
|
||||
void onPressedShift(bool shift);
|
||||
void onReleasedShift();
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
bool hasLineFeedButton() const { return mbLineFeedButton; }
|
||||
private:
|
||||
bool mbLineFeedButton;
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
GXTexObj mSpaceTexture;
|
||||
GXTexObj mSpaceTextureCN;
|
||||
GXTexObj mSpaceTextureKR;
|
||||
nw4rmanager::TiEventHandler* mpEventHandler;
|
||||
predictlang::LayoutByNW4R* mpPredictDialog;
|
||||
signwindow::LayoutByNW4R* mpSignWindow;
|
||||
#endif
|
||||
public:
|
||||
#endif
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
virtual bool updateInput(int chan, f32 x, f32 y, u32 trig, u32 hold, u32 release, void* data) override;
|
||||
virtual bool updateInput(input::HKBManager& hkbManager) override;
|
||||
#endif
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
virtual nw4rmanager::AnmPane* getAnmPane(InputMode mode);
|
||||
virtual void throwReleaseForAll();
|
||||
virtual void changeAnimationAllToNormal();
|
||||
virtual void updatePredictLanguage(CommandReceiver::ChangePredictMode* mode);
|
||||
virtual void changeKeyTop(const struct PaneNameToCharCode* table);
|
||||
virtual void changeSpaceKeyTop(const struct PaneNameToCharCode* table);
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@@ -92,6 +92,9 @@ namespace textinput {
|
||||
EVENT_RELEASE
|
||||
};
|
||||
|
||||
#ifdef TIINPUTFORM_IMPLEMENTATION
|
||||
virtual void init();
|
||||
#else
|
||||
virtual void init() { // 0x10
|
||||
for (int i = 0; i < GUI_POINTS_MAX; i++) {
|
||||
mbPointed[i] = false;
|
||||
@@ -100,6 +103,7 @@ namespace textinput {
|
||||
mFlightDuration[i] = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
GUIComponent(u32 id)
|
||||
: GUIInterface(), mbInitialize(false), mDraggingButton(0xFFFF), mID(id), mbTriggerTarget(false), mpManager(NULL), mpListener(NULL) {
|
||||
|
||||
@@ -6,11 +6,140 @@
|
||||
#include <revolution/mem/allocator.h>
|
||||
|
||||
#include "keyboard/tiCpData.h"
|
||||
#ifdef TIHKBMANAGER_IMPLEMENTATION
|
||||
#include <revolution/kbd.h>
|
||||
enum _KBDEc { KBD_EC_BUSY = 7 };
|
||||
#endif
|
||||
|
||||
namespace textinput {
|
||||
namespace input {
|
||||
#ifdef TIHKBMANAGER_IMPLEMENTATION
|
||||
class HKBManager {
|
||||
public:
|
||||
class KeyState_ {
|
||||
public:
|
||||
void NotifyEvent(u8 down, u8 code);
|
||||
void Update();
|
||||
void UpdateModState_();
|
||||
void Clear() {
|
||||
held = 0;
|
||||
triggered = 0;
|
||||
released = 0;
|
||||
repeated = 0;
|
||||
current = 0;
|
||||
pending = 0;
|
||||
modifiers &= 0x700;
|
||||
forceMask = 0;
|
||||
forceState = 0;
|
||||
retryLeds = 0;
|
||||
}
|
||||
void Initialize(u8 channel) {
|
||||
held = 0;
|
||||
triggered = 0;
|
||||
released = 0;
|
||||
repeated = 0;
|
||||
current = 0;
|
||||
pending = 0;
|
||||
forceMask = 0;
|
||||
forceState = 0;
|
||||
retryLeds = 0;
|
||||
device = channel;
|
||||
country = 0xf;
|
||||
modifiers = 0;
|
||||
}
|
||||
u8 device;
|
||||
u32 held, triggered, released, repeated;
|
||||
u32 previous, current, pending;
|
||||
u32 modifiers, forceState, forceMask;
|
||||
s32 country;
|
||||
u8 retryLeds;
|
||||
u8 previousKeys[8], currentKeys[8], pendingKeys[8];
|
||||
u32 repeatDelay[8];
|
||||
};
|
||||
class KeySet {
|
||||
public:
|
||||
KeySet() {}
|
||||
KeySet(const HKBManager* owner, u8 kind)
|
||||
: manager(owner), type(kind), index(-1), device(0), vcode(0) {}
|
||||
u8 GetKey() const;
|
||||
u32 GetWChar() const;
|
||||
u32 GetVCode() const;
|
||||
u32 IsValid() const;
|
||||
bool CheckValidity() const {
|
||||
if (!manager) return false;
|
||||
s8 keyIndex = index;
|
||||
if (keyIndex < 0 || keyIndex >= 8) return false;
|
||||
u8 keyDevice = device;
|
||||
if (keyDevice >= 2) return false;
|
||||
switch (type) {
|
||||
case 0: return (manager->states[keyDevice].held & (1 << keyIndex)) != 0;
|
||||
case 1: return (manager->states[keyDevice].triggered & (1 << keyIndex)) != 0;
|
||||
case 2: return (manager->states[keyDevice].released & (1 << keyIndex)) != 0;
|
||||
case 3: return (manager->states[keyDevice].repeated & (1 << keyIndex)) != 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
KeySet GetNext() const;
|
||||
const HKBManager* manager;
|
||||
u8 type;
|
||||
s8 index;
|
||||
u8 device;
|
||||
mutable u16 vcode;
|
||||
};
|
||||
class KBDListenerOwn;
|
||||
class KBDListenerLinks {
|
||||
public:
|
||||
KBDListenerLinks() : previous(0), next(0) {}
|
||||
virtual ~KBDListenerLinks() {}
|
||||
virtual void OnAttach(KBDDevEvent*) = 0;
|
||||
virtual void OnDetach(KBDDevEvent*) = 0;
|
||||
virtual void OnKeyEvent(KBDKeyEvent*) = 0;
|
||||
KBDListenerOwn* previous;
|
||||
KBDListenerOwn* next;
|
||||
};
|
||||
class KBDListenerOwn : public KBDListenerLinks {
|
||||
public:
|
||||
KBDListenerOwn(HKBManager* owner) : manager(owner) {}
|
||||
virtual ~KBDListenerOwn();
|
||||
virtual void OnAttach(KBDDevEvent* event);
|
||||
virtual void OnDetach(KBDDevEvent* event);
|
||||
virtual void OnKeyEvent(KBDKeyEvent* event);
|
||||
HKBManager* manager;
|
||||
};
|
||||
HKBManager() __attribute__((never_inline));
|
||||
~HKBManager();
|
||||
static HKBManager& getInstance() { return sInstance; }
|
||||
void Initialize();
|
||||
void ClearState();
|
||||
u32 GetModifierState() const;
|
||||
void SetCountry(u8 country);
|
||||
void SetModifierState(u32 state, u32 mask);
|
||||
void SetForceModifierState(u32 state, u32 mask);
|
||||
void Update();
|
||||
KeySet GetTriggeredKeySet() const;
|
||||
KeySet GetReleasedKeySet() const;
|
||||
KeySet GetRepeatedKeySet() const;
|
||||
static void SetLedCB(_KBDEc result, void* userData);
|
||||
static void AttachCB(KBDDevEvent* event);
|
||||
static void DetachCB(KBDDevEvent* event);
|
||||
static void KeyEventCB(KBDKeyEvent* event);
|
||||
private:
|
||||
u8 initialized;
|
||||
u8 attached[2];
|
||||
u32 lockState;
|
||||
u32 retryDevices;
|
||||
const wchar_t* allowedCharacters;
|
||||
u32 allowedCharacterCount;
|
||||
KeyState_ states[2];
|
||||
KBDListenerOwn listener;
|
||||
static HKBManager sInstance;
|
||||
};
|
||||
#else
|
||||
class HKBManager {
|
||||
public:
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
void ClearState();
|
||||
#endif
|
||||
static HKBManager& getInstance() { return sInstance; }
|
||||
|
||||
void Initialize();
|
||||
@@ -19,13 +148,15 @@ namespace textinput {
|
||||
u32 GetModifierState() const;
|
||||
void SetModifierState(u32, u32);
|
||||
|
||||
#ifdef TI_PC_KEYBOARD_IMPLEMENTATION
|
||||
#if defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TISIGNWINDOW_IMPLEMENTATION)
|
||||
class KeySet {
|
||||
public:
|
||||
u8 GetKey() const;
|
||||
wchar_t GetWChar() const;
|
||||
bool IsValid() const;
|
||||
KeySet GetNext() const;
|
||||
KeySet(const KeySet& other)
|
||||
: mpManager(other.mpManager), mKind(other.mKind), mIndex(other.mIndex), mDevice(other.mDevice), mCharacter(other.mCharacter) {}
|
||||
private:
|
||||
const HKBManager* mpManager;
|
||||
u8 mKind;
|
||||
@@ -51,6 +182,7 @@ namespace textinput {
|
||||
|
||||
static HKBManager sInstance;
|
||||
};
|
||||
#endif
|
||||
} // namespace input
|
||||
} // namespace textinput
|
||||
|
||||
|
||||
@@ -8,23 +8,37 @@ namespace textinput {
|
||||
class Manager;
|
||||
namespace keyboard {
|
||||
namespace hwkey {
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
class HWKeyboard : public CommandSender {
|
||||
#else
|
||||
class HWKeyboard : CommandSender {
|
||||
#endif
|
||||
public:
|
||||
HWKeyboard(Manager *);
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
inline ~HWKeyboard();
|
||||
#else
|
||||
~HWKeyboard();
|
||||
#endif
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
void setLanguage(Destination destination, Language language);
|
||||
#endif
|
||||
|
||||
virtual void init();
|
||||
#ifdef TI_PC_KEYBOARD_IMPLEMENTATION
|
||||
wchar_t convertWCCode(wchar_t code) const;
|
||||
#endif
|
||||
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
void updateInput(int chan, f32 x, f32 y, u32 trig, u32 hold, u32 release, void* data);
|
||||
#else
|
||||
virtual void updateInput(int chan, f32 x, f32 y, u32 trig, u32 hold, u32 release, void* data);
|
||||
#endif
|
||||
virtual bool updateInput(input::HKBManager& hkbManager);
|
||||
|
||||
#ifdef TIINPUTFORM_IMPLEMENTATION
|
||||
void resetQuoteState() { mbSingleQuoteClosing = 0; mbDoubleQuoteClosing = 0; }
|
||||
#endif
|
||||
private:
|
||||
void updateShift(input::HKBManager& hkbManager);
|
||||
void controlKeyTriggeredHandler(input::HKBManager);
|
||||
@@ -33,8 +47,13 @@ namespace textinput {
|
||||
|
||||
Manager* mpManager; // 0x10
|
||||
u8 field_0x14; // 0x14
|
||||
#ifdef TIINPUTFORM_IMPLEMENTATION
|
||||
u8 mbSingleQuoteClosing;
|
||||
u8 mbDoubleQuoteClosing;
|
||||
#else
|
||||
u8 field_0x15; // 0x15
|
||||
u8 field_0x16; // 0x16
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -13,14 +13,43 @@
|
||||
#include "tiZiString.h"
|
||||
#include "tiSEId.h"
|
||||
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
extern "C" wchar_t KPRGetChar(KPRQueue* queue);
|
||||
extern "C" void KPRPutChar(KPRQueue* queue, wchar_t character);
|
||||
extern "C" void KPRClearQueue(KPRQueue* queue);
|
||||
extern "C" void KPRInitRegionUS();
|
||||
extern "C" u8 KPRLookAhead(KPRQueue* queue, wchar_t* character, wchar_t* combining);
|
||||
#endif
|
||||
|
||||
namespace textinput {
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
class Manager;
|
||||
#endif
|
||||
namespace inputform {
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
class Base;
|
||||
class EventHandler;
|
||||
class LayoutByNW4R;
|
||||
#endif
|
||||
class EditBuffer {
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
friend class textinput::Manager;
|
||||
public:
|
||||
EditBuffer() : mpString(NULL), mpUnfixString(NULL), mpZiString(NULL), mpAllocator(NULL) {}
|
||||
#endif
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
friend class LayoutByNW4R;
|
||||
friend class Base;
|
||||
#endif
|
||||
public:
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
void create(MEMAllocator* allocator);
|
||||
#endif
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
virtual ~EditBuffer();
|
||||
#else
|
||||
~EditBuffer();
|
||||
#endif
|
||||
|
||||
private:
|
||||
void* mpString; // 0x04
|
||||
@@ -30,7 +59,24 @@ namespace textinput {
|
||||
};
|
||||
|
||||
class DeadKeyStream {
|
||||
#ifdef TI_PC_KEYBOARD_IMPLEMENTATION
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
public:
|
||||
DeadKeyStream() { KPRInitRegionUS(); init(); }
|
||||
static wchar_t ToCombineClass(Language language, wchar_t code);
|
||||
static wchar_t ToIndependentClass(wchar_t code);
|
||||
inline wchar_t getChar();
|
||||
void init();
|
||||
u8 lookAhead() { return KPRLookAhead(&mKPRQueue, NULL, NULL); }
|
||||
void putChar(wchar_t character) { KPRPutChar(&mKPRQueue, character); }
|
||||
bool isEmpty() const { return mKPRQueue.oCount == 0; }
|
||||
void clear() { KPRClearQueue(&mKPRQueue); }
|
||||
private:
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
friend class textinput::Manager;
|
||||
#endif
|
||||
static bool sbCompatibleFilterEnabled;
|
||||
static inline bool isCompatible(wchar_t character);
|
||||
#elif defined(TI_PC_KEYBOARD_IMPLEMENTATION)
|
||||
public:
|
||||
static wchar_t ToIndependentClass(wchar_t code);
|
||||
#endif
|
||||
@@ -82,13 +128,57 @@ namespace textinput {
|
||||
|
||||
// TODO - location
|
||||
class RowInfoManager {
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
friend class LayoutByNW4R;
|
||||
friend class Base;
|
||||
public:
|
||||
RowInfoManager(u16 maxLength) : mpInfo(NULL), mMaxLength(maxLength), mpAllocator(NULL) {}
|
||||
void init();
|
||||
~RowInfoManager();
|
||||
#endif
|
||||
private:
|
||||
Info_* mpInfo; // 0x00
|
||||
u16 mMaxLength; // 0x04
|
||||
MEMAllocator* mpAllocator; // 0x08
|
||||
};
|
||||
|
||||
#ifdef TISIGNWINDOW_IMPLEMENTATION
|
||||
bool isAtokActive() const;
|
||||
#endif
|
||||
#ifdef MYTILETTERFORM_IMPLEMENTATION
|
||||
virtual void create(MEMAllocator* allocator);
|
||||
virtual void init();
|
||||
virtual void onCommand(INPUT_COMMAND command, void* data);
|
||||
#endif
|
||||
virtual ~Base();
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
Base(Manager* manager);
|
||||
virtual void create(MEMAllocator* allocator);
|
||||
virtual void init();
|
||||
virtual void onCommand(INPUT_COMMAND command, void* data);
|
||||
void setCursorPos(tistring::Decolated* string, u32 pos);
|
||||
void calcCursorTimer();
|
||||
bool isAtokActive() const;
|
||||
bool isVacancy() const;
|
||||
void dirtyCacheAll();
|
||||
tistring::Decolated* getCurrentString(bool inputting);
|
||||
void moveCandidateToIdx(s32 index);
|
||||
void onPressDownHWKB();
|
||||
void onPressLeftHWKB();
|
||||
void onPressRightHWKB();
|
||||
void toggleAtokMode_(u8 operation);
|
||||
void onSpaceKeyHWKB(u32 modifiers);
|
||||
void onHKBCtrlCode(HVKCode code, u32 modifiers);
|
||||
void confirmInput_();
|
||||
void confirmInputting_(wchar_t character, bool direct, u16 letterMode, bool confirmOnly, void* holdingKey);
|
||||
void inputCharZi_(wchar_t character, u32 modifiers);
|
||||
void inputCharDefault_(wchar_t character, u32 modifiers);
|
||||
void inputInputting_(wchar_t character);
|
||||
inline bool hasZiPredictions() const;
|
||||
inline bool usesZiPrediction() const;
|
||||
inline void resetPredictionContext();
|
||||
inline void resetInputRelation();
|
||||
#endif
|
||||
|
||||
virtual void create(MEMAllocator* allocator, EditBuffer* editBuffer);
|
||||
|
||||
@@ -199,15 +289,17 @@ namespace textinput {
|
||||
|
||||
virtual void makeUpCursorPos(CursorPos* cursorPos, u32 pos, s32 startLine, s32 endLine);
|
||||
|
||||
#ifdef MYTIINPUTFORM_IMPLEMENTATION
|
||||
#if defined(MYTIINPUTFORM_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(MYTILETTERFORM_IMPLEMENTATION)
|
||||
protected:
|
||||
#if !defined(TIINPUTFORM_IMPLEMENTATION) && !defined(TIMANAGER_IMPLEMENTATION)
|
||||
void setCursorPos(tistring::Decolated* string, u32 pos);
|
||||
void resetRelation();
|
||||
void calcCursorTimer();
|
||||
#endif
|
||||
void resetRelation();
|
||||
#else
|
||||
private:
|
||||
#endif
|
||||
#ifdef MYTIINPUTFORM_IMPLEMENTATION
|
||||
#if defined(MYTIINPUTFORM_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(MYTILETTERFORM_IMPLEMENTATION)
|
||||
nw4r::ut::Rect mRect;
|
||||
#else
|
||||
Rect mRect;
|
||||
@@ -219,6 +311,9 @@ namespace textinput {
|
||||
tistring::WithZi* mpZiString; // 0x16C
|
||||
InputMode meInputMode; // 0x170
|
||||
PredictMode mePredictMode; // 0x174
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
friend class textinput::Manager;
|
||||
#endif
|
||||
bool mbPredictOn; // 0x178
|
||||
bool mbDoWordWrap; // 0x179
|
||||
bool mbRightWithSpace; // 0x17A
|
||||
@@ -254,8 +349,12 @@ namespace textinput {
|
||||
};
|
||||
|
||||
class LayoutByNW4R : public Base, public nw4rmanager::Layout {
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
friend class EventHandler;
|
||||
inline const nw4r::lyt::Pane* getLanguageTextPane() const;
|
||||
#endif
|
||||
public:
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
LayoutByNW4R(textinput::Manager*, nw4r::lyt::MultiArcResourceAccessor*, const char*, EventObserver*, const char*);
|
||||
#endif
|
||||
~LayoutByNW4R();
|
||||
@@ -272,6 +371,9 @@ namespace textinput {
|
||||
|
||||
virtual nw4r::math::VEC2 getScale() const;
|
||||
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
void updateRepeatInput(u32 trig, u32 hold);
|
||||
#endif
|
||||
virtual void updateInputCommon(int chan, u32 trig, u32 hold, u32 release, void* data);
|
||||
virtual bool updateInput(int chan, f32 x, f32 y, u32 trig, u32 hold, u32 release, void* data);
|
||||
virtual bool updateInput(textinput::input::HKBManager& hkbManager);
|
||||
@@ -282,9 +384,13 @@ namespace textinput {
|
||||
virtual void setRootPaneScaleFor16x9();
|
||||
virtual void setRootPaneScaleFor4x3();
|
||||
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(MYTILETTERFORM_IMPLEMENTATION)
|
||||
virtual void onSE(sound::SE seId);
|
||||
#endif
|
||||
|
||||
virtual void visibleSeparator(bool flag);
|
||||
|
||||
#ifdef MYTIINPUTFORM_IMPLEMENTATION
|
||||
#if defined(MYTIINPUTFORM_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(MYTILETTERFORM_IMPLEMENTATION)
|
||||
protected:
|
||||
const void* mpLayoutData;
|
||||
const void* mpLanguageData;
|
||||
|
||||
@@ -8,27 +8,36 @@ namespace textinput {
|
||||
|
||||
class KeyboardBase : public CommandSender {
|
||||
public:
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
KeyboardBase() : meLanguage(JP) {}
|
||||
#endif
|
||||
virtual ~KeyboardBase() {}
|
||||
#ifndef TI_PC_KEYBOARD_IMPLEMENTATION
|
||||
#if !defined(TI_PC_KEYBOARD_IMPLEMENTATION) && !defined(TIMANAGER_IMPLEMENTATION) && !defined(TISIGNWINDOW_IMPLEMENTATION)
|
||||
virtual void create(MEMAllocator* alloc) override;
|
||||
virtual void init() override;
|
||||
virtual void setCommandReceiver(CommandReceiver* receiver) override;
|
||||
virtual void sendCommand(u32 command, void*) override;
|
||||
#endif
|
||||
#if !defined(TIMANAGER_IMPLEMENTATION) && !defined(TISIGNWINDOW_IMPLEMENTATION)
|
||||
virtual void updateFromReceiver(u32, void*) override;
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TI_PC_KEYBOARD_IMPLEMENTATION)
|
||||
#endif
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISIGNWINDOW_IMPLEMENTATION)
|
||||
virtual void onKey(u32, void*);
|
||||
#else
|
||||
virtual void onKey(u32);
|
||||
#endif
|
||||
#ifdef TI_PC_KEYBOARD_IMPLEMENTATION
|
||||
#if defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISIGNWINDOW_IMPLEMENTATION)
|
||||
virtual int getType();
|
||||
#else
|
||||
virtual void getType();
|
||||
#endif
|
||||
virtual void setLanguage(Language language);
|
||||
#ifdef TI_PC_KEYBOARD_IMPLEMENTATION
|
||||
#if defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISIGNWINDOW_IMPLEMENTATION)
|
||||
#ifdef TISIGNWINDOW_IMPLEMENTATION
|
||||
virtual Language getLanguage() const;
|
||||
#else
|
||||
virtual Language getLanguage() const { return meLanguage; }
|
||||
#endif
|
||||
virtual void update() {}
|
||||
#else
|
||||
virtual Language getLanguage() const;
|
||||
|
||||
@@ -28,11 +28,20 @@ namespace textinput {
|
||||
virtual void onEvent(nw4r::lyt::Pane* pane, u32 event) {} // 0x10
|
||||
|
||||
virtual void onSE(sound::SE seId) {}
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
virtual void onOK();
|
||||
virtual void onCancel();
|
||||
virtual void onOutOfLength();
|
||||
#else
|
||||
virtual void onOK() { printf("OK!\n"); }
|
||||
virtual void onCancel() { printf("Cancel!\n"); }
|
||||
virtual void onOutOfLength() { printf("OutOfLength\n"); }
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
namespace predictlang { class LayoutByNW4R; }
|
||||
#endif
|
||||
class Manager : public Base {
|
||||
public:
|
||||
Manager(MEMAllocator* allocator, nw4r::lyt::MultiArcResourceAccessor* multiArc, textinput::EventObserver* event);
|
||||
@@ -94,14 +103,19 @@ namespace textinput {
|
||||
#endif
|
||||
|
||||
virtual void setSecretInputMode(bool secretInputMode) { mpInputForm->setSecretModeOn(secretInputMode); }
|
||||
#ifdef IPL_ADDRESS_EDIT_CPP
|
||||
#if defined(IPL_ADDRESS_EDIT_CPP) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
void enableKSXFilter(bool compatibleFilter);
|
||||
#endif
|
||||
|
||||
virtual void setDefaultPredictionJP(int num, const char** predicts);
|
||||
virtual void setFixedPredictionJP(int num, const char** predicts);
|
||||
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
virtual void setTitleText(wchar_t* titleText);
|
||||
void initAspect();
|
||||
#else
|
||||
virtual void setTitleText(const wchar_t* titleText);
|
||||
#endif
|
||||
|
||||
virtual void start() {}
|
||||
virtual void end() {}
|
||||
@@ -146,6 +160,10 @@ namespace textinput {
|
||||
void enableCompatibleFilter(bool compatibleFilter);
|
||||
|
||||
bool isVacancy() const;
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
bool isPredictTurning() const;
|
||||
void startPredictTurnOn(bool enabled);
|
||||
#endif
|
||||
|
||||
private:
|
||||
MEMAllocator* mpAllocator; // 0x04
|
||||
@@ -159,9 +177,14 @@ namespace textinput {
|
||||
InputForm* mpInputForm; // 0x1C
|
||||
candidatebox::LayoutByNW4R* mpCandidateBox; // 0x20
|
||||
toolbar::LayoutByNW4R* mpToolBar; // 0x24
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
predictlang::LayoutByNW4R* mpPredictLanguageDialog;
|
||||
keyboard::signwindow::LayoutByNW4R* mpSignWindow;
|
||||
#else
|
||||
void* mpPredictLanguageDialog; // 0x28
|
||||
void* mpSignWindow; // 0x2C
|
||||
|
||||
#endif
|
||||
EventObserver* mpEventObserver; // 0x30
|
||||
|
||||
Destination meDestination; // 0x34
|
||||
|
||||
@@ -14,12 +14,22 @@ namespace textinput {
|
||||
class TiEventHandler : public gui::EventHandler {
|
||||
public:
|
||||
typedef struct Input {
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISIGNWINDOW_IMPLEMENTATION) || defined(MYTILETTERFORM_IMPLEMENTATION)
|
||||
u32 controller;
|
||||
f32 x;
|
||||
f32 y;
|
||||
u32 trigger;
|
||||
u32 hold;
|
||||
u32 release;
|
||||
u8 remaining[8];
|
||||
#else
|
||||
// todo
|
||||
u32 field_0x00; // 0x00
|
||||
u8 dummy[8];
|
||||
u32 field_0x0C; // 0x0C
|
||||
u32 field_0x10; // 0x10
|
||||
u8 dummy2[12];
|
||||
#endif
|
||||
} Input;
|
||||
|
||||
virtual void onEvent(gui::GUIComponent& comp, u32 event, void* data); // 0x0C
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#ifndef TEXTINPUT_PC_KEYBOARD_H
|
||||
#define TEXTINPUT_PC_KEYBOARD_H
|
||||
|
||||
#ifdef TI_PC_KEYBOARD_IMPLEMENTATION
|
||||
#if defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISIGNWINDOW_IMPLEMENTATION)
|
||||
#include "tiPcKeyboardImpl.h"
|
||||
#else
|
||||
|
||||
#include "tiNw4rManager.h"
|
||||
#include "tiTextInputBase.h"
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION)
|
||||
#include "tiKeyboard.h"
|
||||
#endif
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace textinput {
|
||||
|
||||
namespace pctype {
|
||||
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION)
|
||||
class UIObj {
|
||||
public:
|
||||
class Listener {
|
||||
@@ -29,7 +29,7 @@ namespace textinput {
|
||||
#endif
|
||||
|
||||
// TODO
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION)
|
||||
class Base : public textinput::keyboard::KeyboardBase {
|
||||
#else
|
||||
class Base : public CommandSender {
|
||||
@@ -37,6 +37,10 @@ namespace textinput {
|
||||
public:
|
||||
enum TranslateMode {
|
||||
TM_00,
|
||||
#ifdef TIINPUTFORM_IMPLEMENTATION
|
||||
TM_Kana,
|
||||
TM_Roman,
|
||||
#endif
|
||||
};
|
||||
|
||||
enum InputType {
|
||||
@@ -47,7 +51,7 @@ namespace textinput {
|
||||
IT_04,
|
||||
};
|
||||
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION)
|
||||
enum InputMode {
|
||||
IM_00,
|
||||
IM_01,
|
||||
@@ -126,7 +130,7 @@ namespace textinput {
|
||||
virtual void updateFixMode();
|
||||
#endif
|
||||
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION)
|
||||
private:
|
||||
u8 mKeyboardInputFlags[8];
|
||||
const void* mpKeyStateTable;
|
||||
@@ -136,6 +140,9 @@ namespace textinput {
|
||||
u32 mCurrentInputType;
|
||||
u32 mInputState;
|
||||
const void* mpLanguageData;
|
||||
#ifdef TIINPUTFORM_IMPLEMENTATION
|
||||
MEMAllocator* mpAllocator;
|
||||
#endif
|
||||
bool mbOnlyQwerty;
|
||||
bool mbLanguageKeyActive;
|
||||
u16 mKeyboardFlags;
|
||||
@@ -143,6 +150,10 @@ namespace textinput {
|
||||
void* mpCurrentKeyState;
|
||||
|
||||
public:
|
||||
#ifdef TIINPUTFORM_IMPLEMENTATION
|
||||
bool isQwertyOnly() const { return mbOnlyQwerty; }
|
||||
bool isLanguageKeyActive() const { return mbLanguageKeyActive; }
|
||||
#endif
|
||||
u32 getTranslateModeForMemo() const { return mTranslateMode; }
|
||||
u32 getABCInputModeForMemo() const { return mABCInputMode; }
|
||||
u32 getAIUInputModeForMemo() const { return mAIUInputMode; }
|
||||
@@ -151,14 +162,14 @@ namespace textinput {
|
||||
|
||||
// TODO
|
||||
class LayoutByNW4R : public Base, public nw4rmanager::Layout
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION)
|
||||
, public UIObj::Listener
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
// TODO - ...
|
||||
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION)
|
||||
virtual void draw();
|
||||
virtual void calc();
|
||||
virtual void setPredictLanguageDialog(void*);
|
||||
@@ -171,7 +182,15 @@ namespace textinput {
|
||||
|
||||
void onPressedShift(bool shift);
|
||||
void onReleasedShift();
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
#ifdef TIINPUTFORM_IMPLEMENTATION
|
||||
bool hasLineFeedButton() const { return mbLineFeedButton; }
|
||||
private:
|
||||
void* mpPredictLanguageDialog;
|
||||
void* mpSignWindow;
|
||||
bool mbLineFeedButton;
|
||||
public:
|
||||
#endif
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION)
|
||||
virtual bool updateInput(int chan, f32 x, f32 y, u32 trig, u32 hold, u32 release, void* data) override;
|
||||
virtual bool updateInput(input::HKBManager& hkbManager) override;
|
||||
#endif
|
||||
|
||||
@@ -17,6 +17,62 @@ namespace textinput {
|
||||
}
|
||||
namespace keyboard {
|
||||
namespace signwindow {
|
||||
#ifndef TISIGNWINDOW_IMPLEMENTATION
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
struct LanguageDependencyData;
|
||||
class Base : public KeyboardBase {
|
||||
public:
|
||||
Base(Manager* manager) : mpAllocator(NULL), mpManager(manager) {}
|
||||
virtual ~Base();
|
||||
virtual void create(MEMAllocator* allocator);
|
||||
virtual void init();
|
||||
virtual int getType();
|
||||
virtual void setLanguage(Language language);
|
||||
virtual bool isLocked();
|
||||
virtual void setPage(u8 page);
|
||||
virtual u8 getPage();
|
||||
virtual void movePrevSignPage();
|
||||
virtual void moveNextSignPage();
|
||||
virtual void close();
|
||||
private:
|
||||
u32 mInputState;
|
||||
const LanguageDependencyData* mpLanguageData;
|
||||
MEMAllocator* mpAllocator;
|
||||
Manager* mpManager;
|
||||
};
|
||||
class EventHandler;
|
||||
class LayoutByNW4R : public Base, public nw4rmanager::Layout, public nw4rmanager::AnmObserver {
|
||||
public:
|
||||
LayoutByNW4R(Manager* manager, nw4r::lyt::MultiArcResourceAccessor* accessor, EventObserver* observer, const char* layoutName)
|
||||
: Base(manager), nw4rmanager::Layout(accessor, layoutName, observer), mbActive(false), mbInput(false), mpEventHandler(NULL), mpCaller(NULL) {}
|
||||
virtual ~LayoutByNW4R();
|
||||
virtual void create(MEMAllocator* allocator);
|
||||
virtual void init();
|
||||
virtual void onKey(u32 event, void* data);
|
||||
virtual void movePrevSignPage();
|
||||
virtual void moveNextSignPage();
|
||||
virtual void close();
|
||||
virtual void draw();
|
||||
virtual void open(KeyboardBase* keyboard, bool repeat);
|
||||
virtual bool isActive();
|
||||
virtual void onChangeAnmState(AnmEvent event, nw4rmanager::AnmPane* pane, nw4rmanager::Anim* animation);
|
||||
virtual bool updateInput(int chan, f32 x, f32 y, u32 trig, u32 hold, u32 release, void* data);
|
||||
virtual bool updateInput(input::HKBManager& hkb);
|
||||
virtual void throwReleaseForAll();
|
||||
virtual void resetAnmSignWindow();
|
||||
virtual void setSignKeyTop(u16 first, u16 count);
|
||||
virtual void setPageNumber(u16 page);
|
||||
virtual void endToClose();
|
||||
virtual void startToInput();
|
||||
virtual void movePrevSignWindow();
|
||||
virtual void moveNextSignWindow();
|
||||
private:
|
||||
bool mbActive;
|
||||
bool mbInput;
|
||||
EventHandler* mpEventHandler;
|
||||
KeyboardBase* mpCaller;
|
||||
};
|
||||
#else
|
||||
class Base : public KeyboardBase {
|
||||
public:
|
||||
virtual bool isLocked();
|
||||
@@ -32,7 +88,10 @@ namespace textinput {
|
||||
virtual void open(KeyboardBase* keyboard, bool repeat);
|
||||
virtual bool isActive();
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace pctype {
|
||||
|
||||
struct GridKey {
|
||||
@@ -94,8 +153,10 @@ namespace textinput {
|
||||
void refresh_();
|
||||
void refreshText(nw4r::lyt::Pane* root);
|
||||
void setABCFlag(u32 flags);
|
||||
u32 getABCFlag() const { return abcFlags & ~15; }
|
||||
u32 getABCMode() const { return abcFlags & 15; }
|
||||
wchar_t getWCCode(u32 index);
|
||||
wchar_t getWCCode(char* paneName);
|
||||
wchar_t getWCCode(char* paneName) NO_INLINE;
|
||||
void setABCMode(u32 mode) {
|
||||
if ((abcFlags & 15) != mode) {
|
||||
abcFlags = (abcFlags & ~15) | (mode & 15);
|
||||
@@ -115,9 +176,22 @@ namespace textinput {
|
||||
const LanguageData* data;
|
||||
Base* owner;
|
||||
};
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
Base(Manager* manager) {
|
||||
mKeyState.abcFlags = 0;
|
||||
mKeyState.inputType = 0;
|
||||
mKeyState.aiuFlags = 0;
|
||||
mKeyState.language = USA;
|
||||
mKeyState.data = NULL;
|
||||
mKeyState.owner = this;
|
||||
mpAllocator = NULL;
|
||||
mbOnlyQwerty = false;
|
||||
mpManager = manager;
|
||||
}
|
||||
#endif
|
||||
virtual ~Base();
|
||||
virtual void create(MEMAllocator* allocator);
|
||||
virtual void init();
|
||||
virtual inline void init();
|
||||
virtual void updateFromReceiver(u32 command, void* data);
|
||||
virtual void onKey(u32 event, void* data);
|
||||
virtual int getType();
|
||||
@@ -159,46 +233,15 @@ namespace textinput {
|
||||
};
|
||||
|
||||
class LayoutByNW4R;
|
||||
class AnmPane : public nw4rmanager::AnmPane {
|
||||
class AnmPane;
|
||||
class EventHandler : public nw4rmanager::TiEventHandler {
|
||||
public:
|
||||
AnmPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer) : nw4rmanager::AnmPane(pane, observer), mAnimation(0) {}
|
||||
virtual void init();
|
||||
virtual void changeAnimation(u32 animation);
|
||||
virtual ~AnmPane();
|
||||
virtual int getState() const { return mAnimation; }
|
||||
virtual int getKeyType() const { return mKeyType; }
|
||||
|
||||
protected:
|
||||
int mAnimation;
|
||||
int mKeyType;
|
||||
};
|
||||
class NormalButtonAnmPane : public AnmPane {
|
||||
public:
|
||||
NormalButtonAnmPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer) : AnmPane(pane, observer) { mKeyType = 0; }
|
||||
virtual ~NormalButtonAnmPane();
|
||||
virtual void onAnmEvent(AnmPaneEvent event);
|
||||
};
|
||||
class ShiftCapsAnmPane : public AnmPane {
|
||||
public:
|
||||
ShiftCapsAnmPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer) : AnmPane(pane, observer), mbOn(false) { mKeyType = 1; }
|
||||
virtual ~ShiftCapsAnmPane();
|
||||
virtual void onAnmEvent(AnmPaneEvent event);
|
||||
bool isFocused() const;
|
||||
EventHandler(LayoutByNW4R* layout) : mpKeyboard(layout) {}
|
||||
virtual ~EventHandler();
|
||||
virtual void onTiEvent(gui::PaneComponent* component, u32 event, Input* input);
|
||||
|
||||
private:
|
||||
bool mbOn;
|
||||
};
|
||||
class ToggleButtonAnmPane : public AnmPane {
|
||||
public:
|
||||
ToggleButtonAnmPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer) : AnmPane(pane, observer) { mKeyType = 2; }
|
||||
virtual ~ToggleButtonAnmPane();
|
||||
virtual void onAnmEvent(AnmPaneEvent event);
|
||||
};
|
||||
class OnOffButtonAnmPane : public AnmPane {
|
||||
public:
|
||||
OnOffButtonAnmPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer) : AnmPane(pane, observer) { mKeyType = 3; }
|
||||
virtual ~OnOffButtonAnmPane();
|
||||
virtual void onAnmEvent(AnmPaneEvent event);
|
||||
LayoutByNW4R* mpKeyboard;
|
||||
};
|
||||
class UIObj : public gui::EventHandler {
|
||||
public:
|
||||
@@ -219,6 +262,8 @@ namespace textinput {
|
||||
class UIModifierButton : public UIObj {
|
||||
public:
|
||||
UIModifierButton(u32 id, LayoutByNW4R* layout, Listener* listener);
|
||||
inline void Create(nw4rmanager::Layout* layout, const char* pane, const char* bounding);
|
||||
inline void SetState(bool enabled, u32 inactiveAnimation);
|
||||
virtual ~UIModifierButton();
|
||||
virtual void onGUIEvent(gui::PaneComponent& component, u32 event, nw4rmanager::TiEventHandler::Input* input);
|
||||
gui::PaneComponent* mpPaneComponent;
|
||||
@@ -244,17 +289,13 @@ namespace textinput {
|
||||
GXTexObj mEnglishTexture;
|
||||
GXTexObj mHangulTexture;
|
||||
};
|
||||
class EventHandler : public nw4rmanager::TiEventHandler {
|
||||
public:
|
||||
EventHandler(LayoutByNW4R* layout) : mpKeyboard(layout) {}
|
||||
virtual ~EventHandler();
|
||||
virtual void onTiEvent(gui::PaneComponent* component, u32 event, Input* input);
|
||||
|
||||
private:
|
||||
LayoutByNW4R* mpKeyboard;
|
||||
};
|
||||
class LayoutByNW4R : public Base, public nw4rmanager::Layout, public UIObj::Listener {
|
||||
public:
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
LayoutByNW4R(Manager* manager, nw4r::lyt::MultiArcResourceAccessor* accessor, EventObserver* observer, const char* layoutName)
|
||||
: Base(manager), nw4rmanager::Layout(accessor, layoutName, observer), mpKeyboardEventHandler(NULL),
|
||||
mShiftButton(1, this, this), mCapsButton(0, this, this), mModePanel(2, this, this) {}
|
||||
#endif
|
||||
virtual ~LayoutByNW4R();
|
||||
virtual void create(MEMAllocator* allocator);
|
||||
virtual void init();
|
||||
@@ -305,6 +346,48 @@ namespace textinput {
|
||||
UIModePanel mModePanel;
|
||||
};
|
||||
|
||||
class AnmPane : public nw4rmanager::AnmPane {
|
||||
public:
|
||||
AnmPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer) : nw4rmanager::AnmPane(pane, observer), mAnimation(0) {}
|
||||
virtual void init();
|
||||
virtual void changeAnimation(u32 animation);
|
||||
virtual ~AnmPane();
|
||||
virtual int getState() const { return mAnimation; }
|
||||
virtual int getKeyType() const { return mKeyType; }
|
||||
|
||||
protected:
|
||||
int mAnimation;
|
||||
int mKeyType;
|
||||
};
|
||||
class NormalButtonAnmPane : public AnmPane {
|
||||
public:
|
||||
NormalButtonAnmPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer) : AnmPane(pane, observer) { mKeyType = 0; }
|
||||
virtual ~NormalButtonAnmPane();
|
||||
virtual void onAnmEvent(AnmPaneEvent event);
|
||||
};
|
||||
class ShiftCapsAnmPane : public AnmPane {
|
||||
public:
|
||||
ShiftCapsAnmPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer) : AnmPane(pane, observer), mbOn(false) { mKeyType = 1; }
|
||||
virtual ~ShiftCapsAnmPane();
|
||||
virtual void onAnmEvent(AnmPaneEvent event);
|
||||
bool isFocused() const;
|
||||
|
||||
private:
|
||||
bool mbOn;
|
||||
};
|
||||
class ToggleButtonAnmPane : public AnmPane {
|
||||
public:
|
||||
ToggleButtonAnmPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer) : AnmPane(pane, observer) { mKeyType = 2; }
|
||||
virtual ~ToggleButtonAnmPane();
|
||||
virtual void onAnmEvent(AnmPaneEvent event);
|
||||
};
|
||||
class OnOffButtonAnmPane : public AnmPane {
|
||||
public:
|
||||
OnOffButtonAnmPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer) : AnmPane(pane, observer) { mKeyType = 3; }
|
||||
virtual ~OnOffButtonAnmPane();
|
||||
virtual void onAnmEvent(AnmPaneEvent event);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,11 +14,17 @@ namespace textinput {
|
||||
|
||||
class Base : public CommandSender {
|
||||
public:
|
||||
#ifdef TI_PREDICTLANG_SAMPLE_CLASS
|
||||
#if defined(TI_PREDICTLANG_SAMPLE_CLASS) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
Base(Manager* manager) : mePredictMode(inputform::Base::PM_USEn), mpAllocator(NULL), mpManager(manager) {}
|
||||
#endif
|
||||
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
virtual ~Base();
|
||||
virtual void init();
|
||||
virtual void create(MEMAllocator* allocator) override;
|
||||
#else
|
||||
virtual void create(MEMAllocator* allocator) override { mpAllocator = allocator; }
|
||||
#endif
|
||||
virtual void setPredictMode(inputform::Base::PredictMode mode) { mePredictMode = mode; }
|
||||
|
||||
protected:
|
||||
@@ -32,7 +38,11 @@ namespace textinput {
|
||||
|
||||
class LayoutByNW4R : public Base, public nw4rmanager::Layout, public nw4rmanager::AnmObserver {
|
||||
public:
|
||||
#ifdef TI_PREDICTLANG_SAMPLE_CLASS
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
LayoutByNW4R(Manager* manager, nw4r::lyt::MultiArcResourceAccessor* resAccessor, EventObserver* observer, const char* layoutName)
|
||||
: Base(manager), nw4rmanager::Layout(resAccessor, layoutName, observer), mbActive(false), mbInput(false),
|
||||
mpEventHandler(NULL), meDestination(DST_US), mpCaller(NULL) {}
|
||||
#elif defined(TI_PREDICTLANG_SAMPLE_CLASS)
|
||||
LayoutByNW4R(Manager* manager, nw4r::lyt::MultiArcResourceAccessor* resAccessor, EventObserver* observer)
|
||||
: Base(manager), nw4rmanager::Layout(resAccessor, "fs_prdicSelWidw_a.brlyt", observer), mbActive(false), mbInput(false),
|
||||
mpEventHandler(NULL), meDestination(DST_US), mpCaller(NULL) {}
|
||||
@@ -68,12 +78,21 @@ namespace textinput {
|
||||
keyboard::KeyboardBase* mpCaller; // 0xD4
|
||||
};
|
||||
|
||||
#ifdef TI_PREDICTLANG_SAMPLE_CLASS
|
||||
#if defined(TI_PREDICTLANG_SAMPLE_CLASS) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
class Sample : public LayoutByNW4R {
|
||||
public:
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
Sample(Manager* manager, nw4r::lyt::MultiArcResourceAccessor* resAccessor, EventObserver* observer, const char* layoutName)
|
||||
: LayoutByNW4R(manager, resAccessor, observer, layoutName) {}
|
||||
#else
|
||||
Sample(Manager* manager, nw4r::lyt::MultiArcResourceAccessor* resAccessor, EventObserver* observer)
|
||||
: LayoutByNW4R(manager, resAccessor, observer) {}
|
||||
#endif
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
virtual ~Sample();
|
||||
#else
|
||||
virtual ~Sample() {}
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
134
include/keyboard/tiSignWindow.h
Normal file
134
include/keyboard/tiSignWindow.h
Normal file
@@ -0,0 +1,134 @@
|
||||
#ifndef TEXTINPUT_SIGN_WINDOW_H
|
||||
#define TEXTINPUT_SIGN_WINDOW_H
|
||||
|
||||
#include "tiKeyboard.h"
|
||||
#include "tiNw4rManager.h"
|
||||
#include "tiSwData.h"
|
||||
|
||||
namespace textinput {
|
||||
class Manager;
|
||||
namespace keyboard {
|
||||
|
||||
namespace signwindow {
|
||||
|
||||
struct LanguageDependency {
|
||||
u8 count;
|
||||
const PaneNameToCharCodeInSignMode* keys;
|
||||
};
|
||||
|
||||
class Base : public KeyboardBase {
|
||||
public:
|
||||
virtual ~Base();
|
||||
virtual void create(MEMAllocator*) override;
|
||||
virtual void init() override;
|
||||
virtual void onKey(u32, void*) override;
|
||||
virtual bool isLocked();
|
||||
virtual void setPage(u8);
|
||||
virtual u8 getPage();
|
||||
virtual void movePrevSignPage();
|
||||
virtual void moveNextSignPage();
|
||||
virtual void close();
|
||||
virtual int getType() override;
|
||||
virtual void setLanguage(Language) override;
|
||||
|
||||
protected:
|
||||
u8 mInputFlags;
|
||||
bool mbLocked;
|
||||
bool mbRepeat;
|
||||
u8 muPage;
|
||||
const LanguageDependency* mpLanguageDependency;
|
||||
MEMAllocator* mpAllocator;
|
||||
Manager* mpManager;
|
||||
};
|
||||
|
||||
class EventHandler;
|
||||
|
||||
class LayoutByNW4R : public Base, public nw4rmanager::Layout, public nw4rmanager::AnmObserver {
|
||||
public:
|
||||
virtual ~LayoutByNW4R();
|
||||
virtual void create(MEMAllocator*) override;
|
||||
virtual void init() override;
|
||||
virtual void onKey(u32, void*) override;
|
||||
virtual void movePrevSignPage() override;
|
||||
virtual void moveNextSignPage() override;
|
||||
virtual void close() override;
|
||||
virtual void draw() override;
|
||||
virtual void open(KeyboardBase*, bool);
|
||||
virtual bool isActive();
|
||||
virtual void onChangeAnmState(AnmEvent, nw4rmanager::AnmPane*, nw4rmanager::Anim*) override;
|
||||
virtual bool updateInput(int, f32, f32, u32, u32, u32, void*) override;
|
||||
virtual bool updateInput(input::HKBManager&) override;
|
||||
virtual void throwReleaseForAll();
|
||||
virtual void resetAnmSignWindow();
|
||||
virtual void setSignKeyTop(u16, u16);
|
||||
virtual void setPageNumber(u16);
|
||||
virtual void endToClose();
|
||||
virtual void startToInput();
|
||||
virtual void movePrevSignWindow();
|
||||
virtual void moveNextSignWindow();
|
||||
|
||||
bool mbActive;
|
||||
bool mbInput;
|
||||
EventHandler* mpEventHandler;
|
||||
KeyboardBase* mpKeyboard;
|
||||
};
|
||||
|
||||
class Sample : public LayoutByNW4R {
|
||||
public:
|
||||
virtual ~Sample();
|
||||
};
|
||||
|
||||
class EventHandler : public nw4rmanager::TiEventHandler {
|
||||
public:
|
||||
explicit EventHandler(LayoutByNW4R* layout) : mpLayoutByNW4R(layout) {}
|
||||
virtual ~EventHandler();
|
||||
virtual void onTiEvent(gui::PaneComponent*, u32, Input*) override;
|
||||
LayoutByNW4R* mpLayoutByNW4R;
|
||||
};
|
||||
|
||||
class AnmPane : public nw4rmanager::AnmPane {
|
||||
public:
|
||||
AnmPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer)
|
||||
: nw4rmanager::AnmPane(pane, observer), muAnimation(0) {}
|
||||
inline virtual ~AnmPane();
|
||||
virtual void init() override;
|
||||
virtual void changeAnimation(u32) override;
|
||||
virtual u32 getKeyType() const;
|
||||
|
||||
protected:
|
||||
s32 muAnimation;
|
||||
u32 muKeyType;
|
||||
};
|
||||
|
||||
class CellPhoneSignAllAnmPane : public AnmPane {
|
||||
public:
|
||||
CellPhoneSignAllAnmPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer)
|
||||
: AnmPane(pane, observer) { muKeyType = 0; }
|
||||
virtual ~CellPhoneSignAllAnmPane();
|
||||
virtual void init() override;
|
||||
virtual void onAnmEvent(AnmPaneEvent) override;
|
||||
};
|
||||
|
||||
class CellPhoneSignScrollAnmPane : public AnmPane {
|
||||
public:
|
||||
CellPhoneSignScrollAnmPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer)
|
||||
: AnmPane(pane, observer) { muKeyType = 1; }
|
||||
virtual ~CellPhoneSignScrollAnmPane();
|
||||
virtual void init() override;
|
||||
virtual void onAnmEvent(AnmPaneEvent) override;
|
||||
};
|
||||
|
||||
class CellPhoneSignButtonPane : public AnmPane {
|
||||
public:
|
||||
CellPhoneSignButtonPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer)
|
||||
: AnmPane(pane, observer) { muKeyType = 2; }
|
||||
virtual ~CellPhoneSignButtonPane();
|
||||
virtual void init() override;
|
||||
virtual void onAnmEvent(AnmPaneEvent) override;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -3,6 +3,9 @@
|
||||
|
||||
#include <revolution/types.h>
|
||||
#include <revolution/mem/allocator.h>
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISTRING_IMPLEMENTATION) || defined(TIZISTRING_IMPLEMENTATION)
|
||||
#include <revolution/kpr.h>
|
||||
#endif
|
||||
|
||||
namespace textinput {
|
||||
namespace tistring {
|
||||
@@ -36,12 +39,20 @@ namespace textinput {
|
||||
virtual wchar_t* getWCString() const { return mpszString; }
|
||||
|
||||
virtual void setCandidate(wchar_t candidate) { mwcCandidate = candidate; }
|
||||
#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; }
|
||||
#endif
|
||||
virtual bool hasCandidate() const;
|
||||
|
||||
virtual wchar_t getLastWChar();
|
||||
|
||||
#if defined(TISTRING_IMPLEMENTATION) || defined(TIZISTRING_IMPLEMENTATION)
|
||||
protected:
|
||||
#else
|
||||
private:
|
||||
#endif
|
||||
u16 muMaxLength; // 0x04
|
||||
u16 muLength; // 0x06
|
||||
|
||||
@@ -54,14 +65,71 @@ namespace textinput {
|
||||
};
|
||||
|
||||
class KanaStream {
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISTRING_IMPLEMENTATION) || defined(TIZISTRING_IMPLEMENTATION)
|
||||
public:
|
||||
KPRQueue mQueue;
|
||||
wchar_t mPending;
|
||||
wchar_t mOutput[5];
|
||||
#else
|
||||
private:
|
||||
u8 field_0x00[0x24];
|
||||
#endif
|
||||
};
|
||||
|
||||
class Decolated : public StringBase {
|
||||
public:
|
||||
#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) || defined(TISTRING_IMPLEMENTATION) || defined(TIZISTRING_IMPLEMENTATION)
|
||||
virtual ~Decolated();
|
||||
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);
|
||||
virtual void inputChar(wchar_t ch);
|
||||
virtual void inputString(const wchar_t* string);
|
||||
virtual void deleteChar();
|
||||
virtual void backSpace();
|
||||
virtual void confirm(const wchar_t* string);
|
||||
virtual bool moveCursorRight();
|
||||
virtual bool moveCursorLeft();
|
||||
virtual void setCursorPos(u32 pos);
|
||||
virtual void onSustain();
|
||||
virtual void offSustain();
|
||||
virtual bool isOnSustain();
|
||||
virtual u32 getCursorPos() const;
|
||||
virtual void getCursorPos(u32* start, u32* end);
|
||||
virtual bool canBackSpace();
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISTRING_IMPLEMENTATION) || defined(TIZISTRING_IMPLEMENTATION)
|
||||
virtual bool deleteForward();
|
||||
#else
|
||||
virtual void deleteForward();
|
||||
#endif
|
||||
virtual void getSelected(u32& start, u32& end);
|
||||
virtual wchar_t getWCharAtCursor();
|
||||
virtual void replaceAtCursor(wchar_t ch);
|
||||
virtual bool isDakuten();
|
||||
virtual void converDakuten();
|
||||
virtual bool isHandaku();
|
||||
virtual void converHandaku();
|
||||
virtual void convertAll();
|
||||
virtual bool isSmall();
|
||||
virtual void converSmall();
|
||||
virtual bool atTheBeginningOfASentence();
|
||||
virtual void initKanaConverter();
|
||||
virtual wchar_t* getKanaBuffer();
|
||||
virtual bool isKanaFix() const;
|
||||
virtual void confirmKana();
|
||||
virtual void clearKana();
|
||||
virtual void EnableKSXFilter(bool enable);
|
||||
#else
|
||||
virtual void inputChar();
|
||||
virtual void inputString();
|
||||
virtual void deleteChar();
|
||||
@@ -95,15 +163,84 @@ namespace textinput {
|
||||
virtual void clearKana();
|
||||
virtual void EnableKSXFilter();
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(TISTRING_IMPLEMENTATION) || defined(TIZISTRING_IMPLEMENTATION)
|
||||
protected:
|
||||
#else
|
||||
private:
|
||||
#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
|
||||
u8 field_0x20; // 0x20
|
||||
u32 field_0x24; // 0x24
|
||||
#endif
|
||||
KanaStream mKanaStream; // 0x28
|
||||
};
|
||||
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISTRING_IMPLEMENTATION) || defined(TIZISTRING_IMPLEMENTATION)
|
||||
class WithAtok : public Decolated {
|
||||
public:
|
||||
WithAtok(u16 maxLength) : Decolated(maxLength) {}
|
||||
virtual ~WithAtok();
|
||||
virtual void pushBack(wchar_t ch);
|
||||
virtual void popBack();
|
||||
virtual void inputChar(wchar_t ch);
|
||||
virtual void backSpace();
|
||||
virtual void confirm(const wchar_t* string);
|
||||
virtual bool moveCursorRight();
|
||||
virtual bool moveCursorLeft();
|
||||
virtual void getCursorPos(u32* start, u32* end);
|
||||
struct DrawInfo {
|
||||
const wchar_t* string;
|
||||
u32 start;
|
||||
u32 end;
|
||||
u32 selectedStart;
|
||||
u32 selectedEnd;
|
||||
};
|
||||
virtual bool isFix();
|
||||
virtual void setFix(bool fix);
|
||||
virtual void initConverting();
|
||||
virtual bool isConverting();
|
||||
virtual wchar_t* getConfirmedWCString() const;
|
||||
virtual int getCurrentNumPredicted();
|
||||
virtual void getPredicted(int index, wchar_t* string);
|
||||
virtual void commitPredicted(int index);
|
||||
virtual void setSelectedCandidate(s32 index);
|
||||
virtual bool isCandidateSelected();
|
||||
virtual s32 getSelectedCandidate();
|
||||
virtual void init();
|
||||
virtual void setInputting(wchar_t ch);
|
||||
virtual void getDrawString(DrawInfo& info);
|
||||
virtual void openDictionary(void* atok, int atokSize, void* apot, int apotSize, void* nintendo, int nintendoSize);
|
||||
virtual void closeDictionary();
|
||||
virtual bool hasConfirmedString();
|
||||
virtual void enableConfirmedString(bool enable);
|
||||
virtual void startConverting();
|
||||
virtual bool isDictionaryOpened();
|
||||
virtual void changeKanaMode(bool kana);
|
||||
virtual wchar_t getInputStringLength();
|
||||
virtual void resetRelation();
|
||||
virtual void setFixMode(bool fixed);
|
||||
virtual void setFixPrediction(int count, const char** predictions);
|
||||
virtual void setDefaultPrediction(int count, const char** predictions);
|
||||
virtual s16 getSelectedConverting();
|
||||
virtual s32 getFixedPredictionNum();
|
||||
};
|
||||
#else
|
||||
class WithAtok : public StringBase {};
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,13 @@
|
||||
|
||||
#include <nw4r/ut/CharWriter.h>
|
||||
#include <nw4r/ut/Rect.h>
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TITEXTDRAWER_IMPLEMENTATION) || defined(MYTILETTERFORM_IMPLEMENTATION)
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
namespace textinput {
|
||||
namespace textdrawer {
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(MYTIINPUTFORM_IMPLEMENTATION)
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(MYTIINPUTFORM_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TITEXTDRAWER_IMPLEMENTATION) || defined(MYTILETTERFORM_IMPLEMENTATION)
|
||||
class Base : public nw4r::ut::CharWriter {
|
||||
#else
|
||||
class Base : nw4r::ut::CharWriter {
|
||||
@@ -31,9 +34,23 @@ namespace textinput {
|
||||
} CursorPos;
|
||||
|
||||
typedef struct DrawInfo {
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TITEXTDRAWER_IMPLEMENTATION) || defined(MYTILETTERFORM_IMPLEMENTATION)
|
||||
nw4r::ut::Rect rect;
|
||||
wchar_t character;
|
||||
#else
|
||||
u8 unk_0x00[32];
|
||||
#endif
|
||||
} DrawInfo;
|
||||
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
Base() : mpDrawAllocator(NULL), mfViewX(0.0f), mfViewY(0.0f), mfViewWidth(0.0f), mfViewHeight(0.0f),
|
||||
mfVIWidth(640.0f), mbAspect4x3(false), mbDrawClipped(false), muLine(0), mfLineSpacing(0.0f),
|
||||
mfCharacterSpacing(0.0f), mfFontWidth(0.0f), mfFontHeight(0.0f), mfModifyStartY(0.0f), mfMinScrollY(0.0f),
|
||||
muDrawStartPos(0), muDrawEndPos(65535), mbSecretMode(false), muDrawModifyStartLine(0), muDrawModifyEndLine(0),
|
||||
muDrawModifyStartPos(0), muDrawModifyEndPos(0), muCachedStartPos(0), muCachedEndPos(0), mbDrawCache(false),
|
||||
mfCachedCursorX(0.0f), mfCachedCursorY(0.0f), mfDrawScrollY(0.0f), muCachedCursorPosition(0),
|
||||
mbCursorCache(false), mbMaintainCursorCache(true) { memset(&mCachedCursor, 0, sizeof(mCachedCursor)); }
|
||||
#endif
|
||||
virtual void create(MEMAllocator* allocator);
|
||||
virtual void draw(CursorPos* cursorPos);
|
||||
virtual void draw();
|
||||
@@ -77,26 +94,115 @@ namespace textinput {
|
||||
virtual u32 getEndPos() const;
|
||||
|
||||
// todo
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TITEXTDRAWER_IMPLEMENTATION) || defined(MYTILETTERFORM_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
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TITEXTDRAWER_IMPLEMENTATION) || defined(MYTILETTERFORM_IMPLEMENTATION)
|
||||
virtual bool isEnableCursorCache() const;
|
||||
#else
|
||||
virtual void isEnableCursorCache();
|
||||
#endif
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TITEXTDRAWER_IMPLEMENTATION) || defined(MYTILETTERFORM_IMPLEMENTATION)
|
||||
virtual u32 getDrawModifyStartLine() const;
|
||||
virtual u32 getDrawModifyEndLine() const;
|
||||
#else
|
||||
virtual void getDrawModifyStartLine();
|
||||
virtual void getDrawModifyEndLine();
|
||||
#endif
|
||||
virtual u32 getDrawCacheStartPos() const;
|
||||
virtual void dirtyDrawCache();
|
||||
virtual void dirtyCursorCache();
|
||||
|
||||
#ifdef TITEXTDRAWER_IMPLEMENTATION
|
||||
protected:
|
||||
const wchar_t* mpDrawString;
|
||||
ViewPort mSavedViewport;
|
||||
f32 mSavedProjection[7];
|
||||
nw4r::ut::Rect mProjectionRect;
|
||||
f32 mfVIWidth;
|
||||
bool mbAspect4x3;
|
||||
bool mbDrawClipped;
|
||||
s32 muLine;
|
||||
f32 mfLineSpacing;
|
||||
f32 mfCharacterSpacing;
|
||||
f32 mfFontWidth;
|
||||
f32 mfFontHeight;
|
||||
f32 mfModifyStartY;
|
||||
f32 mfMinScrollY;
|
||||
u32 muDrawStartPos;
|
||||
u32 muDrawEndPos;
|
||||
u32 muDrawCacheStartPos;
|
||||
bool mbSecretMode;
|
||||
s32 muDrawModifyStartLine;
|
||||
s32 muDrawModifyEndLine;
|
||||
s32 muDrawModifyStartPos;
|
||||
s32 muDrawModifyEndPos;
|
||||
u32 muCachedStartPos;
|
||||
u32 muCachedEndPos;
|
||||
bool mbDrawCache;
|
||||
f32 mfCachedCursorX;
|
||||
f32 mfCachedCursorY;
|
||||
f32 mfDrawScrollY;
|
||||
s32 mnCachedCursorLine;
|
||||
CursorPos mCachedCursor;
|
||||
bool mbCursorCache;
|
||||
bool mbMaintainCursorCache;
|
||||
#else
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TITEXTDRAWER_IMPLEMENTATION) || defined(MYTILETTERFORM_IMPLEMENTATION)
|
||||
protected:
|
||||
MEMAllocator* mpDrawAllocator;
|
||||
u8 mDrawConfiguration[0x34];
|
||||
f32 mfViewX;
|
||||
f32 mfViewY;
|
||||
f32 mfViewWidth;
|
||||
f32 mfViewHeight;
|
||||
f32 mfVIWidth;
|
||||
bool mbAspect4x3;
|
||||
bool mbDrawClipped;
|
||||
u32 muLine;
|
||||
f32 mfLineSpacing;
|
||||
f32 mfCharacterSpacing;
|
||||
f32 mfFontWidth;
|
||||
f32 mfFontHeight;
|
||||
f32 mfModifyStartY;
|
||||
f32 mfMinScrollY;
|
||||
u32 muDrawStartPos;
|
||||
u32 muDrawEndPos;
|
||||
u32 muDrawCacheStartPos;
|
||||
#else
|
||||
private:
|
||||
u8 unk_0x50[0x78];
|
||||
#endif
|
||||
bool mbSecretMode; // 0xC8
|
||||
#ifdef MYTIINPUTFORM_IMPLEMENTATION
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TITEXTDRAWER_IMPLEMENTATION) || defined(MYTILETTERFORM_IMPLEMENTATION)
|
||||
u32 muDrawModifyStartLine;
|
||||
u32 muDrawModifyEndLine;
|
||||
u32 muDrawModifyStartPos;
|
||||
u32 muDrawModifyEndPos;
|
||||
u32 muCachedStartPos;
|
||||
u32 muCachedEndPos;
|
||||
bool mbDrawCache;
|
||||
f32 mfCachedCursorX;
|
||||
f32 mfCachedCursorY;
|
||||
f32 mfDrawScrollY;
|
||||
u32 muCachedCursorPosition;
|
||||
CursorPos mCachedCursor;
|
||||
bool mbCursorCache;
|
||||
bool mbMaintainCursorCache;
|
||||
#elif defined(MYTIINPUTFORM_IMPLEMENTATION)
|
||||
protected:
|
||||
u8 mDrawState[0x27];
|
||||
f32 mfDrawScrollY;
|
||||
u8 mDrawCacheState[0x14];
|
||||
#else
|
||||
u8 unk_0xCC[0x3C];
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
@@ -39,6 +39,10 @@ namespace textinput {
|
||||
f32 y; // 0x08
|
||||
} Scroll;
|
||||
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
enum HVKCode { HVK_None = 0 };
|
||||
#endif
|
||||
|
||||
class Base {
|
||||
public :
|
||||
virtual ~Base() {}
|
||||
@@ -50,7 +54,11 @@ namespace textinput {
|
||||
class CommandSender;
|
||||
class CommandReceiver : public Base {
|
||||
public:
|
||||
#ifdef MYTIINPUTFORM_IMPLEMENTATION
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
CommandReceiver() { clearSender(); }
|
||||
virtual ~CommandReceiver();
|
||||
#endif
|
||||
#if defined(MYTIINPUTFORM_IMPLEMENTATION) || defined(MYTILETTERFORM_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
struct Scroll {
|
||||
bool absY;
|
||||
f32 x;
|
||||
@@ -62,7 +70,7 @@ namespace textinput {
|
||||
INPUT_COMMAND_37 = 37,
|
||||
} INPUT_COMMAND;
|
||||
|
||||
#ifdef TI_PC_KEYBOARD_IMPLEMENTATION
|
||||
#if defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISIGNWINDOW_IMPLEMENTATION)
|
||||
struct ChangePredictMode { u32 mode; bool enabled; };
|
||||
#endif
|
||||
virtual void clearSender();
|
||||
@@ -78,7 +86,7 @@ namespace textinput {
|
||||
CommandSender() : mpCommandReceiver(NULL) {}
|
||||
|
||||
virtual void setCommandReceiver(CommandReceiver* cmdRecv);
|
||||
#ifdef TI_PC_KEYBOARD_IMPLEMENTATION
|
||||
#if defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
virtual void sendCommand(u32 command, void* data) {
|
||||
if (mpCommandReceiver != NULL) mpCommandReceiver->onCommand(static_cast<CommandReceiver::INPUT_COMMAND>(command), data);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace textinput {
|
||||
namespace toolbar {
|
||||
class Base {
|
||||
public:
|
||||
#ifdef TI_TOOLBAR_SAMPLE_CLASS
|
||||
#if defined(TI_TOOLBAR_SAMPLE_CLASS) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
Base(Manager* manager) : mQwerty(true), meLanguage(USA), mpAllocator(NULL), mpManager(manager) {}
|
||||
#endif
|
||||
|
||||
@@ -35,7 +35,11 @@ namespace textinput {
|
||||
|
||||
class LayoutByNW4R : public Base, public nw4rmanager::Layout {
|
||||
public:
|
||||
#ifdef TI_TOOLBAR_SAMPLE_CLASS
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
LayoutByNW4R(Manager* manager, nw4r::lyt::MultiArcResourceAccessor* resAccessor, EventObserver* observer, const char* layoutName)
|
||||
: Base(manager), nw4rmanager::Layout(resAccessor, layoutName, observer), mpEventHandler(NULL),
|
||||
mbIsEnableQwertyChg(false) {}
|
||||
#elif defined(TI_TOOLBAR_SAMPLE_CLASS)
|
||||
LayoutByNW4R(Manager* manager, nw4r::lyt::MultiArcResourceAccessor* resAccessor, EventObserver* observer)
|
||||
: Base(manager), nw4rmanager::Layout(resAccessor, "fs_VK_toolbar_a.brlyt", observer), mpEventHandler(NULL),
|
||||
mbIsEnableQwertyChg(false) {}
|
||||
@@ -117,12 +121,21 @@ namespace textinput {
|
||||
KeyType meKeyType; // 0x30
|
||||
};
|
||||
|
||||
#ifdef TI_TOOLBAR_SAMPLE_CLASS
|
||||
#if defined(TI_TOOLBAR_SAMPLE_CLASS) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
class Sample : public LayoutByNW4R {
|
||||
public:
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
Sample(Manager* manager, nw4r::lyt::MultiArcResourceAccessor* resAccessor, EventObserver* observer, const char* layoutName)
|
||||
: LayoutByNW4R(manager, resAccessor, observer, layoutName) {}
|
||||
#else
|
||||
Sample(Manager* manager, nw4r::lyt::MultiArcResourceAccessor* resAccessor, EventObserver* observer)
|
||||
: LayoutByNW4R(manager, resAccessor, observer) {}
|
||||
#endif
|
||||
#ifdef TIMANAGER_IMPLEMENTATION
|
||||
virtual ~Sample();
|
||||
#else
|
||||
virtual ~Sample() {}
|
||||
#endif
|
||||
};
|
||||
#else
|
||||
class Sample {};
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
|
||||
namespace textinput {
|
||||
namespace util {
|
||||
#ifdef TIINPUTFORM_IMPLEMENTATION
|
||||
wchar_t HankakuToZenkaku(wchar_t ch);
|
||||
#endif
|
||||
wchar_t toWLower(wchar_t ch);
|
||||
wchar_t toWUpper(wchar_t ch);
|
||||
|
||||
@@ -17,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);
|
||||
@@ -46,7 +55,11 @@ namespace textinput {
|
||||
public:
|
||||
Animation() : mfAnimationTime(0.0f), mbInAnimation(false), mbSE(false), mpAnimObserver(NULL) {}
|
||||
|
||||
virtual void startAnm(AnimObserver*, f32, f32, f32, void*); // 0x08
|
||||
#ifdef TIINPUTFORM_IMPLEMENTATION
|
||||
virtual void startAnm(f32 start, f32 end, f32 duration, AnimObserver* observer, void* data);
|
||||
#else
|
||||
virtual void startAnm(AnimObserver*, f32, f32, f32, void*);
|
||||
#endif // 0x08
|
||||
virtual void calc(); // 0x0C
|
||||
virtual f32 getValue(); // 0x10
|
||||
virtual bool isActive(); // 0x14
|
||||
|
||||
@@ -1,14 +1,159 @@
|
||||
#ifndef TEXTINPUT_ZI_STRING_H
|
||||
#define TEXTINPUT_ZI_STRING_H
|
||||
|
||||
#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(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 };
|
||||
enum LetterMode { LM_Lower, LM_Normal, LM_Upper };
|
||||
WithZi(u16 maxLength) : Decolated(maxLength), mbDictionaryOpen(false), mbContextChanged(false),
|
||||
mCurrentWordLength(0), mpDictionaries(NULL), mpDictionaryWork(NULL), mInputLength(0),
|
||||
mCandidateCount(0), mOemDictionaryId(0), mDictionaryLanguage(0xff), mSelectedCandidate(0),
|
||||
mPredictLanguage(0), mLetterMode(2), mpHoldingKey(NULL), mbKoreanPartialConfirm(false) {}
|
||||
virtual ~WithZi();
|
||||
virtual void init();
|
||||
virtual void setInputting(wchar_t ch);
|
||||
virtual int getCurrentNumPredicted();
|
||||
virtual void getPredicted(int index, wchar_t* string);
|
||||
virtual const wchar_t* getCurrentSelected();
|
||||
virtual u16 getInputStringLength();
|
||||
virtual void setSelectedCandidate(s32 index);
|
||||
virtual bool isFix();
|
||||
virtual void setPredictLaunguage(PredictLanguage language);
|
||||
virtual void changeLetterMode(LetterMode mode);
|
||||
virtual void ChangeDictionaryLanguage(u8 language);
|
||||
virtual void setCellPhoneHoldingkey(void* key);
|
||||
virtual void setElementBuffer();
|
||||
virtual u8 getPredictLanguage();
|
||||
s32 getSelectedCandidateIndex() const { return mSelectedCandidate; }
|
||||
void openDictionary(void* ziDict, void* ziOemDict);
|
||||
void setCurrentWord(const wchar_t* string);
|
||||
void update();
|
||||
const wchar_t* getCurrentInput();
|
||||
s32 getCurrentInput(wchar_t* buffer, u32 length);
|
||||
void clearCandidates();
|
||||
void partialConfirmForKR();
|
||||
private:
|
||||
EZTXGetParam mSearch;
|
||||
u32 mSearchState;
|
||||
bool mbDictionaryOpen;
|
||||
bool mbContextChanged;
|
||||
u32 mCurrentWordLength;
|
||||
EZTXLanguageEntry* mpDictionaries;
|
||||
void* mpDictionaryWork;
|
||||
u16 mInputLength;
|
||||
s32 mCandidateCount;
|
||||
u32 mOemDictionaryId;
|
||||
u8 mDictionaryLanguage;
|
||||
s32 mSelectedCandidate;
|
||||
u32 mPredictLanguage;
|
||||
u32 mLetterMode;
|
||||
void* mpHoldingKey;
|
||||
bool mbKoreanPartialConfirm;
|
||||
};
|
||||
#else
|
||||
class WithZi {
|
||||
public:
|
||||
virtual ~WithZi();
|
||||
|
||||
void openDictionary(void* ziDict, void* ziOemDict);
|
||||
};
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,9 +44,12 @@ namespace ipl {
|
||||
#ifdef IPL_GCW_INTP_CTOR_OUT_OF_LINE
|
||||
LinearIntp() NO_INLINE;
|
||||
#endif
|
||||
#ifdef IPL_BOARD_OBJECT_INLINE_INTERPOLATION_DTORS
|
||||
#if defined(IPL_BOARD_OBJECT_INLINE_INTERPOLATION_DTORS) || defined(IPL_GC_WINDOW_CPP)
|
||||
virtual ~LinearIntp();
|
||||
#endif
|
||||
#ifdef IPL_GC_WINDOW_CPP
|
||||
T get() const;
|
||||
#else
|
||||
T get() const {
|
||||
T r = mEnd * getCurrentFrame();
|
||||
T b = mStart * (mMaxFrame - mFrame);
|
||||
@@ -54,6 +57,7 @@ namespace ipl {
|
||||
return b * (f64)(1.0f / getMaxFrame());
|
||||
}
|
||||
|
||||
#endif
|
||||
T get2() const { return (((mStart * (mMaxFrame - mFrame)) + (mEnd * mFrame)) / mMaxFrame); }
|
||||
};
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace ipl {
|
||||
y = r.y;
|
||||
z = 0.0f;
|
||||
}
|
||||
#if defined(IPL_ADDRESS_EDIT_CPP) || defined(IPL_SD_CHANNEL_SELECT_CPP)
|
||||
#if defined(IPL_ADDRESS_EDIT_CPP) || defined(IPL_SD_CHANNEL_SELECT_CPP) || defined(IPL_GC_WINDOW_CPP)
|
||||
VEC3(f32 fx, f32 fy, f32 fz);
|
||||
#else
|
||||
VEC3(f32 fx, f32 fy, f32 fz) {
|
||||
|
||||
99
include/scene/memoryCard/iplGCWindow.h
Normal file
99
include/scene/memoryCard/iplGCWindow.h
Normal file
@@ -0,0 +1,99 @@
|
||||
#ifndef IPL_SCENE_GC_WINDOW_H
|
||||
#define IPL_SCENE_GC_WINDOW_H
|
||||
|
||||
#include "scene/memoryCard/iplMemoryCardBase.h"
|
||||
#include "scene/memoryCard/iplMemoryCardManager.h"
|
||||
#include "math/iplMathTypes.h"
|
||||
#include "math/iplInterporation.h"
|
||||
|
||||
namespace ipl {
|
||||
namespace scene {
|
||||
class GCWindow : public MemoryBase, public MemCardEventHandler {
|
||||
#ifdef IPL_MEMORY_CARD_CPP
|
||||
friend class MemoryCard;
|
||||
#endif
|
||||
public:
|
||||
GCWindow(EGG::Heap*, nand::LayoutFile*, const char*, const char*);
|
||||
virtual ~GCWindow();
|
||||
void init(const math::VEC3&, MemoryCardManager*, u8, short);
|
||||
void calc();
|
||||
void draw();
|
||||
void destroy();
|
||||
void onPoint(const char*, controller::Interface*);
|
||||
void onLeft(const char*);
|
||||
void onTrig(const char*);
|
||||
private:
|
||||
void on_wait();
|
||||
void on_fadein();
|
||||
void on_normal();
|
||||
void on_fadeout1st();
|
||||
void on_fadeout_yes1st();
|
||||
void on_focus_move();
|
||||
void on_focus_copy();
|
||||
void on_focus_del();
|
||||
void on_select_out();
|
||||
void on_dialog();
|
||||
void on_error_message();
|
||||
void on_process();
|
||||
void on_error_message1st();
|
||||
void on_error_message2nd();
|
||||
void on_error_message3rd();
|
||||
void on_format1st();
|
||||
void on_format2nd();
|
||||
void on_format3rd();
|
||||
void on_format4th();
|
||||
void on_format_error();
|
||||
void change_textbox_doing();
|
||||
void change_textbox_done();
|
||||
void set_texture(const char*, const GXTexObj&);
|
||||
public:
|
||||
virtual void onMemEvent(long, u8);
|
||||
bool isProcess();
|
||||
void stop_wait_anim();
|
||||
|
||||
private:
|
||||
int mState;
|
||||
MemoryBaseEvent* mpEvent;
|
||||
MemoryCardManager* mpMemoryCardManager;
|
||||
math::LinearIntp<math::VEC3> mLinearInterp;
|
||||
math::VEC3 mTranslate;
|
||||
u8 mCardState;
|
||||
short mCardIndex;
|
||||
int mOperation;
|
||||
bool mActive;
|
||||
bool mWaiting;
|
||||
u8 mFlags0[2];
|
||||
u8 mFlags1[2];
|
||||
};
|
||||
|
||||
class SavedataEditWindow : public MemoryBase {
|
||||
public:
|
||||
SavedataEditWindow(EGG::Heap* heap, nand::LayoutFile* layoutFile, const char* directory, const char* fileName);
|
||||
virtual void init();
|
||||
virtual void calc();
|
||||
virtual void draw();
|
||||
virtual void destroy();
|
||||
|
||||
private:
|
||||
void add_animation(const char* fileName, const char* groupName) {
|
||||
AnmName animation = {fileName, groupName};
|
||||
MemoryBase::add_animation(&animation, 1);
|
||||
}
|
||||
void on_normal();
|
||||
void on_fadein();
|
||||
void on_fadeout1st();
|
||||
void on_focus_del();
|
||||
void on_select_out();
|
||||
void on_fadeout_yes1st();
|
||||
|
||||
int mState;
|
||||
MemoryBaseEvent* mpEvent;
|
||||
math::LinearIntp<math::VEC3> mLinearInterp;
|
||||
math::VEC3 mTranslate;
|
||||
bool mActive;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -59,6 +59,10 @@ namespace ipl {
|
||||
void start_errormessage_fadein();
|
||||
int update_slot();
|
||||
|
||||
#ifdef IPL_MEMORY_CARD_CPP
|
||||
bool can_scroll_r() const { return mIconCount > 30 && mState == 2; }
|
||||
bool can_scroll_l() const { return mIconIndex >= 0 && mState == 2; }
|
||||
#endif
|
||||
void show_arw();
|
||||
void show_capacity(u8 slot);
|
||||
|
||||
|
||||
@@ -85,8 +85,16 @@ namespace ipl {
|
||||
GXTexObj* _create_icon(u8 slot, s16 fileNo, long start);
|
||||
const wchar_t* getComment(u8 slot, s16 index, int which);
|
||||
GXTexObj* create_banner(u8 slot, s16 index);
|
||||
#ifdef IPL_GC_WINDOW_CPP
|
||||
u32 getBlocks(u8 slot, s16 index);
|
||||
#else
|
||||
u16 getBlocks(u8 slot, s16 index);
|
||||
#endif
|
||||
#ifdef IPL_MEMORY_CARD_CPP
|
||||
u32 getFreeBlocks(u8 slot);
|
||||
#else
|
||||
u16 getFreeBlocks(u8 slot);
|
||||
#endif
|
||||
|
||||
void setEventHandler(MemCardEventHandler* eventHandler) {
|
||||
mpEventHandler = eventHandler;
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace ipl {
|
||||
int getIndex() const { return mIndex; }
|
||||
nw4r::math::VEC3& getTranslate() const;
|
||||
|
||||
#ifdef IPL_SD_CHANNEL_TITLE_CPP
|
||||
#if defined(IPL_SD_CHANNEL_TITLE_CPP) || defined(IPL_SD_CHANNEL_OBJ_CPP)
|
||||
public:
|
||||
#else
|
||||
private:
|
||||
@@ -39,12 +39,20 @@ namespace ipl {
|
||||
EGG::ExpHeap* mpDialogHeap;
|
||||
EGG::ExpHeap* mpChannelHeap;
|
||||
EGG::Heap* mpHeap;
|
||||
#ifdef IPL_SD_CHANNEL_OBJ_CPP
|
||||
int mState;
|
||||
#else
|
||||
u32 mState;
|
||||
#endif
|
||||
int mPage;
|
||||
int mIndex;
|
||||
nand::LayoutFile* mpLayoutFile;
|
||||
nw4r::lyt::Pane* mpPane;
|
||||
#ifdef IPL_SD_CHANNEL_OBJ_CPP
|
||||
nand::File* mpPaneAnimator;
|
||||
#else
|
||||
layout::Animator* mpPaneAnimator;
|
||||
#endif
|
||||
layout::Object* mpBaseLayout;
|
||||
layout::Animator* mpBaseAnimator;
|
||||
layout::Object* mpPageLayout;
|
||||
@@ -58,7 +66,11 @@ namespace ipl {
|
||||
int mDialogTimer;
|
||||
int mAnimationState;
|
||||
nw4r::lyt::Group* mpNewMessageGroup;
|
||||
#ifdef IPL_SD_CHANNEL_OBJ_CPP
|
||||
layout::Animator* mpNewMessageAnimator;
|
||||
#else
|
||||
int mNewMessageCount;
|
||||
#endif
|
||||
u8 mbNewMessageGroupActive;
|
||||
int mNewMessageState;
|
||||
int mNewMessageFrame;
|
||||
@@ -176,7 +188,7 @@ namespace ipl {
|
||||
static const char* mscClockPaneNames[3];
|
||||
static const char* mscMaskPaneName;
|
||||
|
||||
#ifdef IPL_SD_CHANNEL_TITLE_CPP
|
||||
#if defined(IPL_SD_CHANNEL_TITLE_CPP) || defined(IPL_SD_CHANNEL_OBJ_CPP)
|
||||
public:
|
||||
#else
|
||||
private:
|
||||
|
||||
@@ -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();
|
||||
|
||||
53
libs/RVL_SDK/include/private/fa/pdm.h
Normal file
53
libs/RVL_SDK/include/private/fa/pdm.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef PF_FA_PDM_H
|
||||
#define PF_FA_PDM_H
|
||||
#include <private/vf/PrFILE2/dskmng/pdm_types.h>
|
||||
typedef struct PDM_PARTITION PDM_PARTITION;
|
||||
typedef struct PDM_CALLBACK {
|
||||
void (*insert)(PDM_PARTITION*);
|
||||
void (*eject)(PDM_PARTITION*);
|
||||
} PDM_CALLBACK;
|
||||
struct PDM_PARTITION {
|
||||
pf_u32 status;
|
||||
PDM_DISK* p_disk;
|
||||
pf_u32 part_id;
|
||||
pf_u32 start_sector;
|
||||
pf_u32 total_sector;
|
||||
pf_s32 driver_last_error;
|
||||
pf_u32 lock_state[2];
|
||||
PDM_CALLBACK callbacks;
|
||||
};
|
||||
struct PDM_DISK {
|
||||
pf_u32 status;
|
||||
PDM_DISK_TBL disk_tbl;
|
||||
pf_s16 init_count;
|
||||
pf_s16 mount_count;
|
||||
PDM_DISK* lock_handle;
|
||||
pf_u32 lock_count;
|
||||
PDM_DISK_INFO disk_info;
|
||||
PDM_PARTITION* p_cur_part;
|
||||
};
|
||||
typedef struct PDM_DISK_SET {
|
||||
pf_u16 num_partition;
|
||||
pf_u16 num_allocated_disk;
|
||||
PDM_DISK disk[26];
|
||||
PDM_PARTITION partition[26];
|
||||
} PDM_DISK_SET;
|
||||
extern PDM_DISK_SET pdm_disk_set;
|
||||
extern PDM_DISK_TBL pdm_drv_tbl[26];
|
||||
void pdm_part_set_driver_error_code(PDM_PARTITION*, pf_s32);
|
||||
void pdm_part_set_change_media_state(PDM_DISK*, pf_bool);
|
||||
pf_s32 pdm_disk_convert_sector_into_block(PDM_DISK*, pf_u32, pf_u32, pf_u32, pf_u32*, pf_u32*);
|
||||
pf_s32 pdm_disk_convert_block_into_sector(PDM_DISK*, pf_u32, pf_u32, pf_u32, pf_u32*, pf_u32*);
|
||||
pf_s32 pdm_disk_add_disk(PDM_INIT_DISK*, PDM_DISK**);
|
||||
pf_s32 pdm_disk_del_disk(PDM_DISK*);
|
||||
pf_s32 pdm_disk_set_disk(PDM_DISK*, PDM_PARTITION*);
|
||||
pf_s32 pdm_disk_get_media_attribute(PDM_DISK*, PDM_DISK_INFO*);
|
||||
pf_s32 pdm_disk_get_media_bps(PDM_DISK*, pf_u16*);
|
||||
pf_s32 pdm_disk_init(PDM_DISK*);
|
||||
pf_s32 pdm_disk_mount(PDM_DISK*);
|
||||
pf_s32 pdm_disk_format(PDM_DISK*, const pf_u8*);
|
||||
pf_s32 pdm_disk_physical_read(PDM_DISK*, pf_u8*, pf_u32, pf_u32, pf_u32, pf_u32*);
|
||||
pf_s32 pdm_disk_physical_write(PDM_DISK*, const pf_u8*, pf_u32, pf_u32, pf_u32, pf_u32*);
|
||||
pf_s32 pdm_disk_unmount(PDM_DISK*, pf_u32);
|
||||
pf_s32 pdm_disk_finalize(PDM_DISK*);
|
||||
#endif
|
||||
17
libs/RVL_SDK/include/private/fa/pf_system.h
Normal file
17
libs/RVL_SDK/include/private/fa/pf_system.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef PF_FA_SYSTEM_LAYOUT_H
|
||||
#define PF_FA_SYSTEM_LAYOUT_H
|
||||
#include <revolution/os.h>
|
||||
|
||||
typedef struct PFSYS_SYSTEM_SET {
|
||||
u32 initialized;
|
||||
s32 task_id;
|
||||
s32 mailbox_id;
|
||||
u8 task_stack[0x2000];
|
||||
OSThread task;
|
||||
OSMessageQueue mailbox;
|
||||
OSMessage messages[20];
|
||||
u32 flock_count;
|
||||
} PFSYS_SYSTEM_SET;
|
||||
|
||||
extern PFSYS_SYSTEM_SET pf_sys_set;
|
||||
#endif
|
||||
96
libs/RVL_SDK/include/private/fa/pf_volume.h
Normal file
96
libs/RVL_SDK/include/private/fa/pf_volume.h
Normal file
@@ -0,0 +1,96 @@
|
||||
#ifndef PF_FA_VOLUME_LAYOUT_H
|
||||
#define PF_FA_VOLUME_LAYOUT_H
|
||||
#define PRFILE2_VFMOD_PF_VOLUME_H
|
||||
#include <private/vf/PrFILE2/fatfs/pf_entry.h>
|
||||
#include <private/vf/PrFILE2/driver/pf_driver.h>
|
||||
#include <private/vf/PrFILE2/fatfs/pf_devinf.h>
|
||||
typedef struct PF_CHARCODE {
|
||||
pf_s32 (*oem2unicode)(const pf_s8*, pf_u16*);
|
||||
pf_s32 (*unicode2oem)(const pf_u16*, pf_s8*);
|
||||
pf_s32 (*oem_char_width)(const pf_s8*);
|
||||
pf_bool (*is_oem_mb_char)(const pf_s8, pf_bool);
|
||||
pf_s32 (*unicode_char_width)(const pf_u16*);
|
||||
pf_bool (*is_unicode_mb_char)(const pf_u16, pf_bool);
|
||||
} PF_CHARCODE;
|
||||
|
||||
typedef struct PF_BPB {
|
||||
pf_u16 bytes_per_sector;
|
||||
pf_u16 num_reserved_sectors;
|
||||
pf_u16 num_root_dir_entries;
|
||||
pf_u8 sectors_per_cluster;
|
||||
pf_u8 num_FATs;
|
||||
pf_u32 total_sectors;
|
||||
pf_u32 sectors_per_FAT;
|
||||
pf_u32 root_dir_cluster;
|
||||
pf_u16 fs_info_sector;
|
||||
pf_u16 backup_boot_sector;
|
||||
pf_u16 ext_flags;
|
||||
pf_u8 media;
|
||||
PF_FAT_TYPE fat_type;
|
||||
pf_u8 log2_bytes_per_sector;
|
||||
pf_u8 log2_sectors_per_cluster;
|
||||
pf_u8 num_active_FATs;
|
||||
pf_u16 num_root_dir_sectors;
|
||||
pf_u32 active_FAT_sector;
|
||||
pf_u32 first_root_dir_sector;
|
||||
pf_u32 first_data_sector;
|
||||
pf_u32 num_clusters;
|
||||
} PF_BPB;
|
||||
|
||||
typedef struct PF_CUR_DIR {
|
||||
pf_u32 stat;
|
||||
pf_s32 context_id;
|
||||
PF_DIR_ENT directory;
|
||||
} PF_CUR_DIR;
|
||||
|
||||
|
||||
typedef pf_s32 (*PF_VOLUME_CB)(pf_s32);
|
||||
struct PF_VOLUME {
|
||||
PF_BPB bpb;
|
||||
pf_u32 num_free_clusters;
|
||||
pf_u32 last_free_cluster;
|
||||
pf_u8 file_and_directory_state[0x1624 - 0x40];
|
||||
PF_SECTOR_CACHE cache;
|
||||
pf_s8 label[12];
|
||||
PF_CUR_DIR current_dir[4];
|
||||
struct {
|
||||
pf_u32 tracker_size;
|
||||
pf_u32 tracker_max;
|
||||
pf_u32* tracker_bits;
|
||||
} tail_entry;
|
||||
pf_s32 last_error;
|
||||
pf_s32 last_driver_error;
|
||||
pf_u32 file_config;
|
||||
pf_u16 flags;
|
||||
pf_s8 drv_char;
|
||||
pf_u16 fsi_flag;
|
||||
PF_CLUSTER_LINK_VOL cluster_link;
|
||||
void* p_part;
|
||||
void (*p_callback)();
|
||||
const pf_u8* format_param;
|
||||
};
|
||||
typedef struct PF_FA_CUR_VOLUME {
|
||||
pf_u32 stat;
|
||||
pf_s32 context_id;
|
||||
PF_VOLUME* p_vol;
|
||||
} PF_FA_CUR_VOLUME;
|
||||
typedef struct PF_VOLUME_SET {
|
||||
pf_u32 flags;
|
||||
pf_u32 reserved;
|
||||
PF_VOLUME* current_volume;
|
||||
PF_FA_CUR_VOLUME context_volumes[3];
|
||||
pf_s32 num_attached_drives;
|
||||
pf_s32 num_mounted_volumes;
|
||||
pf_u32 config;
|
||||
void* param;
|
||||
pf_s32 last_error;
|
||||
pf_s32 last_driver_error;
|
||||
PF_CHARCODE codeset;
|
||||
pf_u32 setting;
|
||||
pf_s32 context_id;
|
||||
pf_u32 context_state[2];
|
||||
struct { pf_u32 stat; pf_s32 context_id; } contexts[3];
|
||||
PF_VOLUME volumes[26];
|
||||
} PF_VOLUME_SET;
|
||||
extern PF_VOLUME_SET pf_vol_set;
|
||||
#endif
|
||||
@@ -30,11 +30,21 @@ typedef enum _KBDCountryCode {
|
||||
} KBDCountryCode;
|
||||
|
||||
typedef struct _KBDKeyEvent {
|
||||
#ifdef TIHKBMANAGER_IMPLEMENTATION
|
||||
u8 device;
|
||||
u8 key;
|
||||
u32 flags;
|
||||
#else
|
||||
u8 unk_0x00[32];
|
||||
#endif
|
||||
} KBDKeyEvent;
|
||||
|
||||
typedef struct _KBDDevEvent {
|
||||
#ifdef TIHKBMANAGER_IMPLEMENTATION
|
||||
u8 device;
|
||||
#else
|
||||
u8 unk_0x00[32];
|
||||
#endif
|
||||
} KBDDevEvent;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
535
libs/RVL_SDK/src/fa/driver/nand_drv.c
Normal file
535
libs/RVL_SDK/src/fa/driver/nand_drv.c
Normal file
@@ -0,0 +1,535 @@
|
||||
#include <private/fa/pdm.h>
|
||||
#include <revolution/nand.h>
|
||||
#include <revolution/types.h>
|
||||
extern void* pf_memset(void*, u8, u32);
|
||||
extern void* pf_memcpy(void*, const void*, u32);
|
||||
extern s32 pf_strcmp(const char*, const char*);
|
||||
extern char* pf_strcpy(char*, const char*);
|
||||
extern u32 pf_strlen(const char*);
|
||||
extern void pdm_disk_notify_media_insert(PDM_DISK*);
|
||||
typedef struct NAND_DISK_INFO {
|
||||
PDM_DISK* disk;
|
||||
char path[80];
|
||||
u32 file_size;
|
||||
NANDFileInfo file;
|
||||
u32 flags;
|
||||
u32 reserved_sectors;
|
||||
s32 last_error;
|
||||
} NAND_DISK_INFO;
|
||||
typedef struct NAND_SEMAPHORE { s32 count; s32 maximum; void* object; } NAND_SEMAPHORE;
|
||||
extern s32 pfk_create_semaphore(NAND_SEMAPHORE*);
|
||||
extern void pfk_get_semaphore(s32);
|
||||
extern void pfk_release_semaphore(s32);
|
||||
char NAND_Org_Path[64];
|
||||
NAND_DISK_INFO nanddisk_info[23];
|
||||
NAND_SEMAPHORE csem;
|
||||
NAND_SEMAPHORE osem;
|
||||
s32 Nanddisk_Internal_Info_Init;
|
||||
s32 NAND_Init;
|
||||
s32 fa_nanad_semid;
|
||||
|
||||
static inline s32 find_disk(PDM_DISK* disk, NAND_DISK_INFO** result) {
|
||||
NAND_DISK_INFO* info;
|
||||
u16 index;
|
||||
for (index = 0; index < 23; index++) {
|
||||
info = &nanddisk_info[index];
|
||||
if (info->disk == disk) { *result = info; break; }
|
||||
}
|
||||
return index == 23 ? -22 : 0;
|
||||
}
|
||||
static inline s32 set_disk_error(PDM_DISK* disk, s32 error) {
|
||||
u16 index;
|
||||
for (index = 0; index < 23; index++) {
|
||||
if (nanddisk_info[index].disk == disk) { nanddisk_info[index].last_error = error; break; }
|
||||
}
|
||||
return index == 23 ? -22 : 0;
|
||||
}
|
||||
static inline void store_disk_error(PDM_DISK* disk, s32 error) {
|
||||
u16 index;
|
||||
for (index = 0; index < 23; index++) {
|
||||
if (nanddisk_info[index].disk == disk) { nanddisk_info[index].last_error = error; break; }
|
||||
}
|
||||
}
|
||||
static inline NAND_DISK_INFO* find_unmounted_disk(PDM_DISK* disk) {
|
||||
u16 index;
|
||||
NAND_DISK_INFO* info;
|
||||
for (index = 0; index < 23; index++) {
|
||||
info = &nanddisk_info[index];
|
||||
if (info->disk == disk) { if (!(info->flags & 2)) { return info; } }
|
||||
}
|
||||
for (index = 0; index < 23; index++) {
|
||||
info = &nanddisk_info[index];
|
||||
if (info->disk == 0) { if (info->path[0] != 0) { return info; } }
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static inline u16 read_u16(u8* buf, u32 offset) {
|
||||
if ((u32)&buf[offset] & 1) { return (buf[offset + 1] << 8) | buf[offset]; }
|
||||
return PF_SWAP_16(*(u16*)&buf[(offset + 1) & ~1]);
|
||||
}
|
||||
static inline void write_u16(u8* buf, u32 offset, u16 value) {
|
||||
if ((u32)&buf[offset] & 1) { buf[offset] = value; buf[offset + 1] = value >> 8; }
|
||||
else { *(u16*)&buf[(offset + 1) & ~1] = PF_SWAP_16(value); }
|
||||
}
|
||||
static inline void write_u32(u8* buf, u32 offset, u32 value) {
|
||||
if ((u32)&buf[offset] & 3) { buf[offset] = value; buf[offset + 1] = value >> 8; buf[offset + 2] = value >> 16; buf[offset + 3] = value >> 24; }
|
||||
else { *(u32*)&buf[offset] = PF_SWAP_32(value); }
|
||||
}
|
||||
static s32 fa_nanddrv_CreateNANDFileForDsk(NAND_DISK_INFO*);
|
||||
static s32 fa_nanddrv_ParseCreateNANDFile(NAND_DISK_INFO*);
|
||||
static s32 fa_nanddrv_VerifyBPB(u8*, u32*);
|
||||
static s32 fa_nanddrv_BuildUpFSInfoSector(u8*);
|
||||
static s32 fa_nanddrv_BuildUpBootSector(NAND_DISK_INFO*, u8*, PDM_FAT_TYPE*, u32);
|
||||
static s32 fa_nanddrv_physical_read(u32, u8*, u32, u32, u32*, PDM_DISK*);
|
||||
static s32 fa_nanddrv_physical_write(u32, const u8*, u32, u32, u32*, PDM_DISK*);
|
||||
|
||||
static s32 fa_nanddrv_RelateNANDFileToDsk(PDM_DISK* disk, NAND_DISK_INFO* info, s32 format) {
|
||||
s32 error = NANDChangeDir(NAND_Org_Path);
|
||||
if (error != 0) { return error; }
|
||||
if (info->flags & 4) { error = 0; }
|
||||
else { error = NANDOpen(info->path, &info->file, 3); }
|
||||
if (format) { error = -12; }
|
||||
switch (error) {
|
||||
case -12:
|
||||
error = fa_nanddrv_CreateNANDFileForDsk(info);
|
||||
if (error == 0) { info->disk = disk; }
|
||||
break;
|
||||
case 0:
|
||||
info->disk = disk;
|
||||
error = 0;
|
||||
break;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
static s32 fa_nanddrv_CreateNANDFileForDsk(NAND_DISK_INFO* info) {
|
||||
u8 zeros[512] __attribute__((aligned(32)));
|
||||
u8 boot[512] __attribute__((aligned(32)));
|
||||
u8 fsinfo[512] __attribute__((aligned(32)));
|
||||
PDM_FAT_TYPE type;
|
||||
u32 clusters;
|
||||
s32 error;
|
||||
u32 remaining;
|
||||
error = fa_nanddrv_ParseCreateNANDFile(info);
|
||||
if (error != 0) { return error; }
|
||||
pf_memset(boot, 0, 512);
|
||||
clusters = 0;
|
||||
fa_nanddrv_BuildUpBootSector(info, boot, &type, 0);
|
||||
if (type != fa_nanddrv_VerifyBPB(boot, &clusters)) { fa_nanddrv_BuildUpBootSector(info, boot, &type, clusters); }
|
||||
error = NANDWrite(&info->file, boot, 512);
|
||||
if (error < 0) { NANDClose(&info->file); NANDDelete(info->path); return error; }
|
||||
remaining = info->file_size - 512;
|
||||
if (type == PDM_FAT_32) {
|
||||
fa_nanddrv_BuildUpFSInfoSector(fsinfo);
|
||||
error = NANDWrite(&info->file, fsinfo, 512);
|
||||
if (error < 0) { NANDClose(&info->file); NANDDelete(info->path); return error; }
|
||||
remaining -= 512;
|
||||
}
|
||||
pf_memset(zeros, 0, 512);
|
||||
for (; remaining >= 512; remaining -= 512) {
|
||||
error = NANDWrite(&info->file, zeros, 512);
|
||||
if (error < 0) { NANDClose(&info->file); NANDDelete(info->path); return error; }
|
||||
}
|
||||
if (remaining) {
|
||||
error = NANDWrite(&info->file, zeros, remaining);
|
||||
if (error < 0) { NANDClose(&info->file); NANDDelete(info->path); return error; }
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static s32 fa_nanddrv_ParseCreateNANDFile(NAND_DISK_INFO* info) {
|
||||
u16 length = 0;
|
||||
char* path;
|
||||
u16 position = 0;
|
||||
char name[16];
|
||||
char* next;
|
||||
s32 error;
|
||||
if (info->flags & 4) { return 0; }
|
||||
path = info->path;
|
||||
pf_memset(name, 0, 16);
|
||||
next = name;
|
||||
for (;;) {
|
||||
switch (*path) {
|
||||
case '/':
|
||||
if (length == 0) {
|
||||
if (position == 0) { error = NANDChangeDir("/"); if (error != 0) { return error; } }
|
||||
path++;
|
||||
break;
|
||||
}
|
||||
if (path[1] == 0) {
|
||||
if (length > 12) { return -20; }
|
||||
error = NANDCreate(name, 0x30, 0);
|
||||
if (error == 0 || error == -6) {
|
||||
NANDOpen(name, &info->file, 3);
|
||||
error = NANDChangeDir(NAND_Org_Path);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
if (length > 11) { return -20; }
|
||||
if (pf_strcmp(name, "..") != 0) { error = NANDCreateDir(name, 0x30, 0); }
|
||||
else { error = 0; }
|
||||
if (error == 0 || error == -6 || error == -1) {
|
||||
error = NANDChangeDir(name);
|
||||
if (error != 0) { return error; }
|
||||
path++;
|
||||
pf_memset(name, 0, 16);
|
||||
next = name;
|
||||
length = 0;
|
||||
break;
|
||||
}
|
||||
return error;
|
||||
case 0:
|
||||
if (length > 12) { return -20; }
|
||||
error = NANDCreate(name, 0x30, 0);
|
||||
if (error == 0 || error == -6) {
|
||||
NANDOpen(name, &info->file, 3);
|
||||
error = NANDChangeDir(NAND_Org_Path);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
*next = *path;
|
||||
length++;
|
||||
position++;
|
||||
path++;
|
||||
next++;
|
||||
}
|
||||
}
|
||||
static s32 fa_nanddrv_VerifyBPB(u8* buf, u32* clusters) {
|
||||
u8 sector_log = 0;
|
||||
u8 cluster_log;
|
||||
u16 value = 512;
|
||||
u32 root;
|
||||
u32 fat;
|
||||
u32 total;
|
||||
u16 root_sectors;
|
||||
PDM_FAT_TYPE result;
|
||||
u32 first;
|
||||
while ((value >>= 1) != 0) { sector_log++; }
|
||||
cluster_log = 0;
|
||||
value = 1;
|
||||
while ((value >>= 1) != 0) { cluster_log++; }
|
||||
if ((u32)&buf[17] & 1) { root = (buf[18] << 8) | buf[17]; }
|
||||
else { root = PF_SWAP_16(*(u16*)&buf[18]) << 5; }
|
||||
root_sectors = (s32)(root + 511) >> sector_log;
|
||||
fat = read_u16(buf, 22);
|
||||
if (fat == 0) { fat = PF_SWAP_32(*(u32*)&buf[36]); }
|
||||
first = root_sectors + fat * 2 + 1;
|
||||
if ((u32)&buf[19] & 1) { total = (buf[20] << 8) | buf[19]; }
|
||||
else { total = PF_SWAP_16(*(u16*)&buf[20]); }
|
||||
if (total == 0) { total = PF_SWAP_32(*(u32*)&buf[32]); }
|
||||
*clusters = total - first;
|
||||
total = (u32)(total - first) >> cluster_log;
|
||||
if (total < 4085) { return 0; }
|
||||
result = PDM_FAT_32;
|
||||
if ((u32)total < 65525) { result = PDM_FAT_16; }
|
||||
return result;
|
||||
}
|
||||
#pragma dont_inline on
|
||||
static s32 fa_nanddrv_BuildUpFSInfoSector(u8* buf) {
|
||||
pf_memset(buf, 0, 512);
|
||||
if ((u32)&buf[0] & 3) { buf[0] = 0x52; buf[1] = 0x52; buf[2] = 0x61; buf[3] = 0x41; }
|
||||
else { *(u32*)&buf[0] = 0x52526141; }
|
||||
if ((u32)&buf[484] & 3) { buf[484] = 0x72; buf[485] = 0x72; buf[486] = 0x41; buf[487] = 0x61; }
|
||||
else { *(u32*)&buf[484] = 0x72724161; }
|
||||
if ((u32)&buf[488] & 3) { buf[488] = 0xFF; buf[489] = 0xFF; buf[490] = 0xFF; buf[491] = 0xFF; }
|
||||
else { *(u32*)&buf[488] = 0xFFFFFFFF; }
|
||||
if ((u32)&buf[492] & 3) { buf[492] = 0xFF; buf[493] = 0xFF; buf[494] = 0xFF; buf[495] = 0xFF; }
|
||||
else { *(u32*)&buf[492] = 0xFFFFFFFF; }
|
||||
if ((u32)&buf[508] & 3) { buf[508] = 0x00; buf[509] = 0x00; buf[510] = 0x55; buf[511] = 0xAA; }
|
||||
else { *(u32*)&buf[508] = 0x000055AA; }
|
||||
return 0;
|
||||
}
|
||||
#pragma dont_inline reset
|
||||
static s32 fa_nanddrv_BuildUpBootSector(NAND_DISK_INFO* info, u8* buf, PDM_FAT_TYPE* type, u32 clusters) {
|
||||
u32 total;
|
||||
u32 fat_sectors;
|
||||
PDM_FAT_TYPE fat_type;
|
||||
total = clusters ? clusters : info->file_size >> 9;
|
||||
if (total < 4085) { fat_type = PDM_FAT_12; fat_sectors = (((total * 3) >> 1) + 511) >> 9; }
|
||||
else if (total < 65525) { fat_type = PDM_FAT_16; fat_sectors = (total * 2 + 511) >> 9; }
|
||||
else { fat_type = PDM_FAT_32; fat_sectors = (total * 4 + 511) >> 9; }
|
||||
pf_memset(buf, 0, 512);
|
||||
buf[0] = 0xEB; buf[2] = 0x90; buf[510] = 0x55; buf[511] = 0xAA;
|
||||
write_u16(buf, 24, 63);
|
||||
write_u16(buf, 26, 255);
|
||||
write_u16(buf, 11, 512);
|
||||
buf[13] = 1;
|
||||
write_u16(buf, 14, 1);
|
||||
buf[16] = 2;
|
||||
write_u16(buf, 17, 128);
|
||||
buf[21] = 0xF0;
|
||||
if (total < 65536) { write_u16(buf, 19, total); write_u32(buf, 32, 0); }
|
||||
else { write_u16(buf, 19, 0); write_u32(buf, 32, total); }
|
||||
if (fat_type == PDM_FAT_32) {
|
||||
write_u16(buf, 17, 0);
|
||||
write_u32(buf, 36, fat_sectors);
|
||||
write_u16(buf, 40, 0); write_u16(buf, 42, 0);
|
||||
write_u32(buf, 44, 2); write_u16(buf, 48, 1);
|
||||
buf[65] = 0; buf[66] = 0x29;
|
||||
if ((u32)&buf[67] & 3) { buf[67] = 0x34; buf[68] = 0x12; buf[69] = 0; buf[70] = 0; }
|
||||
else { *(u32*)&buf[76] = 0x34120000; }
|
||||
} else {
|
||||
write_u16(buf, 17, 128); write_u16(buf, 22, fat_sectors);
|
||||
buf[37] = 0; buf[38] = 0x29;
|
||||
if ((u32)&buf[39] & 3) { buf[39] = 0x34; buf[40] = 0x12; buf[41] = 0; buf[42] = 0; }
|
||||
else { *(u32*)&buf[48] = 0x34120000; }
|
||||
}
|
||||
*type = fat_type;
|
||||
return 0;
|
||||
}
|
||||
s32 fa_nanddrv_init(PDM_DISK* disk) {
|
||||
if (disk == 0) { return -20; }
|
||||
if (NAND_Init == 0) {
|
||||
if (NANDInit() != 0) { return -21; }
|
||||
if (NANDGetCurrentDir(NAND_Org_Path) != 0) { return -21; }
|
||||
NAND_Init++;
|
||||
}
|
||||
pdm_disk_notify_media_insert(disk);
|
||||
return 0;
|
||||
}
|
||||
s32 fa_nanddrv_mount(PDM_DISK* disk) {
|
||||
NAND_DISK_INFO* info;
|
||||
NAND_DISK_INFO* mounted;
|
||||
s32 error;
|
||||
pfk_get_semaphore(fa_nanad_semid);
|
||||
if (disk == 0) { pfk_release_semaphore(fa_nanad_semid); return -20; }
|
||||
if (find_disk(disk, &mounted) == 0 && (mounted->flags & 2)) { pfk_release_semaphore(fa_nanad_semid); return -21; }
|
||||
info = find_unmounted_disk(disk);
|
||||
if (info == 0) { pfk_release_semaphore(fa_nanad_semid); return -22; }
|
||||
if (info->disk != 0) { error = 0; }
|
||||
else { error = fa_nanddrv_RelateNANDFileToDsk(disk, info, 0); }
|
||||
if (error == 0) { info->flags |= 2; }
|
||||
pfk_release_semaphore(fa_nanad_semid);
|
||||
return error;
|
||||
}
|
||||
s32 fa_nanddrv_format(PDM_DISK* disk, const u8* param) {
|
||||
NAND_DISK_INFO* info = 0;
|
||||
s32 error;
|
||||
pfk_get_semaphore(fa_nanad_semid);
|
||||
if (disk == 0) { pfk_release_semaphore(fa_nanad_semid); return -20; }
|
||||
if (find_disk(disk, &info) != 0) { pfk_release_semaphore(fa_nanad_semid); return -20; }
|
||||
info->flags |= 4;
|
||||
error = fa_nanddrv_RelateNANDFileToDsk(disk, info, 1);
|
||||
info->flags &= ~4;
|
||||
pfk_release_semaphore(fa_nanad_semid);
|
||||
return error;
|
||||
}
|
||||
s32 fa_nanddrv_pread(PDM_DISK* disk, u8* buf, u32 block, u32 count, u32* success) {
|
||||
s32 error;
|
||||
pfk_get_semaphore(fa_nanad_semid);
|
||||
*success = 0;
|
||||
if (disk == 0) { pfk_release_semaphore(fa_nanad_semid); return -20; }
|
||||
if (buf == 0) { pfk_release_semaphore(fa_nanad_semid); return -20; }
|
||||
error = fa_nanddrv_physical_read(count, buf, block, 512, success, disk);
|
||||
if (error != 0) { pfk_release_semaphore(fa_nanad_semid); return error; }
|
||||
pfk_release_semaphore(fa_nanad_semid);
|
||||
return 0;
|
||||
}
|
||||
s32 fa_nanddrv_pwrite(PDM_DISK* disk, const u8* buf, u32 block, u32 count, u32* success) {
|
||||
s32 error;
|
||||
pfk_get_semaphore(fa_nanad_semid);
|
||||
*success = 0;
|
||||
if (disk == 0) { pfk_release_semaphore(fa_nanad_semid); return -20; }
|
||||
if (buf == 0) { pfk_release_semaphore(fa_nanad_semid); return -20; }
|
||||
error = fa_nanddrv_physical_write(count, buf, block, 512, success, disk);
|
||||
if (error != 0) { pfk_release_semaphore(fa_nanad_semid); return error; }
|
||||
pfk_release_semaphore(fa_nanad_semid);
|
||||
return 0;
|
||||
}
|
||||
s32 fa_nanddrv_unmount(PDM_DISK* disk) {
|
||||
NAND_DISK_INFO* info = 0;
|
||||
u32 position;
|
||||
s32 error;
|
||||
s32 result;
|
||||
pfk_get_semaphore(fa_nanad_semid);
|
||||
if (disk == 0) { pfk_release_semaphore(fa_nanad_semid); return -20; }
|
||||
error = set_disk_error(disk, 0);
|
||||
if (error == 0) {
|
||||
if (find_disk(disk, &info) != 0) { pfk_release_semaphore(fa_nanad_semid); return -20; }
|
||||
info->flags &= ~2;
|
||||
error = NANDTell(&info->file, &position);
|
||||
if (error != 0) { result = error; goto flush_done; }
|
||||
error = NANDClose(&info->file);
|
||||
if (error < 0) { result = error; goto flush_done; }
|
||||
error = NANDOpen(info->path, &info->file, 3);
|
||||
if (error < 0) { result = error; goto flush_done; }
|
||||
error = NANDSeek(&info->file, position, 0);
|
||||
result = error < 0 ? error : 0;
|
||||
flush_done:
|
||||
error = result;
|
||||
if (error < 0) { set_disk_error(disk, error); pfk_release_semaphore(fa_nanad_semid); return error; }
|
||||
}
|
||||
pfk_release_semaphore(fa_nanad_semid);
|
||||
return error;
|
||||
}
|
||||
s32 fa_nanddrv_finalize(PDM_DISK* disk) {
|
||||
NAND_DISK_INFO* info;
|
||||
s32 error = 0;
|
||||
u16 index;
|
||||
pfk_get_semaphore(fa_nanad_semid);
|
||||
if (disk == 0) { pfk_release_semaphore(fa_nanad_semid); return -20; }
|
||||
for (index = 0; index < 23; index++) {
|
||||
info = &nanddisk_info[index];
|
||||
if (info->disk == disk) {
|
||||
error = NANDClose(&info->file);
|
||||
pf_memset(info, 0, sizeof(*info));
|
||||
break;
|
||||
}
|
||||
}
|
||||
pfk_release_semaphore(fa_nanad_semid);
|
||||
if (error != 0) { return -20; }
|
||||
return index == 23 ? -22 : 0;
|
||||
}
|
||||
s32 fa_nanddrv_get_disk_info(PDM_DISK* disk, PDM_DISK_INFO* disk_info) {
|
||||
NAND_DISK_INFO* info = 0;
|
||||
pfk_get_semaphore(fa_nanad_semid);
|
||||
if (disk == 0 || disk_info == 0) { pfk_release_semaphore(fa_nanad_semid); return -20; }
|
||||
if (find_disk(disk, &info) != 0) { pfk_release_semaphore(fa_nanad_semid); return -20; }
|
||||
disk_info->total_sectors = info->file_size >> 9;
|
||||
disk_info->cylinders = disk_info->total_sectors / 255 / 63 / 512;
|
||||
disk_info->heads = 255;
|
||||
disk_info->sectors_per_track = 63;
|
||||
disk_info->bytes_per_sector = 512;
|
||||
disk_info->media_attr = 0;
|
||||
disk_info->format_param = 0;
|
||||
pfk_release_semaphore(fa_nanad_semid);
|
||||
return 0;
|
||||
}
|
||||
const PDM_FUNCTBL fa_nand_func = {
|
||||
fa_nanddrv_init, fa_nanddrv_finalize, fa_nanddrv_mount, fa_nanddrv_unmount,
|
||||
fa_nanddrv_format, fa_nanddrv_pread, fa_nanddrv_pwrite, fa_nanddrv_get_disk_info
|
||||
};
|
||||
s32 fa_nanddrv_init_drv_tbl(PDM_DISK_TBL* table, u32 extension) {
|
||||
table->ui_ext = extension;
|
||||
table->p_func = (PDM_FUNCTBL*)&fa_nand_func;
|
||||
return 0;
|
||||
}
|
||||
s32 fa_nanddrv_NotifyNANDFile(const char* path, u32 size) {
|
||||
NAND_DISK_INFO* info;
|
||||
u16 index;
|
||||
if (pf_strlen(path) >= 76) { return -20; }
|
||||
if (Nanddisk_Internal_Info_Init == 0) {
|
||||
pf_memset(nanddisk_info, 0, sizeof(nanddisk_info));
|
||||
Nanddisk_Internal_Info_Init++;
|
||||
csem.count = 1;
|
||||
csem.maximum = 1;
|
||||
csem.object = &osem;
|
||||
fa_nanad_semid = pfk_create_semaphore(&csem);
|
||||
if (fa_nanad_semid == 0) { return -21; }
|
||||
}
|
||||
for (index = 0; index < 23; index++) {
|
||||
info = &nanddisk_info[index];
|
||||
if (pf_strcmp(info->path, path) == 0) { return 0; }
|
||||
if (nanddisk_info[index].disk == 0) {
|
||||
pf_strcpy(info->path, path);
|
||||
info->file_size = size;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return index == 23 ? -22 : 0;
|
||||
}
|
||||
static s32 fa_nanddrv_physical_read(u32 count, u8* buf, u32 block, u32 bps, u32* success, PDM_DISK* disk) {
|
||||
u32 file_size;
|
||||
u32 wanted;
|
||||
u32 remaining;
|
||||
s32 error;
|
||||
NAND_DISK_INFO* info = 0;
|
||||
u16 index;
|
||||
u32 offset;
|
||||
u32 position;
|
||||
u8 work[512] __attribute__((aligned(32)));
|
||||
for (index = 0; index < 23; index++) {
|
||||
if (nanddisk_info[index].disk == disk) { info = &nanddisk_info[index]; break; }
|
||||
}
|
||||
if ((index == 23 ? -22 : 0) != 0) { return -20; }
|
||||
remaining = count * bps;
|
||||
file_size = info->file_size;
|
||||
wanted = block * bps;
|
||||
if (NANDTell(&info->file, &position) != 0 || position != wanted) { error = NANDSeek(&info->file, wanted, 0); }
|
||||
else { error = 0; }
|
||||
if (error >= 0) {
|
||||
if (wanted + remaining > file_size) {
|
||||
remaining = file_size - wanted;
|
||||
offset = 0;
|
||||
while (remaining >= 512) {
|
||||
error = NANDRead(&info->file, work, 512);
|
||||
if (error < 0) { return -22; }
|
||||
pf_memcpy(buf + offset, work, error);
|
||||
offset += error; remaining -= error;
|
||||
}
|
||||
if (remaining) {
|
||||
error = NANDRead(&info->file, work, remaining);
|
||||
if (error < 0) { return -22; }
|
||||
pf_memcpy(buf + offset, work, error);
|
||||
}
|
||||
return -22;
|
||||
}
|
||||
offset = 0;
|
||||
while (remaining >= 512) {
|
||||
error = NANDRead(&info->file, work, 512);
|
||||
if (error < 0) { store_disk_error(disk, error); return error; }
|
||||
pf_memcpy(buf + offset, work, error);
|
||||
offset += error; remaining -= error;
|
||||
}
|
||||
if (remaining) {
|
||||
error = NANDRead(&info->file, work, remaining);
|
||||
if (error < 0) { store_disk_error(disk, error); return error; }
|
||||
pf_memcpy(buf + offset, work, error);
|
||||
}
|
||||
*success = count;
|
||||
return 0;
|
||||
}
|
||||
store_disk_error(disk, error);
|
||||
return error;
|
||||
}
|
||||
static s32 fa_nanddrv_physical_write(u32 count, const u8* buf, u32 block, u32 bps, u32* success, PDM_DISK* disk) {
|
||||
u32 remaining;
|
||||
u32 wanted;
|
||||
u32 file_size;
|
||||
NAND_DISK_INFO* info = 0;
|
||||
u16 index;
|
||||
u32 offset;
|
||||
u32 position;
|
||||
s32 error;
|
||||
u8 work[512] __attribute__((aligned(32)));
|
||||
for (index = 0; index < 23; index++) {
|
||||
if (nanddisk_info[index].disk == disk) { info = &nanddisk_info[index]; break; }
|
||||
}
|
||||
if ((index == 23 ? -22 : 0) != 0) { return -20; }
|
||||
remaining = count * bps;
|
||||
file_size = info->file_size;
|
||||
wanted = block * bps;
|
||||
if (NANDTell(&info->file, &position) != 0 || position != wanted) { error = NANDSeek(&info->file, wanted, 0); }
|
||||
else { error = 0; }
|
||||
if (error >= 0) {
|
||||
if (wanted + remaining > file_size) {
|
||||
remaining = file_size - wanted;
|
||||
offset = 0;
|
||||
while (remaining >= 512) {
|
||||
pf_memcpy(work, buf + offset, 512);
|
||||
error = NANDWrite(&info->file, work, 512);
|
||||
if (error < 0) { return -22; }
|
||||
remaining -= error; offset += error;
|
||||
}
|
||||
if (remaining) {
|
||||
pf_memcpy(work, buf + offset, remaining);
|
||||
error = NANDWrite(&info->file, work, remaining);
|
||||
}
|
||||
return -22;
|
||||
}
|
||||
offset = 0;
|
||||
while (remaining >= 512) {
|
||||
pf_memcpy(work, buf + offset, 512);
|
||||
error = NANDWrite(&info->file, work, 512);
|
||||
if (error < 0) { store_disk_error(disk, error); return error; }
|
||||
remaining -= error; offset += error;
|
||||
}
|
||||
if (remaining) {
|
||||
pf_memcpy(work, buf + offset, remaining);
|
||||
error = NANDWrite(&info->file, work, remaining);
|
||||
if (error < 0) { store_disk_error(disk, error); return error; }
|
||||
}
|
||||
*success = count;
|
||||
return 0;
|
||||
}
|
||||
store_disk_error(disk, error);
|
||||
return error;
|
||||
}
|
||||
99
libs/RVL_SDK/src/fa/pdm_bpb.c
Normal file
99
libs/RVL_SDK/src/fa/pdm_bpb.c
Normal file
@@ -0,0 +1,99 @@
|
||||
#define PF_FA_STR_LAYOUT
|
||||
#include <private/fa/pf_volume.h>
|
||||
#include <private/vf/PrFILE2/dskmng/pdm_bpb.h>
|
||||
extern pf_bool pdm_part_is_boot_sector(pf_u8*);
|
||||
|
||||
static inline pf_u16 read_boot_u16(pf_u8* buf, pf_u32 offset) {
|
||||
if ((pf_u32)&buf[offset] & 1) {
|
||||
return (buf[offset + 1] << 8) | buf[offset];
|
||||
}
|
||||
return PF_SWAP_16(*(pf_u16*)&buf[(offset + 1) & ~1]);
|
||||
}
|
||||
|
||||
void pdm_bpb_CalcBPBFields(PF_VOLUME* p_vol) {
|
||||
pf_u32 num_data_sectors;
|
||||
pf_u16 val;
|
||||
p_vol->bpb.log2_bytes_per_sector = 0;
|
||||
val = p_vol->bpb.bytes_per_sector;
|
||||
while (val >>= 1) { p_vol->bpb.log2_bytes_per_sector++; }
|
||||
p_vol->bpb.log2_sectors_per_cluster = 0;
|
||||
val = p_vol->bpb.sectors_per_cluster;
|
||||
while (val >>= 1) { p_vol->bpb.log2_sectors_per_cluster++; }
|
||||
p_vol->bpb.num_root_dir_sectors = ((p_vol->bpb.num_root_dir_entries << 5) + (p_vol->bpb.bytes_per_sector - 1)) >> p_vol->bpb.log2_bytes_per_sector;
|
||||
p_vol->bpb.first_data_sector = (p_vol->bpb.num_FATs * p_vol->bpb.sectors_per_FAT) + (p_vol->bpb.num_root_dir_sectors + p_vol->bpb.num_reserved_sectors);
|
||||
num_data_sectors = p_vol->bpb.total_sectors - p_vol->bpb.first_data_sector;
|
||||
p_vol->bpb.num_clusters = num_data_sectors >> p_vol->bpb.log2_sectors_per_cluster;
|
||||
if (p_vol->bpb.num_clusters < 0xFF5) {
|
||||
p_vol->bpb.fat_type = FAT_12;
|
||||
p_vol->bpb.first_root_dir_sector = p_vol->bpb.num_reserved_sectors + p_vol->bpb.num_FATs * p_vol->bpb.sectors_per_FAT;
|
||||
} else if (p_vol->bpb.num_clusters < 0xFFF5) {
|
||||
p_vol->bpb.fat_type = FAT_16;
|
||||
p_vol->bpb.first_root_dir_sector = p_vol->bpb.num_reserved_sectors + p_vol->bpb.num_FATs * p_vol->bpb.sectors_per_FAT;
|
||||
} else {
|
||||
p_vol->bpb.fat_type = FAT_32;
|
||||
p_vol->bpb.first_root_dir_sector = 0;
|
||||
}
|
||||
}
|
||||
|
||||
pf_s32 pdm_bpb_InitVolumeWithBootSector(PF_VOLUME* p_vol, pf_u8* buf) {
|
||||
pf_u32 total_sectors;
|
||||
pf_s32 err = 0;
|
||||
pf_u32 fat_sectors;
|
||||
pf_u32 version;
|
||||
if (!pdm_part_is_boot_sector(buf)) {
|
||||
err = 3;
|
||||
} else {
|
||||
p_vol->bpb.bytes_per_sector = read_boot_u16(buf, 11);
|
||||
p_vol->bpb.sectors_per_cluster = buf[13];
|
||||
p_vol->bpb.num_reserved_sectors = read_boot_u16(buf, 14);
|
||||
p_vol->bpb.num_FATs = buf[16];
|
||||
p_vol->bpb.num_root_dir_entries = read_boot_u16(buf, 17);
|
||||
p_vol->bpb.media = buf[21];
|
||||
total_sectors = read_boot_u16(buf, 19);
|
||||
p_vol->bpb.total_sectors = total_sectors == 0 ? PF_SWAP_32(*(pf_u32*)&buf[32]) : total_sectors;
|
||||
fat_sectors = read_boot_u16(buf, 22);
|
||||
p_vol->bpb.sectors_per_FAT = fat_sectors == 0 ? PF_SWAP_32(*(pf_u32*)&buf[36]) : fat_sectors;
|
||||
pdm_bpb_CalcBPBFields(p_vol);
|
||||
switch (p_vol->bpb.fat_type) {
|
||||
case FAT_12:
|
||||
case FAT_16:
|
||||
if (fat_sectors == 0) { err = 4; }
|
||||
break;
|
||||
case FAT_32:
|
||||
if (total_sectors != 0 || fat_sectors != 0) { err = 4; }
|
||||
version = read_boot_u16(buf, 42);
|
||||
p_vol->bpb.ext_flags = read_boot_u16(buf, 40);
|
||||
p_vol->bpb.root_dir_cluster = PF_SWAP_32(*(pf_u32*)&buf[44]);
|
||||
p_vol->bpb.fs_info_sector = read_boot_u16(buf, 48);
|
||||
p_vol->bpb.backup_boot_sector = read_boot_u16(buf, 50);
|
||||
p_vol->bpb.first_root_dir_sector = p_vol->bpb.first_data_sector + ((p_vol->bpb.root_dir_cluster - 2) << p_vol->bpb.log2_sectors_per_cluster);
|
||||
if (version != 0) { err = 4; }
|
||||
break;
|
||||
default:
|
||||
err = 4;
|
||||
break;
|
||||
}
|
||||
if (p_vol->bpb.ext_flags & 0x80) {
|
||||
p_vol->bpb.num_active_FATs = 1;
|
||||
p_vol->bpb.active_FAT_sector = p_vol->bpb.num_reserved_sectors + ((p_vol->bpb.ext_flags & 7) * p_vol->bpb.sectors_per_FAT);
|
||||
} else {
|
||||
p_vol->bpb.num_active_FATs = p_vol->bpb.num_FATs;
|
||||
p_vol->bpb.active_FAT_sector = p_vol->bpb.num_reserved_sectors;
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
pf_s32 pdm_bpb_InitVolumeWithFSINFOSector(PF_VOLUME* p_vol, pf_u8* buf, pf_u32* p_free_count, pf_u32* p_next_free) {
|
||||
pf_u32 free_count;
|
||||
pf_u32 next_free;
|
||||
*p_free_count = -1;
|
||||
*p_next_free = -1;
|
||||
if (PF_SWAP_32(*(pf_u32*)&buf[0]) == 0x41615252 && PF_SWAP_32(*(pf_u32*)&buf[484]) == 0x61417272 && PF_SWAP_32(*(pf_u32*)&buf[508]) == 0xAA550000) {
|
||||
free_count = PF_SWAP_32(*(pf_u32*)&buf[488]);
|
||||
next_free = PF_SWAP_32(*(pf_u32*)&buf[492]);
|
||||
if (free_count >= 2 && free_count < p_vol->bpb.num_clusters + 2) { *p_free_count = free_count; }
|
||||
if (next_free >= 2 && next_free < p_vol->bpb.num_clusters + 2) { *p_next_free = next_free; }
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
161
libs/RVL_SDK/src/fa/pdm_disk.c
Normal file
161
libs/RVL_SDK/src/fa/pdm_disk.c
Normal file
@@ -0,0 +1,161 @@
|
||||
#include <private/fa/pdm.h>
|
||||
extern void* pf_memset(void*, pf_u8, pf_u32);
|
||||
PDM_DISK_SET pdm_disk_set;
|
||||
PDM_DISK_TBL pdm_drv_tbl[26];
|
||||
|
||||
pf_s32 pdm_disk_convert_sector_into_block(PDM_DISK* p_disk, pf_u32 start, pf_u32 count, pf_u32 bytes_per_sector, pf_u32* p_start, pf_u32* p_count) {
|
||||
pf_u32 ratio;
|
||||
pf_s32 err = 0;
|
||||
*p_start = start;
|
||||
*p_count = count;
|
||||
if (bytes_per_sector > 512) {
|
||||
ratio = (pf_u16)bytes_per_sector >> 9;
|
||||
if (ratio == 2) { *p_start <<= 1; }
|
||||
else if (ratio == 4) { *p_start <<= 2; }
|
||||
else if (ratio == 8) { *p_start <<= 3; }
|
||||
if (ratio == 2) { *p_count <<= 1; }
|
||||
else if (ratio == 4) { *p_count <<= 2; }
|
||||
else if (ratio == 8) { *p_count <<= 3; }
|
||||
} else if (bytes_per_sector < 512) { err = 4; }
|
||||
return err;
|
||||
}
|
||||
pf_s32 pdm_disk_convert_block_into_sector(PDM_DISK* p_disk, pf_u32 start, pf_u32 count, pf_u32 bytes_per_sector, pf_u32* p_start, pf_u32* p_count) {
|
||||
pf_u32 ratio;
|
||||
pf_s32 err = 0;
|
||||
*p_start = start;
|
||||
*p_count = count;
|
||||
if (bytes_per_sector > 512) {
|
||||
ratio = (pf_u16)bytes_per_sector >> 9;
|
||||
if (ratio == 2) { *p_start >>= 1; }
|
||||
else if (ratio == 4) { *p_start >>= 2; }
|
||||
else if (ratio == 8) { *p_start >>= 3; }
|
||||
if (ratio == 2) { *p_count >>= 1; }
|
||||
else if (ratio == 4) { *p_count >>= 2; }
|
||||
else if (ratio == 8) { *p_count >>= 3; }
|
||||
} else if (bytes_per_sector < 512) { err = 4; }
|
||||
return err;
|
||||
}
|
||||
pf_s32 pdm_disk_init_disk_manager(void) {
|
||||
pf_memset(&pdm_disk_set, 0, sizeof(pdm_disk_set));
|
||||
return 0;
|
||||
}
|
||||
pf_s32 pdm_disk_add_disk(PDM_INIT_DISK* p_init_disk_tbl, PDM_DISK** pp_disk) {
|
||||
PDM_DISK_TBL* p_driver;
|
||||
pf_u16 disk_no;
|
||||
PDM_DISK* p_disk;
|
||||
*pp_disk = PF_NULL;
|
||||
if (pdm_disk_set.num_allocated_disk >= 26) { return 8; }
|
||||
for (disk_no = 0; disk_no < 26; disk_no++) {
|
||||
if (!(pdm_disk_set.disk[disk_no].status & 1)) { break; }
|
||||
}
|
||||
if (disk_no >= 26) { return 8; }
|
||||
p_driver = &pdm_drv_tbl[disk_no];
|
||||
p_init_disk_tbl->p_func(p_driver, p_init_disk_tbl->ui_ext);
|
||||
p_disk = &pdm_disk_set.disk[disk_no];
|
||||
p_disk->disk_tbl = *p_driver;
|
||||
p_disk->status |= 1;
|
||||
pdm_disk_set.num_allocated_disk++;
|
||||
*pp_disk = p_disk;
|
||||
return 0;
|
||||
}
|
||||
pf_s32 pdm_disk_del_disk(PDM_DISK* p_disk) {
|
||||
if (p_disk->init_count != 0) { return 16; }
|
||||
if (p_disk->mount_count != 0) { return 17; }
|
||||
p_disk->status &= ~1;
|
||||
pdm_disk_set.num_allocated_disk--;
|
||||
return 0;
|
||||
}
|
||||
pf_s32 pdm_disk_set_disk(PDM_DISK* p_disk, PDM_PARTITION* p_part) {
|
||||
p_disk->p_cur_part = p_part;
|
||||
return 0;
|
||||
}
|
||||
pf_s32 pdm_disk_get_media_attribute(PDM_DISK* p_disk, PDM_DISK_INFO* p_info) {
|
||||
*p_info = p_disk->disk_info;
|
||||
return 0;
|
||||
}
|
||||
pf_s32 pdm_disk_get_media_bps(PDM_DISK* p_disk, pf_u16* p_bps) {
|
||||
*p_bps = p_disk->disk_info.bytes_per_sector;
|
||||
return 0;
|
||||
}
|
||||
pf_s32 pdm_disk_init(PDM_DISK* p_disk) {
|
||||
pf_s32 err;
|
||||
if (p_disk->init_count == 0) {
|
||||
err = p_disk->disk_tbl.p_func->init(p_disk);
|
||||
if (err != 0) { pdm_part_set_driver_error_code(p_disk->p_cur_part, err); return 21; }
|
||||
}
|
||||
p_disk->init_count++;
|
||||
return 0;
|
||||
}
|
||||
pf_s32 pdm_disk_mount(PDM_DISK* p_disk) {
|
||||
pf_s32 err;
|
||||
if (p_disk->mount_count == 0) {
|
||||
err = p_disk->disk_tbl.p_func->mount(p_disk);
|
||||
if (err != 0) { pdm_part_set_driver_error_code(p_disk->p_cur_part, err); return 21; }
|
||||
err = p_disk->disk_tbl.p_func->get_disk_info(p_disk, &p_disk->disk_info);
|
||||
if (err != 0) {
|
||||
pdm_part_set_driver_error_code(p_disk->p_cur_part, err);
|
||||
p_disk->disk_tbl.p_func->unmount(p_disk);
|
||||
return 21;
|
||||
}
|
||||
if (p_disk->disk_info.media_attr & 1) { p_disk->status |= 2; }
|
||||
else { p_disk->status &= ~2; }
|
||||
}
|
||||
p_disk->mount_count++;
|
||||
return 0;
|
||||
}
|
||||
pf_s32 pdm_disk_format(PDM_DISK* p_disk, const pf_u8* param) {
|
||||
pf_s32 err;
|
||||
err = p_disk->disk_tbl.p_func->format(p_disk, param);
|
||||
if (err != 0) { pdm_part_set_driver_error_code(p_disk->p_cur_part, err); return 21; }
|
||||
return 0;
|
||||
}
|
||||
pf_s32 pdm_disk_physical_read(PDM_DISK* p_disk, pf_u8* buf, pf_u32 sector, pf_u32 count, pf_u32 bps, pf_u32* p_success) {
|
||||
pf_s32 err;
|
||||
pf_u32 block;
|
||||
pf_u32 num_blocks;
|
||||
pf_u32 converted_sector;
|
||||
err = pdm_disk_convert_sector_into_block(p_disk, sector, count, bps, &block, &num_blocks);
|
||||
if (err != 0) { return err; }
|
||||
err = p_disk->disk_tbl.p_func->physical_read(p_disk, buf, block, num_blocks, p_success);
|
||||
pdm_disk_convert_block_into_sector(p_disk, block, *p_success, bps, &converted_sector, p_success);
|
||||
if (err != 0) { pdm_part_set_driver_error_code(p_disk->p_cur_part, err); return 21; }
|
||||
return 0;
|
||||
}
|
||||
pf_s32 pdm_disk_physical_write(PDM_DISK* p_disk, const pf_u8* buf, pf_u32 sector, pf_u32 count, pf_u32 bps, pf_u32* p_success) {
|
||||
pf_s32 err;
|
||||
pf_u32 block;
|
||||
pf_u32 num_blocks;
|
||||
pf_u32 converted_sector;
|
||||
err = pdm_disk_convert_sector_into_block(p_disk, sector, count, bps, &block, &num_blocks);
|
||||
if (err != 0) { return err; }
|
||||
err = p_disk->disk_tbl.p_func->physical_write(p_disk, buf, block, num_blocks, p_success);
|
||||
pdm_disk_convert_block_into_sector(p_disk, block, *p_success, bps, &converted_sector, p_success);
|
||||
if (err != 0) { pdm_part_set_driver_error_code(p_disk->p_cur_part, err); return 21; }
|
||||
return 0;
|
||||
}
|
||||
pf_s32 pdm_disk_unmount(PDM_DISK* p_disk, pf_u32 mode) {
|
||||
pf_s32 err = 0;
|
||||
if (p_disk->mount_count == 1) {
|
||||
err = p_disk->disk_tbl.p_func->unmount(p_disk);
|
||||
if (err != 0) { pdm_part_set_driver_error_code(p_disk->p_cur_part, err); err = 21; }
|
||||
} else if (p_disk->mount_count == 0) { return 14; }
|
||||
if (err == 0 || mode == 1) { p_disk->mount_count--; }
|
||||
return err;
|
||||
}
|
||||
pf_s32 pdm_disk_finalize(PDM_DISK* p_disk) {
|
||||
pf_s32 err;
|
||||
if (p_disk->init_count == 1) {
|
||||
err = p_disk->disk_tbl.p_func->finalize(p_disk);
|
||||
if (err != 0) { pdm_part_set_driver_error_code(p_disk->p_cur_part, err); return 21; }
|
||||
} else if (p_disk->init_count == 0) { return 13; }
|
||||
p_disk->init_count--;
|
||||
return 0;
|
||||
}
|
||||
void pdm_disk_notify_media_eject(PDM_DISK* p_disk) {
|
||||
p_disk->status &= ~4;
|
||||
pdm_part_set_change_media_state(p_disk, 0);
|
||||
}
|
||||
void pdm_disk_notify_media_insert(PDM_DISK* p_disk) {
|
||||
p_disk->status |= 4;
|
||||
pdm_part_set_change_media_state(p_disk, 1);
|
||||
}
|
||||
287
libs/RVL_SDK/src/fa/pdm_partition.c
Normal file
287
libs/RVL_SDK/src/fa/pdm_partition.c
Normal file
@@ -0,0 +1,287 @@
|
||||
#include <private/fa/pdm.h>
|
||||
#include <revolution/types.h>
|
||||
#define MBR_WORD(buf, offset) (((pf_u32)(buf)[(offset) + 2] << 16) + (buf)[offset] + (((pf_u32)(buf)[(offset) + 3] << 24) + ((pf_u32)(buf)[(offset) + 1] << 8)))
|
||||
static inline pf_u16 read_boot_u16(pf_u8* buf, pf_u32 offset) {
|
||||
if ((pf_u32)&buf[offset] & 1) { return (buf[offset + 1] << 8) | buf[offset]; }
|
||||
return PF_SWAP_16(*(pf_u16*)&buf[(offset + 1) & ~1]);
|
||||
}
|
||||
|
||||
pf_s32 pdm_part_is_master_boot_sector(pf_u8* buf, pf_u32 total, pf_bool* p_is_mbr) {
|
||||
pf_s16 index;
|
||||
pf_u32 start[4];
|
||||
pf_u32 count[4];
|
||||
*p_is_mbr = 0;
|
||||
if (buf[510] != 0x55 || buf[511] != 0xAA) { return 2; }
|
||||
for (index = 0; index < 4; index++) {
|
||||
start[index] = 0;
|
||||
start[index] = (((pf_u32)buf[456] << 16) + buf[454]) + (((pf_u32)buf[457] << 24) + ((pf_u32)buf[455] << 8));
|
||||
count[index] = (((pf_u32)buf[460] << 16) + buf[458]) + (((pf_u32)buf[461] << 24) + ((pf_u32)buf[459] << 8));
|
||||
if (start[index] != 0 && count[index] != 0) {
|
||||
if (index == 0) { *p_is_mbr = 1; }
|
||||
} else {
|
||||
if (index == 0) { return 2; }
|
||||
}
|
||||
buf += 16;
|
||||
}
|
||||
for (index = 0; index < 4; index++) {
|
||||
if (start[index] + count[index] > total) {
|
||||
if (index == 0) { *p_is_mbr = 0; }
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
pf_bool pdm_part_is_boot_sector(pf_u8* buf) {
|
||||
pf_u16 byte_per_sector;
|
||||
pf_u16 sector_per_cluster;
|
||||
pf_u8 media;
|
||||
pf_bool is_boot;
|
||||
|
||||
is_boot = PF_TRUE;
|
||||
if ((buf[0x00] != 0xEB || buf[0x2] != 0x90) && buf[0x0] != 0xE9) {
|
||||
is_boot = PF_FALSE;
|
||||
}
|
||||
if (buf[0x1FE] != 0x55 || buf[0x1FF] != 0xAA) {
|
||||
is_boot = PF_FALSE;
|
||||
}
|
||||
byte_per_sector = read_boot_u16(buf, 0xB);
|
||||
if (byte_per_sector != 0x200 && byte_per_sector != 0x400 && byte_per_sector != 0x800 && byte_per_sector != 0x1000) {
|
||||
is_boot = PF_FALSE;
|
||||
}
|
||||
sector_per_cluster = buf[0xD];
|
||||
if (sector_per_cluster != 1 && sector_per_cluster != 2 && sector_per_cluster != 4 && sector_per_cluster != 8 && sector_per_cluster != 0x10 &&
|
||||
sector_per_cluster != 0x20 && sector_per_cluster != 0x40 && sector_per_cluster != 0x80) {
|
||||
is_boot = PF_FALSE;
|
||||
}
|
||||
media = buf[0x15];
|
||||
if (media != 0xF0 && media != 0xF8 && media != 0xF9 && media != 0xFA && media != 0xFB && media != 0xFC && media != 0xFD && media != 0xFE &&
|
||||
media != 0xFF) {
|
||||
is_boot = PF_FALSE;
|
||||
}
|
||||
return is_boot;
|
||||
}
|
||||
|
||||
pf_s32 pdm_part_get_start_sector(PDM_PARTITION* p_part) {
|
||||
pf_u32 part_index = 0;
|
||||
pf_u32 requested = p_part->part_id;
|
||||
pf_u32 start[4];
|
||||
pf_u32 count[4];
|
||||
pf_u16 index;
|
||||
pf_u16 extended_index;
|
||||
pf_u32 base;
|
||||
pf_u32 sector;
|
||||
pf_u32 length;
|
||||
pf_bool is_mbr;
|
||||
pf_u32 success;
|
||||
pf_s32 err;
|
||||
pf_u8 buf[512] __attribute__((aligned(32)));
|
||||
p_part->start_sector = 0;
|
||||
p_part->total_sector = p_part->p_disk->disk_info.total_sectors;
|
||||
err = pdm_disk_physical_read(p_part->p_disk, buf, 0, 1, 512, &success);
|
||||
if (err != 0) { return err; }
|
||||
pdm_part_is_master_boot_sector(buf, p_part->p_disk->disk_info.total_sectors, &is_mbr);
|
||||
if (is_mbr) {
|
||||
start[0] = MBR_WORD(buf, 454);
|
||||
start[1] = MBR_WORD(buf, 470);
|
||||
start[2] = MBR_WORD(buf, 486);
|
||||
start[3] = MBR_WORD(buf, 502);
|
||||
count[0] = MBR_WORD(buf, 458);
|
||||
count[1] = MBR_WORD(buf, 474);
|
||||
count[2] = MBR_WORD(buf, 490);
|
||||
count[3] = MBR_WORD(buf, 506);
|
||||
part_index = 0;
|
||||
for (index = 0; index < 4; index++) {
|
||||
sector = start[index];
|
||||
length = count[index];
|
||||
if (sector == 0 || length == 0) { return 7; }
|
||||
err = pdm_disk_physical_read(p_part->p_disk, buf, sector, 1, 512, &success);
|
||||
if (err != 0) { return err; }
|
||||
pdm_part_is_master_boot_sector(buf, p_part->p_disk->disk_info.total_sectors, &is_mbr);
|
||||
if (is_mbr) {
|
||||
base = start[index];
|
||||
sector = base;
|
||||
for (extended_index = 0; extended_index < 2; extended_index++) {
|
||||
if (extended_index == 0) {
|
||||
sector = sector + MBR_WORD(buf, 454);
|
||||
length = MBR_WORD(buf, 458);
|
||||
err = pdm_disk_physical_read(p_part->p_disk, buf, sector, 1, 512, &success);
|
||||
if (err != 0) { return err; }
|
||||
if (requested == part_index) { p_part->start_sector = sector; p_part->total_sector = length; return 0; }
|
||||
part_index++;
|
||||
} else {
|
||||
sector = base + MBR_WORD(buf, 470);
|
||||
length = MBR_WORD(buf, 474);
|
||||
if (sector == 0 || length == 0) { break; }
|
||||
err = pdm_disk_physical_read(p_part->p_disk, buf, sector, 1, 512, &success);
|
||||
if (err != 0) { return err; }
|
||||
pdm_part_is_master_boot_sector(buf, p_part->p_disk->disk_info.total_sectors, &is_mbr);
|
||||
if (!is_mbr) { break; }
|
||||
extended_index = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (requested == part_index) { p_part->start_sector = sector; p_part->total_sector = length; break; }
|
||||
part_index++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (requested >= 2) { return 7; }
|
||||
p_part->start_sector = part_index;
|
||||
p_part->total_sector = p_part->p_disk->disk_info.total_sectors;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
pf_u32 pdm_part_chg_ltop(PDM_PARTITION* p_part, pf_u32 sector, pf_u32 bps) {
|
||||
pf_u16 media_bps;
|
||||
pf_u32 ratio;
|
||||
pf_u32 start;
|
||||
pdm_disk_get_media_bps(p_part->p_disk, &media_bps);
|
||||
if (bps == media_bps) { return sector + p_part->start_sector; }
|
||||
start = p_part->start_sector;
|
||||
ratio = media_bps >> 9;
|
||||
if (ratio == 2) { start <<= 1; }
|
||||
else if (ratio == 4) { start <<= 2; }
|
||||
else if (ratio == 8) { start <<= 3; }
|
||||
ratio = (pf_u16)bps >> 9;
|
||||
if (ratio == 2) { start >>= 1; }
|
||||
else if (ratio == 4) { start >>= 2; }
|
||||
else if (ratio == 8) { start >>= 3; }
|
||||
return sector + start;
|
||||
}
|
||||
pf_s32 pdm_part_get_partition(PDM_DISK* p_disk, pf_u32 id, PDM_PARTITION** pp_part) {
|
||||
pf_s32 err;
|
||||
pf_u16 index;
|
||||
*pp_part = PF_NULL;
|
||||
if (pdm_disk_set.num_partition >= 26) { return 10; }
|
||||
for (index = 0; index < 26; index++) {
|
||||
if (!(pdm_disk_set.partition[index].status & 1)) { break; }
|
||||
}
|
||||
if (index == 26) { return 10; }
|
||||
err = pdm_disk_set_disk(p_disk, &pdm_disk_set.partition[index]);
|
||||
if (err != 0) { return err; }
|
||||
pdm_disk_set.num_partition++;
|
||||
pdm_disk_set.partition[index].status |= 1;
|
||||
pdm_disk_set.partition[index].p_disk = p_disk;
|
||||
pdm_disk_set.partition[index].part_id = id;
|
||||
*pp_part = &pdm_disk_set.partition[index];
|
||||
return 0;
|
||||
}
|
||||
pf_s32 pdm_part_release_partition(PDM_PARTITION* p_part) {
|
||||
p_part->status &= ~1;
|
||||
pdm_disk_set.num_partition--;
|
||||
return 0;
|
||||
}
|
||||
pf_bool pdm_part_is_attached_partition(PDM_PARTITION* p_part) { return (p_part->status >> 2) & 1; }
|
||||
void pdm_part_set_driver_error_code(PDM_PARTITION* p_part, pf_s32 err) { p_part->driver_last_error = err; }
|
||||
pf_s32 pdm_part_get_driver_error_code(PDM_PARTITION* p_part) { return p_part->driver_last_error; }
|
||||
pf_s32 pdm_part_get_media_attribute(PDM_PARTITION* p_part, PDM_DISK_INFO* p_info) {
|
||||
pf_s32 err = pdm_disk_get_media_attribute(p_part->p_disk, p_info);
|
||||
if (err != 0) { return err; }
|
||||
return 0;
|
||||
}
|
||||
pf_s32 pdm_part_init(PDM_PARTITION* p_part) {
|
||||
pf_s32 err;
|
||||
if (!(p_part->status & 4)) {
|
||||
err = pdm_disk_set_disk(p_part->p_disk, p_part);
|
||||
if (err != 0) { return err; }
|
||||
err = pdm_disk_init(p_part->p_disk);
|
||||
if (err != 0) { return err; }
|
||||
} else { return 11; }
|
||||
p_part->status |= 4;
|
||||
return 0;
|
||||
}
|
||||
pf_s32 pdm_part_mount(PDM_PARTITION* p_part) {
|
||||
pf_s32 err;
|
||||
if (!(p_part->status & 8)) {
|
||||
err = pdm_disk_set_disk(p_part->p_disk, p_part);
|
||||
if (err != 0) { return err; }
|
||||
err = pdm_disk_mount(p_part->p_disk);
|
||||
if (err != 0) { return err; }
|
||||
err = pdm_part_get_start_sector(p_part);
|
||||
if (err != 0) { pdm_disk_unmount(p_part->p_disk, 0); return err; }
|
||||
} else { return 12; }
|
||||
p_part->status &= ~2;
|
||||
p_part->status |= 8;
|
||||
return 0;
|
||||
}
|
||||
pf_s32 pdm_part_format(PDM_PARTITION* p_part, const pf_u8* param) {
|
||||
pf_s32 err;
|
||||
err = pdm_disk_set_disk(p_part->p_disk, p_part);
|
||||
if (err != 0) { return err; }
|
||||
err = pdm_disk_format(p_part->p_disk, param);
|
||||
if (err != 0) { return err; }
|
||||
return 0;
|
||||
}
|
||||
pf_s32 pdm_part_logical_read(PDM_PARTITION* p_part, pf_u8* buf, pf_u32 sector, pf_u32 count, pf_u32 bps, pf_u32* p_success) {
|
||||
pf_s32 err;
|
||||
pf_u32 physical_sector;
|
||||
if ((p_part->status & 8) != 8 || (p_part->status & 2) == 2) { return 15; }
|
||||
err = pdm_disk_set_disk(p_part->p_disk, p_part);
|
||||
if (err != 0) { return err; }
|
||||
if (p_part->total_sector <= sector) { return 18; }
|
||||
if (p_part->total_sector < sector + count) { count -= (sector + count) - p_part->total_sector; }
|
||||
physical_sector = pdm_part_chg_ltop(p_part, sector, bps);
|
||||
err = pdm_disk_physical_read(p_part->p_disk, buf, physical_sector, count, bps, p_success);
|
||||
if (err != 0) { return err; }
|
||||
return 0;
|
||||
}
|
||||
pf_s32 pdm_part_logical_write(PDM_PARTITION* p_part, const pf_u8* buf, pf_u32 sector, pf_u32 count, pf_u32 bps, pf_u32* p_success) {
|
||||
pf_s32 err;
|
||||
pf_u32 physical_sector;
|
||||
if ((p_part->status & 8) != 8 || (p_part->status & 2) == 2) { return 15; }
|
||||
err = pdm_disk_set_disk(p_part->p_disk, p_part);
|
||||
if (err != 0) { return err; }
|
||||
if (p_part->total_sector <= sector) { return 18; }
|
||||
if (p_part->total_sector < sector + count) { count -= (sector + count) - p_part->total_sector; }
|
||||
physical_sector = pdm_part_chg_ltop(p_part, sector, bps);
|
||||
err = pdm_disk_physical_write(p_part->p_disk, buf, physical_sector, count, bps, p_success);
|
||||
if (err != 0) { return err; }
|
||||
return 0;
|
||||
}
|
||||
pf_s32 pdm_part_unmount(PDM_PARTITION* p_part, pf_u32 mode) {
|
||||
pf_s32 err;
|
||||
pf_s32 result = 0;
|
||||
if (p_part->status & 8) {
|
||||
err = pdm_disk_set_disk(p_part->p_disk, p_part);
|
||||
if (err != 0) { return err; }
|
||||
err = pdm_disk_unmount(p_part->p_disk, mode);
|
||||
if (err != 0) { result = err; }
|
||||
} else { result = 14; }
|
||||
if (result == 0 || mode == 1) { p_part->status &= ~2; p_part->status &= ~8; }
|
||||
return result;
|
||||
}
|
||||
pf_s32 pdm_part_finalize(PDM_PARTITION* p_part) {
|
||||
pf_s32 err;
|
||||
if (p_part->status & 4) {
|
||||
err = pdm_disk_set_disk(p_part->p_disk, p_part);
|
||||
if (err != 0) { return err; }
|
||||
err = pdm_disk_finalize(p_part->p_disk);
|
||||
if (err != 0) { return err; }
|
||||
} else { return 13; }
|
||||
p_part->status &= ~4;
|
||||
return 0;
|
||||
}
|
||||
pf_s32 pdm_part_register_callback(PDM_PARTITION* p_part, PDM_CALLBACK* callbacks) {
|
||||
p_part->callbacks.insert = callbacks->insert;
|
||||
p_part->callbacks.eject = callbacks->eject;
|
||||
return 0;
|
||||
}
|
||||
pf_s32 pdm_part_unregister_callback(PDM_PARTITION* p_part) {
|
||||
p_part->callbacks.insert = PF_NULL;
|
||||
p_part->callbacks.eject = PF_NULL;
|
||||
return 0;
|
||||
}
|
||||
void pdm_part_set_change_media_state(PDM_DISK* p_disk, pf_bool is_inserted) {
|
||||
pf_u16 index;
|
||||
for (index = 0; index < 26; index++) {
|
||||
if ((pdm_disk_set.partition[index].status & 1) && pdm_disk_set.partition[index].p_disk == p_disk) {
|
||||
PDM_PARTITION* p_part = &pdm_disk_set.partition[index];
|
||||
p_part->status |= 2;
|
||||
if (is_inserted == 0 && pdm_disk_set.partition[index].callbacks.eject != PF_NULL) {
|
||||
pdm_disk_set.partition[index].callbacks.eject(p_part);
|
||||
} else if (pdm_disk_set.partition[index].callbacks.insert != PF_NULL) {
|
||||
pdm_disk_set.partition[index].callbacks.insert(p_part);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
29
libs/RVL_SDK/src/fa/pf_attach.c
Normal file
29
libs/RVL_SDK/src/fa/pf_attach.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <private/vf/PrFILE2/pf_types.h>
|
||||
#include <private/vf/PrFILE2/driver/pf_driver.h>
|
||||
|
||||
typedef struct PFATTACH_NOTIFY {
|
||||
pf_u8 driver_state[0x50];
|
||||
void* callback_data;
|
||||
} PFATTACH_NOTIFY;
|
||||
typedef struct PFATTACH_GLOBAL {
|
||||
pf_u8 volume_state[0x40];
|
||||
pf_s32 last_error;
|
||||
} PFATTACH_GLOBAL;
|
||||
extern PFATTACH_GLOBAL pf_vol_set;
|
||||
extern pf_s32 PFVOL_attach(PF_DRV_TBL*, PFATTACH_NOTIFY*, void*);
|
||||
extern pf_s32 PFAPI_convertReturnValue(pf_s32);
|
||||
|
||||
pf_int32 pf2_attach(PF_DRV_TBL** drv_tbl, PFATTACH_NOTIFY* notify) {
|
||||
pf_s32 err;
|
||||
if (drv_tbl == PF_NULL || !*drv_tbl) {
|
||||
err = 10;
|
||||
pf_vol_set.last_error = 10;
|
||||
} else {
|
||||
for (; *drv_tbl != PF_NULL; drv_tbl++) {
|
||||
if (notify != PF_NULL) err = PFVOL_attach(*drv_tbl, notify, notify->callback_data);
|
||||
else err = PFVOL_attach(*drv_tbl, PF_NULL, PF_NULL);
|
||||
if (err != 0) return PFAPI_convertReturnValue(err);
|
||||
}
|
||||
}
|
||||
return PFAPI_convertReturnValue(err);
|
||||
}
|
||||
986
libs/RVL_SDK/src/fa/pf_cache.c
Normal file
986
libs/RVL_SDK/src/fa/pf_cache.c
Normal file
@@ -0,0 +1,986 @@
|
||||
#include <private/vf/PrFILE2/fatfs/pf_cache.h>
|
||||
|
||||
typedef struct PFCACHE_BPB {
|
||||
pf_u16 bytes_per_sector;
|
||||
pf_u16 num_reserved_sectors;
|
||||
pf_u16 num_root_dir_entries;
|
||||
pf_u8 sectors_per_cluster;
|
||||
pf_u8 num_FATs;
|
||||
pf_u32 total_sectors;
|
||||
pf_u32 sectors_per_FAT;
|
||||
pf_u32 root_dir_cluster;
|
||||
pf_u16 fs_info_sector;
|
||||
pf_u16 backup_boot_sector;
|
||||
pf_u16 ext_flags;
|
||||
pf_u8 media;
|
||||
pf_s32 fat_type;
|
||||
pf_u8 log2_bytes_per_sector;
|
||||
pf_u8 log2_sectors_per_cluster;
|
||||
pf_u8 num_active_FATs;
|
||||
pf_u16 num_root_dir_sectors;
|
||||
pf_u32 active_FAT_sector;
|
||||
pf_u32 first_root_dir_sector;
|
||||
pf_u32 first_data_sector;
|
||||
pf_u32 num_clusters;
|
||||
} PFCACHE_BPB;
|
||||
|
||||
struct PF_VOLUME {
|
||||
PFCACHE_BPB bpb;
|
||||
pf_u32 num_free_clusters;
|
||||
pf_u32 last_free_cluster;
|
||||
pf_u8 file_and_directory_state[0x1624 - 0x40];
|
||||
PF_SECTOR_CACHE cache;
|
||||
};
|
||||
|
||||
enum { FAT_32 = 2 };
|
||||
|
||||
extern void* pf_memcpy(void* dest, const void* src, pf_u32 size);
|
||||
extern void* pf_memset(void* dest, pf_s32 value, pf_u32 size);
|
||||
extern pf_s32 PFDRV_lread(PF_VOLUME* p_vol, pf_u8* buffer, pf_u32 sector, pf_u32 num_sector, pf_u32* p_num_success);
|
||||
extern pf_s32 PFDRV_lwrite(PF_VOLUME* p_vol, const pf_u8* buffer, pf_u32 sector, pf_u32 num_sector, pf_u32* p_num_success);
|
||||
pf_s32 PFCACHE_FlushAllCaches(PF_VOLUME* p_vol);
|
||||
|
||||
#pragma dont_inline on
|
||||
pf_s32 PFCACHE_InitPageList(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_head, PF_CACHE_PAGE* pages, PF_CACHE_BUFFER* buffers, pf_u32 num,
|
||||
pf_u32 size, pf_bool is_fat) {
|
||||
pf_u32 i;
|
||||
pf_u32 bps_per_buf;
|
||||
*pp_head = pages;
|
||||
bps_per_buf = (p_vol->bpb.bytes_per_sector >> 9) * size;
|
||||
if ((num / bps_per_buf) == 0) {
|
||||
return 30;
|
||||
}
|
||||
if ((num / bps_per_buf) == 1) {
|
||||
pages->p_prev = pages;
|
||||
pages->p_next = pages;
|
||||
pages->buffer = *buffers;
|
||||
pages->p_buf = *buffers;
|
||||
pages->p_mod_sbuf = PF_NULL;
|
||||
pages->p_mod_ebuf = PF_NULL;
|
||||
pages->size = size;
|
||||
pages->sector = 0xFFFFFFFF;
|
||||
pages->option = 0;
|
||||
pages->signature = PF_NULL;
|
||||
pages->stat &= ~(0x01 | 0x02);
|
||||
if (is_fat) {
|
||||
pages->stat |= 0x04;
|
||||
} else {
|
||||
pages->stat &= ~0x04;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
pages->p_prev = &pages[(num - (num % bps_per_buf)) - bps_per_buf];
|
||||
pages->p_next = &pages[bps_per_buf];
|
||||
pages->buffer = *buffers;
|
||||
pages->p_buf = *buffers;
|
||||
pages->p_mod_sbuf = PF_NULL;
|
||||
pages->p_mod_ebuf = PF_NULL;
|
||||
pages->size = size;
|
||||
pages->sector = 0xFFFFFFFF;
|
||||
pages->option = 0;
|
||||
pages->signature = PF_NULL;
|
||||
pages->stat &= ~(0x01 | 0x02);
|
||||
if (is_fat) {
|
||||
pages->stat |= 0x04;
|
||||
} else {
|
||||
pages->stat &= ~0x04;
|
||||
}
|
||||
for (i = bps_per_buf; i < (num - (num % bps_per_buf) - bps_per_buf); i += bps_per_buf) {
|
||||
pages[i].p_prev = &pages[i - bps_per_buf];
|
||||
pages[i].p_next = &pages[i + bps_per_buf];
|
||||
pages[i].buffer = buffers[i];
|
||||
pages[i].p_buf = buffers[i];
|
||||
pages[i].p_mod_sbuf = PF_NULL;
|
||||
pages[i].p_mod_ebuf = PF_NULL;
|
||||
pages[i].size = size;
|
||||
pages[i].sector = 0xFFFFFFFF;
|
||||
pages[i].option = 0;
|
||||
pages[i].signature = PF_NULL;
|
||||
pages[i].stat &= ~(0x01 | 0x02);
|
||||
if (is_fat) {
|
||||
pages[i].stat |= 0x04;
|
||||
} else {
|
||||
pages[i].stat &= ~0x04;
|
||||
}
|
||||
}
|
||||
pages[(num - (num % bps_per_buf)) - bps_per_buf].p_prev = &pages[((num - (num % bps_per_buf)) - bps_per_buf) - bps_per_buf];
|
||||
pages[(num - (num % bps_per_buf)) - bps_per_buf].p_next = pages;
|
||||
pages[(num - (num % bps_per_buf)) - bps_per_buf].buffer = buffers[(num - (num % bps_per_buf)) - bps_per_buf];
|
||||
pages[(num - (num % bps_per_buf)) - bps_per_buf].p_buf = buffers[(num - (num % bps_per_buf)) - bps_per_buf];
|
||||
pages[(num - (num % bps_per_buf)) - bps_per_buf].p_mod_sbuf = PF_NULL;
|
||||
pages[(num - (num % bps_per_buf)) - bps_per_buf].p_mod_ebuf = PF_NULL;
|
||||
pages[(num - (num % bps_per_buf)) - bps_per_buf].size = size;
|
||||
pages[(num - (num % bps_per_buf)) - bps_per_buf].sector = 0xFFFFFFFF;
|
||||
pages[(num - (num % bps_per_buf)) - bps_per_buf].option = 0;
|
||||
pages[(num - (num % bps_per_buf)) - bps_per_buf].signature = PF_NULL;
|
||||
pages[(num - (num % bps_per_buf)) - bps_per_buf].stat &= ~(0x01 | 0x02);
|
||||
if (is_fat) {
|
||||
pages[(num - (num % bps_per_buf)) - bps_per_buf].stat |= 0x04;
|
||||
} else {
|
||||
pages[(num - (num % bps_per_buf)) - bps_per_buf].stat &= ~0x04;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#pragma dont_inline reset
|
||||
|
||||
#pragma dont_inline on
|
||||
PF_CACHE_PAGE* PFCACHE_SearchForPage(PF_VOLUME* p_vol, PF_CACHE_PAGE* p_head, pf_u32 sector) {
|
||||
PF_CACHE_PAGE* p_page;
|
||||
if (sector == 0xFFFFFFFF) {
|
||||
return PF_NULL;
|
||||
}
|
||||
if ((p_head->stat & 1) == 0) {
|
||||
return PF_NULL;
|
||||
}
|
||||
if (p_head->sector <= sector && p_head->sector + p_head->size - 1 >= sector) {
|
||||
p_head->p_buf = &p_head->buffer[(sector - p_head->sector) << p_vol->bpb.log2_bytes_per_sector];
|
||||
return p_head;
|
||||
}
|
||||
for (p_page = p_head->p_next; p_page != p_head; p_page = p_page->p_next) {
|
||||
if ((p_page->stat & 1) == 0) {
|
||||
return PF_NULL;
|
||||
}
|
||||
if (p_page->sector <= sector && p_page->sector + p_page->size - 1 >= sector) {
|
||||
p_page->p_buf = &p_page->buffer[(sector - p_page->sector) << p_vol->bpb.log2_bytes_per_sector];
|
||||
return p_page;
|
||||
}
|
||||
}
|
||||
return PF_NULL;
|
||||
}
|
||||
|
||||
#pragma dont_inline reset
|
||||
|
||||
#pragma dont_inline on
|
||||
pf_bool PFCACHE_SearchForFreePage(PF_CACHE_PAGE* p_head, PF_CACHE_PAGE** pp_page) {
|
||||
PF_CACHE_PAGE* p_page;
|
||||
for (p_page = p_head->p_prev; p_page != p_head; p_page = p_page->p_prev) {
|
||||
if ((p_page->stat & 1) == 0) {
|
||||
*pp_page = p_page;
|
||||
return PF_TRUE;
|
||||
}
|
||||
if (p_page->sector != 0xFFFFFFFF) {
|
||||
*pp_page = p_page;
|
||||
return PF_FALSE;
|
||||
}
|
||||
}
|
||||
if ((p_page->stat & 1) == 0) {
|
||||
*pp_page = p_page;
|
||||
return PF_TRUE;
|
||||
}
|
||||
if (p_page->sector != 0xFFFFFFFF) {
|
||||
*pp_page = p_page;
|
||||
return PF_FALSE;
|
||||
}
|
||||
*pp_page = PF_NULL;
|
||||
return PF_FALSE;
|
||||
}
|
||||
|
||||
#pragma dont_inline reset
|
||||
|
||||
#pragma dont_inline on
|
||||
pf_s32 PFCACHE_FlushPageIfNeeded(PF_VOLUME* p_vol, PF_CACHE_PAGE* p_page) {
|
||||
pf_s32 err;
|
||||
pf_u32 num_success;
|
||||
pf_u32 size;
|
||||
if (p_page != PF_NULL && (p_page->stat & 0x02) != 0 && p_page->sector != 0xFFFFFFFF) {
|
||||
if (p_page->p_mod_sbuf == PF_NULL) {
|
||||
size = p_page->size;
|
||||
err = PFDRV_lwrite(p_vol, p_page->buffer, p_page->sector, size, &num_success);
|
||||
} else {
|
||||
size = (((pf_u32)p_page->p_mod_ebuf >> p_vol->bpb.log2_bytes_per_sector) -
|
||||
((pf_u32)p_page->p_mod_sbuf >> p_vol->bpb.log2_bytes_per_sector)) + 1;
|
||||
err = PFDRV_lwrite(p_vol, p_page->p_mod_sbuf,
|
||||
p_page->sector + ((pf_u32)(p_page->p_mod_sbuf - p_page->buffer) >> p_vol->bpb.log2_bytes_per_sector),
|
||||
size, &num_success);
|
||||
}
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
if (num_success != size) {
|
||||
return 17;
|
||||
}
|
||||
p_page->p_mod_sbuf = NULL;
|
||||
p_page->p_mod_ebuf = NULL;
|
||||
p_page->stat &= ~2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#pragma dont_inline reset
|
||||
|
||||
#pragma dont_inline on
|
||||
pf_s32 PFCACHE_DoAllocatePage(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_head, pf_u32 sector, PF_CACHE_PAGE** pp_page, pf_bool* p_is_hit) {
|
||||
pf_s32 err;
|
||||
*pp_page = PFCACHE_SearchForPage(p_vol, *pp_head, sector);
|
||||
if (*pp_page != PF_NULL) {
|
||||
*p_is_hit = PF_TRUE;
|
||||
} else {
|
||||
*p_is_hit = PF_FALSE;
|
||||
if (PFCACHE_SearchForFreePage(*pp_head, pp_page) == 0) {
|
||||
if (*pp_page == 0) {
|
||||
*pp_page = PF_NULL;
|
||||
return 30;
|
||||
}
|
||||
err = PFCACHE_FlushPageIfNeeded(p_vol, *pp_page);
|
||||
if (err != 0) {
|
||||
*pp_page = PF_NULL;
|
||||
return err;
|
||||
}
|
||||
(*pp_page)->p_mod_sbuf = NULL;
|
||||
(*pp_page)->p_mod_ebuf = NULL;
|
||||
}
|
||||
if (sector != 0xFFFFFFFF) {
|
||||
if (((*pp_page)->stat & 0x04) != 0) {
|
||||
(*pp_page)->sector = sector - (sector % (*pp_page)->size);
|
||||
(*pp_page)->p_buf = &(*pp_page)->buffer[(sector % (*pp_page)->size) << p_vol->bpb.log2_bytes_per_sector];
|
||||
} else {
|
||||
if (p_vol->bpb.fat_type == FAT_32 && (sector < p_vol->bpb.first_data_sector || sector >= p_vol->bpb.total_sectors)) {
|
||||
if (sector == p_vol->bpb.fs_info_sector) {
|
||||
(*pp_page)->size = 1;
|
||||
}
|
||||
}
|
||||
(*pp_page)->sector = sector - (sector % (*pp_page)->size);
|
||||
(*pp_page)->p_buf = &(*pp_page)->buffer[(sector % (*pp_page)->size) << p_vol->bpb.log2_bytes_per_sector];
|
||||
}
|
||||
} else {
|
||||
(*pp_page)->sector = sector;
|
||||
(*pp_page)->p_buf = (*pp_page)->buffer;
|
||||
}
|
||||
(*pp_page)->stat |= 0x01;
|
||||
}
|
||||
{
|
||||
PF_CACHE_PAGE* p_page = *pp_page;
|
||||
if (p_page != *pp_head) {
|
||||
if (p_page == (*pp_head)->p_prev) {
|
||||
*pp_head = p_page;
|
||||
} else {
|
||||
p_page->p_prev->p_next = p_page->p_next;
|
||||
p_page->p_next->p_prev = p_page->p_prev;
|
||||
p_page->p_next = *pp_head;
|
||||
p_page->p_prev = (*pp_head)->p_prev;
|
||||
p_page->p_next->p_prev = p_page;
|
||||
p_page->p_prev->p_next = p_page;
|
||||
*pp_head = p_page;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#pragma dont_inline reset
|
||||
|
||||
#pragma dont_inline on
|
||||
pf_s32 PFCACHE_DoReadPage(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_head, pf_u32 sector, PF_CACHE_PAGE** pp_page, pf_bool set_sig) {
|
||||
pf_u32 num_success;
|
||||
pf_bool is_hit;
|
||||
pf_s32 err;
|
||||
err = PFCACHE_DoAllocatePage(p_vol, pp_head, sector, pp_page, &is_hit);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
if (!is_hit) {
|
||||
err = PFDRV_lread(p_vol, (*pp_page)->buffer, (*pp_page)->sector, (*pp_page)->size, &num_success);
|
||||
if (err != 0) {
|
||||
{
|
||||
PF_CACHE_PAGE* p_page = *pp_page;
|
||||
p_page->stat &= ~3;
|
||||
p_page->p_mod_sbuf = NULL;
|
||||
p_page->p_mod_ebuf = NULL;
|
||||
p_page->sector = 0xFFFFFFFF;
|
||||
p_page->signature = PF_NULL;
|
||||
if (p_page == *pp_head) {
|
||||
*pp_head = p_page->p_next;
|
||||
} else if (p_page != (*pp_head)->p_prev) {
|
||||
p_page->p_prev->p_next = p_page->p_next;
|
||||
p_page->p_next->p_prev = p_page->p_prev;
|
||||
p_page->p_next = *pp_head;
|
||||
p_page->p_prev = (*pp_head)->p_prev;
|
||||
p_page->p_next->p_prev = p_page;
|
||||
p_page->p_prev->p_next = p_page;
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
if (num_success != (*pp_page)->size && p_vol->bpb.total_sectors != ((*pp_page)->sector + num_success)) {
|
||||
{
|
||||
PF_CACHE_PAGE* p_page = *pp_page;
|
||||
p_page->stat &= ~3;
|
||||
p_page->p_mod_sbuf = NULL;
|
||||
p_page->p_mod_ebuf = NULL;
|
||||
p_page->sector = 0xFFFFFFFF;
|
||||
p_page->signature = PF_NULL;
|
||||
if (p_page == *pp_head) {
|
||||
*pp_head = p_page->p_next;
|
||||
} else if (p_page != (*pp_head)->p_prev) {
|
||||
p_page->p_prev->p_next = p_page->p_next;
|
||||
p_page->p_next->p_prev = p_page->p_prev;
|
||||
p_page->p_next = *pp_head;
|
||||
p_page->p_prev = (*pp_head)->p_prev;
|
||||
p_page->p_next->p_prev = p_page;
|
||||
p_page->p_prev->p_next = p_page;
|
||||
}
|
||||
}
|
||||
return 17;
|
||||
}
|
||||
(*pp_page)->stat &= ~2;
|
||||
(*pp_page)->p_mod_sbuf = NULL;
|
||||
(*pp_page)->p_mod_ebuf = NULL;
|
||||
if (set_sig) {
|
||||
(*pp_page)->signature = p_vol->cache.signature;
|
||||
} else {
|
||||
(*pp_page)->signature = PF_NULL;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#pragma dont_inline reset
|
||||
|
||||
#pragma dont_inline on
|
||||
pf_s32 PFCACHE_DoReadPageAndFlushIfNeeded(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_head, pf_u32 sector, PF_CACHE_PAGE** pp_page,
|
||||
pf_bool set_sig) {
|
||||
pf_u32 num_success;
|
||||
pf_bool is_hit;
|
||||
pf_s32 err;
|
||||
err = PFCACHE_DoAllocatePage(p_vol, pp_head, sector, pp_page, &is_hit);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
if (!is_hit) {
|
||||
err = PFDRV_lread(p_vol, (*pp_page)->buffer, (*pp_page)->sector, (*pp_page)->size, &num_success);
|
||||
if (err != 0) {
|
||||
{
|
||||
PF_CACHE_PAGE* p_page = *pp_page;
|
||||
p_page->stat &= ~3;
|
||||
p_page->p_mod_sbuf = NULL;
|
||||
p_page->p_mod_ebuf = NULL;
|
||||
p_page->sector = 0xFFFFFFFF;
|
||||
p_page->signature = PF_NULL;
|
||||
if (p_page == *pp_head) {
|
||||
*pp_head = p_page->p_next;
|
||||
} else if (p_page != (*pp_head)->p_prev) {
|
||||
p_page->p_prev->p_next = p_page->p_next;
|
||||
p_page->p_next->p_prev = p_page->p_prev;
|
||||
p_page->p_next = *pp_head;
|
||||
p_page->p_prev = (*pp_head)->p_prev;
|
||||
p_page->p_next->p_prev = p_page;
|
||||
p_page->p_prev->p_next = p_page;
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
if (num_success != (*pp_page)->size && p_vol->bpb.total_sectors != ((*pp_page)->sector + num_success)) {
|
||||
{
|
||||
PF_CACHE_PAGE* p_page = *pp_page;
|
||||
p_page->stat &= ~3;
|
||||
p_page->p_mod_sbuf = NULL;
|
||||
p_page->p_mod_ebuf = NULL;
|
||||
p_page->sector = 0xFFFFFFFF;
|
||||
p_page->signature = PF_NULL;
|
||||
if (p_page == *pp_head) {
|
||||
*pp_head = p_page->p_next;
|
||||
} else if (p_page != (*pp_head)->p_prev) {
|
||||
p_page->p_prev->p_next = p_page->p_next;
|
||||
p_page->p_next->p_prev = p_page->p_prev;
|
||||
p_page->p_next = *pp_head;
|
||||
p_page->p_prev = (*pp_head)->p_prev;
|
||||
p_page->p_next->p_prev = p_page;
|
||||
p_page->p_prev->p_next = p_page;
|
||||
}
|
||||
}
|
||||
return 17;
|
||||
}
|
||||
(*pp_page)->stat &= ~2;
|
||||
(*pp_page)->p_mod_sbuf = NULL;
|
||||
(*pp_page)->p_mod_ebuf = NULL;
|
||||
if (set_sig) {
|
||||
(*pp_page)->signature = p_vol->cache.signature;
|
||||
} else {
|
||||
(*pp_page)->signature = PF_NULL;
|
||||
}
|
||||
} else if (set_sig && ((*pp_page)->stat & 0x02) != 0 && (p_vol->cache.mode & 0x02) != 0 && (*pp_page)->signature != p_vol->cache.signature) {
|
||||
err = PFCACHE_FlushPageIfNeeded(p_vol, *pp_page);
|
||||
if (err != 0) {
|
||||
*pp_page = PF_NULL;
|
||||
return err;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#pragma dont_inline reset
|
||||
|
||||
#pragma dont_inline on
|
||||
pf_s32 PFCACHE_DoReadNumSector(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_head, pf_u8* p_buf, pf_u32 sector, pf_u32 num_sector,
|
||||
pf_u32* p_num_success) {
|
||||
PF_CACHE_PAGE* p_page;
|
||||
pf_s32 err;
|
||||
pf_u32 num_rest_sector;
|
||||
pf_u32 num_success_sector;
|
||||
*p_num_success = 0;
|
||||
err = PFDRV_lread(p_vol, p_buf, sector, num_sector, p_num_success);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
p_page = PF_NULL;
|
||||
num_rest_sector = *p_num_success;
|
||||
num_success_sector = *p_num_success;
|
||||
do {
|
||||
if (p_page == PF_NULL) {
|
||||
p_page = *pp_head;
|
||||
} else {
|
||||
p_page = p_page->p_next;
|
||||
if (p_page == *pp_head) {
|
||||
p_page = PF_NULL;
|
||||
goto found_page;
|
||||
}
|
||||
}
|
||||
for (; (p_page->stat & 1) != 0; p_page = p_page->p_next) {
|
||||
if (p_page->sector != 0xFFFFFFFF) {
|
||||
p_page->p_buf = p_page->buffer;
|
||||
goto found_page;
|
||||
}
|
||||
}
|
||||
p_page = PF_NULL;
|
||||
found_page:
|
||||
if (p_page != PF_NULL && p_page->sector != 0xFFFFFFFF) {
|
||||
if (p_page->sector <= sector && p_page->sector + p_page->size >= sector + num_success_sector) {
|
||||
pf_memcpy(p_buf, &p_page->buffer[(sector - p_page->sector) << p_vol->bpb.log2_bytes_per_sector],
|
||||
num_success_sector << p_vol->bpb.log2_bytes_per_sector);
|
||||
num_rest_sector -= num_success_sector;
|
||||
} else if (p_page->sector >= sector && p_page->sector + p_page->size <= sector + num_success_sector) {
|
||||
pf_memcpy(&p_buf[(p_page->sector - sector) << p_vol->bpb.log2_bytes_per_sector], p_page->buffer,
|
||||
p_page->size << p_vol->bpb.log2_bytes_per_sector);
|
||||
num_rest_sector -= p_page->size;
|
||||
} else if (p_page->sector > sector && p_page->sector < sector + num_success_sector &&
|
||||
p_page->sector + p_page->size >= sector + num_success_sector) {
|
||||
pf_memcpy(&p_buf[(p_page->sector - sector) << p_vol->bpb.log2_bytes_per_sector], p_page->buffer,
|
||||
(p_page->size - (p_page->sector + p_page->size - (sector + num_success_sector))) << p_vol->bpb.log2_bytes_per_sector);
|
||||
num_rest_sector -= p_page->size - ((p_page->sector + p_page->size) - (sector + num_success_sector));
|
||||
} else if (p_page->sector < sector && (p_page->sector + p_page->size) > sector &&
|
||||
(p_page->sector + p_page->size) <= (sector + num_success_sector)) {
|
||||
pf_memcpy(p_buf, &p_page->buffer[(sector - p_page->sector) << p_vol->bpb.log2_bytes_per_sector],
|
||||
(p_page->size - (sector - p_page->sector)) << p_vol->bpb.log2_bytes_per_sector);
|
||||
num_rest_sector -= p_page->size - (sector - p_page->sector);
|
||||
}
|
||||
}
|
||||
} while (p_page != PF_NULL && num_rest_sector != 0);
|
||||
if (*p_num_success != num_sector && p_vol->bpb.total_sectors != (sector + *p_num_success)) {
|
||||
return 17;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#pragma dont_inline reset
|
||||
|
||||
#pragma dont_inline on
|
||||
pf_s32 PFCACHE_DoWritePage(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_head, PF_CACHE_PAGE* p_page, pf_bool set_sig) {
|
||||
pf_s32 err;
|
||||
if (p_page != *pp_head) {
|
||||
if (p_page == (*pp_head)->p_prev) {
|
||||
*pp_head = p_page;
|
||||
} else {
|
||||
p_page->p_prev->p_next = p_page->p_next;
|
||||
p_page->p_next->p_prev = p_page->p_prev;
|
||||
p_page->p_next = *pp_head;
|
||||
p_page->p_prev = (*pp_head)->p_prev;
|
||||
p_page->p_next->p_prev = p_page;
|
||||
p_page->p_prev->p_next = p_page;
|
||||
*pp_head = p_page;
|
||||
}
|
||||
}
|
||||
p_page->stat |= 2;
|
||||
if (p_page->p_mod_sbuf == PF_NULL) {
|
||||
p_page->p_mod_sbuf = p_page->p_buf;
|
||||
p_page->p_mod_ebuf = p_page->p_buf;
|
||||
} else if (p_page->p_buf < p_page->p_mod_sbuf) {
|
||||
p_page->p_mod_sbuf = p_page->p_buf;
|
||||
} else if (p_page->p_buf > p_page->p_mod_ebuf) {
|
||||
p_page->p_mod_ebuf = p_page->p_buf;
|
||||
}
|
||||
if (set_sig) {
|
||||
p_page->signature = p_vol->cache.signature;
|
||||
} else {
|
||||
p_page->signature = PF_NULL;
|
||||
}
|
||||
if ((p_vol->cache.mode & 0x01) != 0 || ((p_vol->cache.mode & 0x04) != 0 && (p_page->stat & 0x04) != 0)) {
|
||||
err = PFCACHE_FlushPageIfNeeded(p_vol, p_page);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#pragma dont_inline reset
|
||||
|
||||
#pragma dont_inline on
|
||||
pf_s32 PFCACHE_DoWriteSector(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_head, const pf_u8* p_buf, pf_u32 sector) {
|
||||
PF_CACHE_PAGE* p_page;
|
||||
pf_u32 num_success;
|
||||
pf_s32 err;
|
||||
p_page = PFCACHE_SearchForPage(p_vol, *pp_head, sector);
|
||||
if (p_page != PF_NULL) {
|
||||
pf_memcpy(p_page->p_buf, (pf_u8*)p_buf, p_vol->bpb.bytes_per_sector);
|
||||
p_page->stat |= 2;
|
||||
if (p_page->p_mod_sbuf == PF_NULL) {
|
||||
p_page->p_mod_sbuf = p_page->p_buf;
|
||||
p_page->p_mod_ebuf = p_page->p_buf;
|
||||
} else if (p_page->p_buf < p_page->p_mod_sbuf) {
|
||||
p_page->p_mod_sbuf = p_page->p_buf;
|
||||
} else if (p_page->p_buf > p_page->p_mod_ebuf) {
|
||||
p_page->p_mod_ebuf = p_page->p_buf;
|
||||
}
|
||||
err = PFCACHE_FlushPageIfNeeded(p_vol, p_page);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
} else {
|
||||
err = PFDRV_lwrite(p_vol, p_buf, sector, 1, &num_success);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
if (num_success != 1) {
|
||||
return 17;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#pragma dont_inline reset
|
||||
|
||||
#pragma dont_inline on
|
||||
pf_s32 PFCACHE_DoWriteNumSectorAndFreeIfNeeded(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_head, const pf_u8* p_buf, pf_u32 sector,
|
||||
pf_u32 num_sector, pf_u32* p_num_success) {
|
||||
PF_CACHE_PAGE* p_page = PF_NULL;
|
||||
pf_s32 err;
|
||||
pf_u32 num_rest_sector = num_sector;
|
||||
pf_u8* p_sbuf;
|
||||
pf_u8* p_ebuf;
|
||||
pf_u32 num_overlap;
|
||||
pf_u32 last_sector;
|
||||
*p_num_success = 0;
|
||||
do {
|
||||
if (p_page == PF_NULL) {
|
||||
p_page = *pp_head;
|
||||
} else {
|
||||
p_page = p_page->p_next;
|
||||
if (p_page == *pp_head) {
|
||||
p_page = PF_NULL;
|
||||
goto found_page;
|
||||
}
|
||||
}
|
||||
for (; (p_page->stat & 1) != 0; p_page = p_page->p_next) {
|
||||
if (p_page->sector != 0xFFFFFFFF) {
|
||||
p_page->p_buf = p_page->buffer;
|
||||
goto found_page;
|
||||
}
|
||||
}
|
||||
p_page = PF_NULL;
|
||||
found_page:
|
||||
if (p_page != PF_NULL && p_page->sector != 0xFFFFFFFF) {
|
||||
if (p_page->sector <= sector && (p_page->sector + p_page->size) >= (sector + num_sector)) {
|
||||
pf_memcpy(&p_page->buffer[(sector - p_page->sector) << p_vol->bpb.log2_bytes_per_sector], (pf_u8*)p_buf,
|
||||
num_sector << p_vol->bpb.log2_bytes_per_sector);
|
||||
*p_num_success += num_rest_sector;
|
||||
num_rest_sector = 0;
|
||||
p_page->stat |= 2;
|
||||
p_sbuf = &p_page->buffer[(sector - p_page->sector) << p_vol->bpb.log2_bytes_per_sector];
|
||||
p_ebuf = &(&p_page->buffer[(sector - p_page->sector) << p_vol->bpb.log2_bytes_per_sector])[(num_sector - 1)
|
||||
<< p_vol->bpb.log2_bytes_per_sector];
|
||||
if (p_page->p_mod_sbuf == NULL) {
|
||||
p_page->p_mod_sbuf = p_sbuf;
|
||||
p_page->p_mod_ebuf = p_ebuf;
|
||||
} else if (p_sbuf < p_page->p_mod_sbuf) {
|
||||
p_page->p_mod_sbuf = p_sbuf;
|
||||
} else if (p_page->p_mod_ebuf < p_ebuf) {
|
||||
p_page->p_mod_ebuf = p_ebuf;
|
||||
}
|
||||
} else if (p_page->sector >= sector && (p_page->sector + p_page->size) <= (sector + num_sector)) {
|
||||
pf_memcpy(p_page->buffer, (pf_u8*)&p_buf[(p_page->sector - sector) << p_vol->bpb.log2_bytes_per_sector],
|
||||
p_page->size << p_vol->bpb.log2_bytes_per_sector);
|
||||
num_rest_sector -= p_page->size;
|
||||
*p_num_success += p_page->size;
|
||||
p_page->stat |= 2;
|
||||
p_page->p_mod_sbuf = p_page->buffer;
|
||||
p_page->p_mod_ebuf = &p_page->buffer[(p_page->size - 1) << p_vol->bpb.log2_bytes_per_sector];
|
||||
} else if (p_page->sector > sector && p_page->sector < (sector + num_sector) &&
|
||||
(p_page->sector + p_page->size) >= (sector + num_sector)) {
|
||||
pf_memcpy(p_page->buffer, (pf_u8*)&p_buf[(p_page->sector - sector) << p_vol->bpb.log2_bytes_per_sector],
|
||||
(sector + num_sector - p_page->sector) << p_vol->bpb.log2_bytes_per_sector);
|
||||
num_overlap = p_page->size - ((p_page->sector + p_page->size) - (num_sector + sector));
|
||||
last_sector = p_page->sector + num_overlap - 1;
|
||||
*p_num_success += num_overlap;
|
||||
num_rest_sector -= num_overlap;
|
||||
p_page->stat |= 2;
|
||||
p_ebuf = &p_page->buffer[(last_sector - p_page->sector) << p_vol->bpb.log2_bytes_per_sector];
|
||||
p_page->p_mod_sbuf = p_page->buffer;
|
||||
if (p_page->p_mod_ebuf == NULL || p_page->p_mod_ebuf < p_ebuf) {
|
||||
p_page->p_mod_ebuf = p_ebuf;
|
||||
}
|
||||
} else if (p_page->sector < sector && (p_page->sector + p_page->size) > sector &&
|
||||
(p_page->sector + p_page->size) <= (sector + num_sector)) {
|
||||
pf_memcpy(&p_page->buffer[(sector - p_page->sector) << p_vol->bpb.log2_bytes_per_sector], (pf_u8*)p_buf,
|
||||
(p_page->size - (sector - p_page->sector)) << p_vol->bpb.log2_bytes_per_sector);
|
||||
num_rest_sector -= p_page->size - (sector - p_page->sector);
|
||||
*p_num_success += p_page->size - (sector - p_page->sector);
|
||||
p_page->stat |= 2;
|
||||
p_sbuf = &p_page->buffer[(p_page->size - (sector - p_page->sector) - 1) << p_vol->bpb.log2_bytes_per_sector];
|
||||
if (p_page->p_mod_sbuf == NULL || p_sbuf < p_page->p_mod_sbuf) {
|
||||
p_page->p_mod_sbuf = p_sbuf;
|
||||
}
|
||||
p_page->p_mod_ebuf = &p_page->buffer[(p_page->size - 1) << p_vol->bpb.log2_bytes_per_sector];
|
||||
}
|
||||
}
|
||||
} while (p_page != PF_NULL && num_rest_sector != 0);
|
||||
if (num_rest_sector != 0) {
|
||||
err = PFDRV_lwrite(p_vol, p_buf, sector, num_sector, p_num_success);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#pragma dont_inline reset
|
||||
|
||||
#pragma dont_inline on
|
||||
pf_s32 PFCACHE_DoFlushCache(PF_VOLUME* p_vol, PF_CACHE_PAGE* p_head) {
|
||||
PF_CACHE_PAGE* p_page;
|
||||
pf_s32 err;
|
||||
pf_s32 first_err;
|
||||
first_err = 0;
|
||||
p_page = p_head;
|
||||
if ((p_page->stat & 0x01) == 0) {
|
||||
return 0;
|
||||
}
|
||||
if ((p_vol->cache.mode & 1) != 0 || ((p_vol->cache.mode & 4) != 0 && (p_page->stat & 4) != 0)) {
|
||||
return 0;
|
||||
}
|
||||
do {
|
||||
if ((p_page->stat & 0x01) == 0) {
|
||||
break;
|
||||
}
|
||||
err = PFCACHE_FlushPageIfNeeded(p_vol, p_page);
|
||||
if (err != 0 && first_err == 0) {
|
||||
first_err = err;
|
||||
}
|
||||
p_page = p_page->p_next;
|
||||
} while (p_page != p_head);
|
||||
return first_err;
|
||||
}
|
||||
|
||||
#pragma dont_inline reset
|
||||
|
||||
void PFCACHE_SetCache(PF_VOLUME* p_vol, PF_CACHE_PAGE* p_cache_page, PF_CACHE_BUFFER* p_cache_buf, pf_u16 num_fat_pages, pf_u16 num_data_pages) {
|
||||
p_vol->cache.pages = p_cache_page;
|
||||
p_vol->cache.buffers = p_cache_buf;
|
||||
p_vol->cache.num_fat_pages = num_fat_pages;
|
||||
p_vol->cache.num_data_pages = num_data_pages;
|
||||
}
|
||||
|
||||
void PFCACHE_SetFATBufferSize(PF_VOLUME* p_vol, pf_u32 size) {
|
||||
if (size != 0) {
|
||||
p_vol->cache.fat_buff_size = size;
|
||||
}
|
||||
}
|
||||
|
||||
void PFCACHE_SetDataBufferSize(PF_VOLUME* p_vol, pf_u32 size) {
|
||||
if (size != 0) {
|
||||
p_vol->cache.data_buff_size = size;
|
||||
}
|
||||
}
|
||||
|
||||
pf_s32 PFCACHE_InitCaches(PF_VOLUME* p_vol) {
|
||||
pf_s32 err;
|
||||
p_vol->cache.mode &= ~0x01;
|
||||
p_vol->cache.mode |= 0x02;
|
||||
p_vol->cache.mode &= ~0x04;
|
||||
pf_memset(p_vol->cache.buffers, 0, (p_vol->cache.num_fat_pages + p_vol->cache.num_data_pages) << 9);
|
||||
err = PFCACHE_InitPageList(p_vol, &p_vol->cache.p_current_fat, p_vol->cache.pages, p_vol->cache.buffers, p_vol->cache.num_fat_pages,
|
||||
p_vol->cache.fat_buff_size, PF_TRUE);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
err = PFCACHE_InitPageList(p_vol, &p_vol->cache.p_current_data, &p_vol->cache.pages[p_vol->cache.num_fat_pages],
|
||||
(PF_CACHE_BUFFER*)p_vol->cache.buffers[p_vol->cache.num_fat_pages], p_vol->cache.num_data_pages,
|
||||
p_vol->cache.data_buff_size, PF_FALSE);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFCACHE_SetWriteThroughMode(PF_VOLUME* p_vol) {
|
||||
pf_s32 err = PFCACHE_FlushAllCaches(p_vol);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
p_vol->cache.mode |= 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFCACHE_SetWriteBackMode(PF_VOLUME* p_vol) {
|
||||
p_vol->cache.mode &= ~1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFCACHE_AllocateFATPage(PF_VOLUME* p_vol, pf_u32 sector, PF_CACHE_PAGE** pp_page, pf_bool* p_is_hit) {
|
||||
pf_s32 err;
|
||||
if (p_vol->cache.p_current_fat == 0) {
|
||||
p_vol->cache.pages->buffer = *p_vol->cache.buffers;
|
||||
p_vol->cache.pages->p_buf = *p_vol->cache.buffers;
|
||||
*pp_page = p_vol->cache.pages;
|
||||
return 0;
|
||||
}
|
||||
err = PFCACHE_DoAllocatePage(p_vol, &p_vol->cache.p_current_fat, sector, pp_page, p_is_hit);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFCACHE_AllocateDataPage(PF_VOLUME* p_vol, pf_u32 sector, PF_CACHE_PAGE** pp_page, pf_bool* p_is_hit) {
|
||||
pf_s32 err;
|
||||
if (p_vol->cache.p_current_data == 0) {
|
||||
p_vol->cache.pages->buffer = *p_vol->cache.buffers;
|
||||
p_vol->cache.pages->p_buf = *p_vol->cache.buffers;
|
||||
*pp_page = p_vol->cache.pages;
|
||||
return 0;
|
||||
}
|
||||
err = PFCACHE_DoAllocatePage(p_vol, &p_vol->cache.p_current_data, sector, pp_page, p_is_hit);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PFCACHE_FreeFATPage(PF_VOLUME* p_vol, PF_CACHE_PAGE* p_page) {
|
||||
if (p_vol->cache.p_current_fat != 0) {
|
||||
p_page->p_mod_sbuf = NULL;
|
||||
p_page->stat &= ~3;
|
||||
p_page->p_mod_ebuf = NULL;
|
||||
p_page->sector = 0xFFFFFFFF;
|
||||
p_page->signature = PF_NULL;
|
||||
if (p_page == p_vol->cache.p_current_fat) {
|
||||
p_vol->cache.p_current_fat = p_page->p_next;
|
||||
} else if (p_page != (p_vol->cache.p_current_fat)->p_prev) {
|
||||
p_page->p_prev->p_next = p_page->p_next;
|
||||
p_page->p_next->p_prev = p_page->p_prev;
|
||||
p_page->p_next = p_vol->cache.p_current_fat;
|
||||
p_page->p_prev = (p_vol->cache.p_current_fat)->p_prev;
|
||||
p_page->p_next->p_prev = p_page;
|
||||
p_page->p_prev->p_next = p_page;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PFCACHE_FreeDataPage(PF_VOLUME* p_vol, PF_CACHE_PAGE* p_page) {
|
||||
if (p_vol->cache.p_current_data != 0) {
|
||||
p_page->p_mod_sbuf = NULL;
|
||||
p_page->stat &= ~3;
|
||||
p_page->p_mod_ebuf = NULL;
|
||||
p_page->sector = 0xFFFFFFFF;
|
||||
p_page->signature = PF_NULL;
|
||||
if (p_page == p_vol->cache.p_current_data) {
|
||||
p_vol->cache.p_current_data = p_page->p_next;
|
||||
} else if (p_page != (p_vol->cache.p_current_data)->p_prev) {
|
||||
p_page->p_prev->p_next = p_page->p_next;
|
||||
p_page->p_next->p_prev = p_page->p_prev;
|
||||
p_page->p_next = p_vol->cache.p_current_data;
|
||||
p_page->p_prev = (p_vol->cache.p_current_data)->p_prev;
|
||||
p_page->p_next->p_prev = p_page;
|
||||
p_page->p_prev->p_next = p_page;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pf_s32 PFCACHE_ReadFATPage(PF_VOLUME* p_vol, pf_u32 sector, PF_CACHE_PAGE** pp_page) {
|
||||
pf_s32 err;
|
||||
err = PFCACHE_DoReadPage(p_vol, &p_vol->cache.p_current_fat, sector, pp_page, 0U);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFCACHE_ReadDataPage(PF_VOLUME* p_vol, pf_u32 sector, PF_CACHE_PAGE** pp_page, pf_bool set_sig) {
|
||||
pf_s32 err;
|
||||
err = PFCACHE_DoReadPage(p_vol, &p_vol->cache.p_current_data, sector, pp_page, set_sig);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFCACHE_ReadDataPageAndFlushIfNeeded(PF_VOLUME* p_vol, pf_u32 sector, PF_CACHE_PAGE** pp_page, pf_bool set_sig) {
|
||||
pf_s32 err;
|
||||
err = PFCACHE_DoReadPageAndFlushIfNeeded(p_vol, &p_vol->cache.p_current_data, sector, pp_page, set_sig);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFCACHE_ReadDataNumSector(PF_VOLUME* p_vol, pf_u8* p_buf, pf_u32 sector, pf_u32 num_sector, pf_u32* p_num_success) {
|
||||
pf_s32 err;
|
||||
if (sector >= p_vol->bpb.total_sectors) {
|
||||
return 16;
|
||||
}
|
||||
err = PFCACHE_DoReadNumSector(p_vol, &p_vol->cache.p_current_data, p_buf, sector, num_sector, p_num_success);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFCACHE_WriteFATPage(PF_VOLUME* p_vol, PF_CACHE_PAGE* p_page) {
|
||||
pf_s32 err;
|
||||
err = PFCACHE_DoWritePage(p_vol, &p_vol->cache.p_current_fat, p_page, 0);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFCACHE_WriteDataPage(PF_VOLUME* p_vol, PF_CACHE_PAGE* p_page, pf_bool set_sig) {
|
||||
pf_s32 err;
|
||||
err = PFCACHE_DoWritePage(p_vol, &p_vol->cache.p_current_data, p_page, set_sig);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFCACHE_WriteFATSectorAndFreeIfNeeded(PF_VOLUME* p_vol, const pf_u8* p_buf, pf_u32 sector) {
|
||||
pf_s32 err;
|
||||
if (sector >= p_vol->bpb.total_sectors) {
|
||||
return 16;
|
||||
}
|
||||
err = PFCACHE_DoWriteSector(p_vol, &p_vol->cache.p_current_fat, p_buf, sector);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFCACHE_WriteDataNumSectorAndFreeIfNeeded(PF_VOLUME* p_vol, const pf_u8* p_buf, pf_u32 sector, pf_u32 num_sector, pf_u32* p_num_success) {
|
||||
pf_s32 err;
|
||||
if (sector >= p_vol->bpb.total_sectors) {
|
||||
return 16;
|
||||
}
|
||||
err = PFCACHE_DoWriteNumSectorAndFreeIfNeeded(p_vol, &p_vol->cache.p_current_data, p_buf, sector, num_sector, p_num_success);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
PF_CACHE_PAGE* PFCACHE_SearchDataCache(PF_VOLUME* p_vol, pf_u32 sector) {
|
||||
return PFCACHE_SearchForPage(p_vol, p_vol->cache.p_current_data, sector);
|
||||
}
|
||||
|
||||
pf_s32 PFCACHE_FlushFATCache(PF_VOLUME* p_vol) {
|
||||
pf_s32 err;
|
||||
err = PFCACHE_DoFlushCache(p_vol, p_vol->cache.p_current_fat);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFCACHE_FlushDataCache(PF_VOLUME* p_vol) {
|
||||
pf_s32 err;
|
||||
err = PFCACHE_DoFlushCache(p_vol, p_vol->cache.p_current_data);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFCACHE_FlushDataCacheSpecific(PF_VOLUME* p_vol, void* signature) {
|
||||
pf_s32 err = 0;
|
||||
PF_CACHE_PAGE* p_head;
|
||||
PF_CACHE_PAGE* p_page;
|
||||
if ((p_vol->cache.mode & 7) != 0) {
|
||||
p_head = p_vol->cache.p_current_data;
|
||||
p_page = p_head;
|
||||
if (p_page->signature == PF_NULL || p_page->signature == signature) {
|
||||
err = PFCACHE_FlushPageIfNeeded(p_vol, p_page);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
for (p_page = p_page->p_next; p_page != p_head; p_page = p_page->p_next) {
|
||||
if (p_page->signature == PF_NULL || p_page->signature == signature) {
|
||||
err = PFCACHE_FlushPageIfNeeded(p_vol, p_page);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
pf_s32 PFCACHE_FlushAllCaches(PF_VOLUME* p_vol) {
|
||||
pf_s32 err;
|
||||
err = PFCACHE_DoFlushCache(p_vol, p_vol->cache.p_current_fat);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
err = PFCACHE_DoFlushCache(p_vol, p_vol->cache.p_current_data);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PFCACHE_FreeAllCaches(PF_VOLUME* p_vol) {
|
||||
while ((p_vol->cache.p_current_fat->stat & 0x01) != 0) {
|
||||
{
|
||||
PF_CACHE_PAGE* p_page = p_vol->cache.p_current_fat;
|
||||
if (p_vol->cache.p_current_fat != 0) {
|
||||
p_page->stat &= ~3;
|
||||
p_page->p_mod_sbuf = NULL;
|
||||
p_page->p_mod_ebuf = NULL;
|
||||
p_page->sector = 0xFFFFFFFF;
|
||||
p_page->signature = PF_NULL;
|
||||
if (p_page == p_vol->cache.p_current_fat) {
|
||||
p_vol->cache.p_current_fat = p_page->p_next;
|
||||
} else if (p_page != (p_vol->cache.p_current_fat)->p_prev) {
|
||||
p_page->p_prev->p_next = p_page->p_next;
|
||||
p_page->p_next->p_prev = p_page->p_prev;
|
||||
p_page->p_next = p_vol->cache.p_current_fat;
|
||||
p_page->p_prev = (p_vol->cache.p_current_fat)->p_prev;
|
||||
p_page->p_next->p_prev = p_page;
|
||||
p_page->p_prev->p_next = p_page;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
while ((p_vol->cache.p_current_data->stat & 0x01) != 0) {
|
||||
{
|
||||
PF_CACHE_PAGE* p_page = p_vol->cache.p_current_data;
|
||||
if (p_vol->cache.p_current_data != 0) {
|
||||
p_page->stat &= ~3;
|
||||
p_page->p_mod_sbuf = NULL;
|
||||
p_page->p_mod_ebuf = NULL;
|
||||
p_page->sector = 0xFFFFFFFF;
|
||||
p_page->signature = PF_NULL;
|
||||
if (p_page == p_vol->cache.p_current_data) {
|
||||
p_vol->cache.p_current_data = p_page->p_next;
|
||||
} else if (p_page != (p_vol->cache.p_current_data)->p_prev) {
|
||||
p_page->p_prev->p_next = p_page->p_next;
|
||||
p_page->p_next->p_prev = p_page->p_prev;
|
||||
p_page->p_next = p_vol->cache.p_current_data;
|
||||
p_page->p_prev = (p_vol->cache.p_current_data)->p_prev;
|
||||
p_page->p_next->p_prev = p_page;
|
||||
p_page->p_prev->p_next = p_page;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
libs/RVL_SDK/src/fa/pf_chdir.c
Normal file
31
libs/RVL_SDK/src/fa/pf_chdir.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#define PF_FA_STR_LAYOUT
|
||||
#define VFiPFAPI_convertReturnValue PFAPI_convertReturnValue
|
||||
#define VFiPFDIR_chdir PFDIR_chdir
|
||||
#define VFiPFSTR_InitStr PFSTR_InitStr
|
||||
#include <private/vf/PrFILE2/standard/pf_mkdir.h>
|
||||
|
||||
typedef struct PFAPI_GLOBAL_STATE {
|
||||
pf_u8 volume_state[0x40];
|
||||
pf_s32 last_error;
|
||||
} PFAPI_GLOBAL_STATE;
|
||||
extern PFAPI_GLOBAL_STATE pf_vol_set;
|
||||
|
||||
|
||||
#include <private/vf/PrFILE2/fatfs/pf_dir.h>
|
||||
#include <private/vf/PrFILE2/standard/pf_api_util.h>
|
||||
|
||||
#include <private/vf/PrFILE2/common/pf_str.h>
|
||||
|
||||
pf_int32 pf2_chdir(const pf_ch8* sPath) {
|
||||
pf_s32 err;
|
||||
PF_STR path_str;
|
||||
|
||||
err = VFiPFSTR_InitStr(&path_str, (pf_s8*)sPath, 1U);
|
||||
if (err == 0) {
|
||||
err = VFiPFDIR_chdir(&path_str);
|
||||
} else {
|
||||
pf_vol_set.last_error = err;
|
||||
}
|
||||
err = VFiPFAPI_convertReturnValue(err);
|
||||
return err;
|
||||
}
|
||||
177
libs/RVL_SDK/src/fa/pf_clib.c
Normal file
177
libs/RVL_SDK/src/fa/pf_clib.c
Normal file
@@ -0,0 +1,177 @@
|
||||
#include <private/vf/PrFILE2/pf_types.h>
|
||||
|
||||
pf_s32 pf_toupper(pf_s32 c) {
|
||||
if (c >= 'a' && c <= 'z') {
|
||||
return c + ('A' - 'a');
|
||||
} else {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
void* pf_memcpy(void* dst, void* src, pf_u32 length) {
|
||||
pf_s8* d;
|
||||
const pf_s8* s;
|
||||
|
||||
pf_u32* ld = (pf_u32*)dst;
|
||||
const pf_u32* ls = (pf_u32*)src;
|
||||
|
||||
if (((pf_u32)ld & 3) == 0 && ((pf_u32)ls & 3) == 0) {
|
||||
for (; length > 3; length -= 4) {
|
||||
*ld++ = *ls++;
|
||||
}
|
||||
}
|
||||
|
||||
d = (pf_s8*)ld;
|
||||
s = (pf_s8*)ls;
|
||||
|
||||
while (length-- != 0) {
|
||||
*d++ = *s++;
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
void* pf_memset(void* dst, pf_s32 c, pf_u32 length) {
|
||||
pf_s8* d = (pf_s8*)dst;
|
||||
pf_u32* ld;
|
||||
pf_u32 lc;
|
||||
|
||||
for (; ((pf_u32)d & 3) != 0; length--) {
|
||||
*d++ = c;
|
||||
}
|
||||
|
||||
ld = (pf_u32*)d;
|
||||
lc = (c << 24) | (c << 16) | (c << 8) | (c);
|
||||
|
||||
for (; length > 3; length -= 4) {
|
||||
*ld++ = lc;
|
||||
}
|
||||
|
||||
d = (pf_s8*)ld;
|
||||
while (length-- != 0) {
|
||||
*d++ = c;
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
pf_s32 pf_memcmp(const void* s1, const void* s2, pf_u32 length) {
|
||||
const pf_u8* p1 = (const pf_u8*)s1;
|
||||
const pf_u8* p2 = (const pf_u8*)s2;
|
||||
|
||||
if (((pf_u32)p1 & 3) == 0 && ((pf_u32)p2 & 3) == 0) {
|
||||
const pf_u32* lp1 = (const pf_u32*)p1;
|
||||
const pf_u32* lp2 = (const pf_u32*)p2;
|
||||
|
||||
for (; length > 3; length -= 4, lp1++, lp2++) {
|
||||
if (*lp1 != *lp2) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
p1 = (const pf_u8*)lp1;
|
||||
p2 = (const pf_u8*)lp2;
|
||||
}
|
||||
|
||||
while (length-- != 0) {
|
||||
if (*p1 != *p2) {
|
||||
return *p1 - *p2;
|
||||
}
|
||||
p1++;
|
||||
p2++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_u32 pf_strlen(const pf_s8* s) {
|
||||
const pf_s8* t = s;
|
||||
|
||||
while (*t != 0) {
|
||||
t++;
|
||||
}
|
||||
|
||||
return (pf_u32)(t - s);
|
||||
}
|
||||
|
||||
pf_s8* pf_strcpy(pf_s8* dst, const pf_s8* src) {
|
||||
pf_s8* d;
|
||||
|
||||
for (d = dst; (*d = *src) != 0; src++, d++) {
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
pf_s32 pf_strcmp(const pf_s8* s1, const pf_s8* s2) {
|
||||
const pf_u8* p1 = (pf_u8*)s1;
|
||||
const pf_u8* p2 = (pf_u8*)s2;
|
||||
|
||||
while (*p1 != 0 && *p2 != 0 && *p1 == *p2) {
|
||||
p1++;
|
||||
p2++;
|
||||
}
|
||||
|
||||
return *p1 - *p2;
|
||||
}
|
||||
|
||||
pf_s32 pf_strncmp(const pf_s8* s1, const pf_s8* s2, pf_u32 length) {
|
||||
const pf_u8* p1 = (pf_u8*)s1;
|
||||
const pf_u8* p2 = (pf_u8*)s2;
|
||||
|
||||
while (length-- != 0) {
|
||||
if (!(*p1 != 0 && *p2 != 0 && *p1 == *p2)) {
|
||||
return *p1 - *p2;
|
||||
}
|
||||
p1++;
|
||||
p2++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_u32 pf_w_strlen(const pf_u16* s) {
|
||||
const pf_u16* t = s;
|
||||
|
||||
while (*t != 0) {
|
||||
t++;
|
||||
}
|
||||
|
||||
return ((pf_s8*)t - (pf_s8*)s) >> 1;
|
||||
}
|
||||
|
||||
pf_u16* pf_w_strcpy(pf_u16* dst, const pf_u16* src) {
|
||||
pf_u16* d;
|
||||
|
||||
for (d = dst; (*d = *src) != 0; src++, d++) {
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
pf_s32 pf_w_strcmp(const pf_u16* s1, const pf_u16* s2) {
|
||||
const pf_u16* p1 = (pf_u16*)s1;
|
||||
const pf_u16* p2 = (pf_u16*)s2;
|
||||
|
||||
while (*p1 != 0 && *p2 != 0 && *p1 == *p2) {
|
||||
p1++;
|
||||
p2++;
|
||||
}
|
||||
|
||||
return *p1 - *p2;
|
||||
}
|
||||
|
||||
pf_s32 pf_w_strncmp(const pf_u16* s1, const pf_u16* s2, pf_u32 length) {
|
||||
const pf_u16* p1 = (pf_u16*)s1;
|
||||
const pf_u16* p2 = (pf_u16*)s2;
|
||||
|
||||
while (length-- != 0) {
|
||||
if (*p1 == 0 || *p2 == 0 || *p1 != *p2) {
|
||||
return *p1 - *p2;
|
||||
}
|
||||
p1++;
|
||||
p2++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
644
libs/RVL_SDK/src/fa/pf_cluster.c
Normal file
644
libs/RVL_SDK/src/fa/pf_cluster.c
Normal file
@@ -0,0 +1,644 @@
|
||||
#include <private/vf/PrFILE2/fatfs/pf_entry.h>
|
||||
|
||||
typedef struct PFCLUSTER_FAT_HINT {
|
||||
pf_u32 chain_index;
|
||||
pf_u32 cluster;
|
||||
pf_u32 previous_cluster;
|
||||
} PFCLUSTER_FAT_HINT;
|
||||
|
||||
typedef struct PFCLUSTER_FFD {
|
||||
pf_u32 start_cluster;
|
||||
pf_u32 current_start_cluster;
|
||||
pf_u32* p_start_cluster;
|
||||
PF_LAST_CLUSTER last_cluster;
|
||||
PF_FAT_LAST_ACCESS last_access_cluster;
|
||||
PF_CLUSTER_LINK cluster_link;
|
||||
PFCLUSTER_FAT_HINT* p_hint;
|
||||
PF_VOLUME* p_vol;
|
||||
} PFCLUSTER_FFD;
|
||||
|
||||
typedef struct PFCLUSTER_ENT_ITER {
|
||||
pf_u32 index;
|
||||
PF_VOLUME* p_vol;
|
||||
PFCLUSTER_FFD ffd;
|
||||
pf_u32 file_sector_index;
|
||||
pf_u32 sector;
|
||||
pf_u16 offset;
|
||||
pf_u16 offset_mask;
|
||||
pf_u8 buf[32];
|
||||
pf_u8 log2_entries_per_sector;
|
||||
} PFCLUSTER_ENT_ITER;
|
||||
|
||||
typedef struct PFCLUSTER_BPB {
|
||||
pf_u16 bytes_per_sector;
|
||||
pf_u16 num_reserved_sectors;
|
||||
pf_u16 num_root_dir_entries;
|
||||
pf_u8 sectors_per_cluster;
|
||||
pf_u8 num_FATs;
|
||||
pf_u32 total_sectors;
|
||||
pf_u32 sectors_per_FAT;
|
||||
pf_u32 root_dir_cluster;
|
||||
pf_u16 fs_info_sector;
|
||||
pf_u16 backup_boot_sector;
|
||||
pf_u16 ext_flags;
|
||||
pf_u8 media;
|
||||
pf_s32 fat_type;
|
||||
pf_u8 log2_bytes_per_sector;
|
||||
pf_u8 log2_sectors_per_cluster;
|
||||
pf_u8 num_active_FATs;
|
||||
pf_u16 num_root_dir_sectors;
|
||||
pf_u32 active_FAT_sector;
|
||||
pf_u32 first_root_dir_sector;
|
||||
pf_u32 first_data_sector;
|
||||
pf_u32 num_clusters;
|
||||
} PFCLUSTER_BPB;
|
||||
|
||||
struct PF_VOLUME {
|
||||
PFCLUSTER_BPB bpb;
|
||||
pf_u32 num_free_clusters;
|
||||
pf_u32 last_free_cluster;
|
||||
pf_u8 file_and_directory_state[0x1624 - 0x40];
|
||||
pf_u32 cache_mode;
|
||||
pf_u8 cache_and_driver_state[0x1f90 - 0x1628];
|
||||
pf_u16 fsi_flag;
|
||||
};
|
||||
|
||||
typedef struct PFCLUSTER_CURSOR {
|
||||
pf_u32 position;
|
||||
pf_u32 sector;
|
||||
pf_u32 file_sector_index;
|
||||
pf_u16 offset_in_sector;
|
||||
pf_u16 reserved;
|
||||
} PFCLUSTER_CURSOR;
|
||||
|
||||
typedef struct PFCLUSTER_SFD {
|
||||
pf_u32 stat;
|
||||
PFCLUSTER_FFD ffd;
|
||||
PF_DIR_ENT dir_entry;
|
||||
} PFCLUSTER_SFD;
|
||||
|
||||
typedef struct PFCLUSTER_FILE {
|
||||
pf_u32 stat;
|
||||
pf_u32 open_mode;
|
||||
PFCLUSTER_SFD* p_sfd;
|
||||
PFCLUSTER_FAT_HINT hint;
|
||||
pf_s32 last_error;
|
||||
PFCLUSTER_CURSOR cursor;
|
||||
} PFCLUSTER_FILE;
|
||||
|
||||
extern pf_s32 PFFILE_Cursor_MoveToClusterEnd(PFCLUSTER_FILE*, pf_u32);
|
||||
extern pf_s32 PFFILE_Cursor_MoveToEnd(PFCLUSTER_FILE*);
|
||||
extern pf_s32 PFFAT_GetSectorAllocated(PFCLUSTER_FFD*, pf_u32, pf_u32, pf_u32*);
|
||||
extern pf_s32 PFFAT_getContinuousSector(PFCLUSTER_FFD*, pf_u32, pf_u32, pf_u32*, pf_u32*);
|
||||
extern pf_s32 PFFAT_TraceClustersChain(PFCLUSTER_FFD*, pf_u32, pf_u32, pf_u32*, pf_u32*);
|
||||
extern pf_u32 PFFAT_GetValueOfEOC2(PF_VOLUME*);
|
||||
extern pf_s32 PFFAT_WriteValueToSpecifiedCluster(PF_VOLUME*, pf_u32, pf_u32);
|
||||
extern pf_s32 PFFAT_ReadValueToSpecifiedCluster(PF_VOLUME*, pf_u32, pf_u32*);
|
||||
extern pf_s32 PFFAT_FreeChain(PFCLUSTER_FFD*, pf_u32, pf_u32, pf_u32);
|
||||
extern pf_s32 PFFAT_AllocateNumClusters(PFCLUSTER_FFD*, pf_u32, pf_u32*, pf_u32*, pf_u32*);
|
||||
extern pf_s32 PFENT_updateEntry(PF_DIR_ENT*, pf_u32);
|
||||
extern pf_u8 PFENT_getcurrentDateTimeForEnt(pf_u16*, pf_u16*);
|
||||
extern pf_s32 PFCACHE_FlushDataCacheSpecific(PF_VOLUME*, void*);
|
||||
extern pf_s32 PFCACHE_AllocateDataPage(PF_VOLUME*, pf_u32, PF_CACHE_PAGE**, pf_bool*);
|
||||
extern void PFCACHE_FreeDataPage(PF_VOLUME*, PF_CACHE_PAGE*);
|
||||
extern pf_s32 PFSEC_ReadData(PF_VOLUME*, pf_u8*, pf_u32, pf_u16, pf_u32, pf_u32*, pf_bool);
|
||||
extern pf_s32 PFSEC_WriteData(PF_VOLUME*, const pf_u8*, pf_u32, pf_u16, pf_u32, pf_u32*, pf_bool);
|
||||
|
||||
|
||||
|
||||
void PFCLUSTER_UpdateLastAccessCluster(PFCLUSTER_FILE* p_file, pf_u32 sector) {
|
||||
PF_VOLUME* p_vol;
|
||||
|
||||
if (p_file->cursor.position == 0) {
|
||||
p_file->p_sfd->ffd.last_access_cluster.cluster = 0;
|
||||
p_file->p_sfd->ffd.last_access_cluster.chain_index = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
p_vol = p_file == PF_NULL ? PF_NULL : p_file->p_sfd->dir_entry.p_vol;
|
||||
if ((p_file->cursor.position & (p_vol->bpb.bytes_per_sector - 1)) == 0 &&
|
||||
(p_file->cursor.file_sector_index & (p_vol->bpb.sectors_per_cluster - 1)) == 0) {
|
||||
if (p_file->cursor.file_sector_index != 0) {
|
||||
p_file->p_sfd->ffd.last_access_cluster.chain_index = (p_file->cursor.file_sector_index - 1) >> p_vol->bpb.log2_sectors_per_cluster;
|
||||
p_file->p_sfd->ffd.last_access_cluster.cluster = (((sector - 1) - p_vol->bpb.first_data_sector) >> p_vol->bpb.log2_sectors_per_cluster) + 2;
|
||||
}
|
||||
} else {
|
||||
p_file->p_sfd->ffd.last_access_cluster.chain_index = p_file->cursor.file_sector_index >> p_vol->bpb.log2_sectors_per_cluster;
|
||||
p_file->p_sfd->ffd.last_access_cluster.cluster = ((sector - p_vol->bpb.first_data_sector) >> p_vol->bpb.log2_sectors_per_cluster) + 2;
|
||||
}
|
||||
}
|
||||
|
||||
pf_s32 PFCLUSTER_AppendCluster(PFCLUSTER_FILE* p_file, pf_u32 byte, pf_bool* p_success) {
|
||||
pf_s32 err;
|
||||
PF_VOLUME* p_vol;
|
||||
pf_u32 sector;
|
||||
pf_u32 num_sector;
|
||||
pf_u32 max_appendable_size;
|
||||
PFCLUSTER_CURSOR save_cursor;
|
||||
PFCLUSTER_FAT_HINT save_hint;
|
||||
|
||||
*p_success = 0;
|
||||
if ((p_file->p_sfd->stat & 0x01) == 0 || (p_file->p_sfd->stat & 0x02) == 0) {
|
||||
return 38;
|
||||
}
|
||||
|
||||
p_vol = p_file == PF_NULL ? PF_NULL : p_file->p_sfd->dir_entry.p_vol;
|
||||
|
||||
save_cursor = p_file->cursor;
|
||||
save_hint = p_file->hint;
|
||||
|
||||
p_file->p_sfd->ffd.p_hint = &p_file->hint;
|
||||
sector = 0xFFFFFFFF;
|
||||
if ((p_vol->fsi_flag & 0x04) != 0 && p_vol->num_free_clusters != -1 && p_vol->num_free_clusters == 0) {
|
||||
return 6;
|
||||
}
|
||||
PFFILE_Cursor_MoveToClusterEnd(p_file, p_file->p_sfd->dir_entry.file_size + byte);
|
||||
if (p_file->cursor.position == -1) {
|
||||
*p_success = 0;
|
||||
return 37;
|
||||
}
|
||||
err = PFFAT_GetSectorAllocated(&p_file->p_sfd->ffd, p_file->cursor.file_sector_index, byte, §or);
|
||||
if (err != 0) {
|
||||
p_file->cursor = save_cursor;
|
||||
p_file->hint = save_hint;
|
||||
return err;
|
||||
}
|
||||
num_sector = 0;
|
||||
err = PFFAT_getContinuousSector(&p_file->p_sfd->ffd, p_file->cursor.file_sector_index, byte, §or, &num_sector);
|
||||
p_file->cursor = save_cursor;
|
||||
p_file->hint = save_hint;
|
||||
if (err != 0) return err;
|
||||
if (sector == -1U) {
|
||||
PFFILE_Cursor_MoveToEnd(p_file);
|
||||
return 28;
|
||||
}
|
||||
max_appendable_size = num_sector << p_vol->bpb.log2_bytes_per_sector;
|
||||
if (byte < max_appendable_size) {
|
||||
max_appendable_size = byte;
|
||||
}
|
||||
*p_success = max_appendable_size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFCLUSTER_AdjustCluster(PFCLUSTER_FILE* p_file) {
|
||||
PF_VOLUME* p_vol;
|
||||
pf_u32 num_cluster;
|
||||
pf_u32 file_end_cluster;
|
||||
pf_u32 spare_cluster;
|
||||
pf_u32 sig_eoc;
|
||||
pf_u32 chain_index;
|
||||
pf_s32 err;
|
||||
|
||||
if (((p_file->p_sfd->stat & 1) == 0) || ((p_file->p_sfd->stat & 2) == 0)) {
|
||||
return 0x26;
|
||||
}
|
||||
p_vol = p_file == PF_NULL ? PF_NULL : p_file->p_sfd->dir_entry.p_vol;
|
||||
|
||||
p_file->p_sfd->ffd.p_hint = &p_file->hint;
|
||||
chain_index = -1U;
|
||||
if (p_file->p_sfd->ffd.last_cluster.max_chain_index != 0) {
|
||||
num_cluster = ((p_file->p_sfd->dir_entry.file_size & ((p_vol->bpb.bytes_per_sector << p_vol->bpb.log2_sectors_per_cluster) - 1)) ? 1 : 0) +
|
||||
(p_file->p_sfd->dir_entry.file_size >> (p_vol->bpb.log2_bytes_per_sector + p_vol->bpb.log2_sectors_per_cluster));
|
||||
|
||||
if ((p_file->p_sfd->ffd.last_cluster.max_chain_index + 1) == num_cluster) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (p_file->p_sfd->dir_entry.file_size != 0) {
|
||||
err = PFFAT_TraceClustersChain(&p_file->p_sfd->ffd, p_file->p_sfd->dir_entry.start_cluster, p_file->p_sfd->dir_entry.file_size,
|
||||
&file_end_cluster, &spare_cluster);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
} else {
|
||||
file_end_cluster = 0;
|
||||
spare_cluster = p_file->p_sfd->dir_entry.start_cluster;
|
||||
}
|
||||
if (spare_cluster != 0) {
|
||||
sig_eoc = PFFAT_GetValueOfEOC2(p_vol);
|
||||
if (spare_cluster != sig_eoc) {
|
||||
if (file_end_cluster != 0) {
|
||||
err = PFFAT_WriteValueToSpecifiedCluster(p_vol, file_end_cluster, sig_eoc);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
p_file->p_sfd->ffd.last_cluster.num_last_cluster = file_end_cluster;
|
||||
p_file->p_sfd->ffd.last_cluster.max_chain_index =
|
||||
((p_file->p_sfd->dir_entry.file_size >> (p_vol->bpb.log2_bytes_per_sector + p_vol->bpb.log2_sectors_per_cluster)) +
|
||||
((p_file->p_sfd->dir_entry.file_size & ((p_vol->bpb.bytes_per_sector << p_vol->bpb.log2_sectors_per_cluster) - 1)) ? 1 : 0)) -
|
||||
1;
|
||||
chain_index = p_file->p_sfd->ffd.last_cluster.max_chain_index + 1;
|
||||
|
||||
} else {
|
||||
p_file->p_sfd->dir_entry.start_cluster = 0;
|
||||
*p_file->p_sfd->ffd.p_start_cluster = 0;
|
||||
p_file->p_sfd->ffd.last_cluster.num_last_cluster = 0;
|
||||
p_file->p_sfd->ffd.last_cluster.max_chain_index = 0;
|
||||
err = PFENT_updateEntry(&p_file->p_sfd->dir_entry, 1U);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
if ((p_vol->cache_mode & 4) != 0) {
|
||||
err = PFCACHE_FlushDataCacheSpecific(p_vol, p_file);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
}
|
||||
err = PFFAT_FreeChain(&p_file->p_sfd->ffd, spare_cluster, chain_index, -1U);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFCLUSTER_GetAppendSize(PFCLUSTER_FILE* p_file, pf_u32* p_size) {
|
||||
PF_VOLUME* p_vol;
|
||||
pf_u32 cluster_size;
|
||||
pf_u32 file_cluster_size;
|
||||
pf_u32 total_allocated_size;
|
||||
pf_u32 file_end_cluster;
|
||||
pf_u32 spare_cluster;
|
||||
pf_u32 next_cluster;
|
||||
pf_u32 num_append_cluster;
|
||||
pf_u32 sig_eoc;
|
||||
pf_s32 err;
|
||||
|
||||
*p_size = 0;
|
||||
if ((p_file->p_sfd->stat & 0x01) == 0 || (p_file->p_sfd->stat & 0x02) == 0) {
|
||||
return 38;
|
||||
}
|
||||
|
||||
p_vol = p_file == PF_NULL ? PF_NULL : p_file->p_sfd->dir_entry.p_vol;
|
||||
|
||||
cluster_size = p_vol->bpb.bytes_per_sector << p_vol->bpb.log2_sectors_per_cluster;
|
||||
if (p_file->p_sfd->dir_entry.start_cluster != 0) {
|
||||
file_cluster_size =
|
||||
p_file->p_sfd->dir_entry.file_size +
|
||||
((p_file->p_sfd->dir_entry.file_size % cluster_size) != 0 ? cluster_size - (p_file->p_sfd->dir_entry.file_size % cluster_size) : 0);
|
||||
if (p_file->p_sfd->ffd.last_cluster.max_chain_index != 0) {
|
||||
total_allocated_size = (p_file->p_sfd->ffd.last_cluster.max_chain_index + 1) * cluster_size;
|
||||
|
||||
} else {
|
||||
if (p_file->p_sfd->dir_entry.file_size != 0) {
|
||||
err = PFFAT_TraceClustersChain(&p_file->p_sfd->ffd, p_file->p_sfd->dir_entry.start_cluster, p_file->p_sfd->dir_entry.file_size,
|
||||
&file_end_cluster, &spare_cluster);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
} else {
|
||||
spare_cluster = p_file->p_sfd->dir_entry.start_cluster;
|
||||
}
|
||||
|
||||
sig_eoc = PFFAT_GetValueOfEOC2(p_vol);
|
||||
num_append_cluster = 0;
|
||||
for (; spare_cluster != sig_eoc; spare_cluster = next_cluster) {
|
||||
num_append_cluster++;
|
||||
err = PFFAT_ReadValueToSpecifiedCluster(p_vol, spare_cluster, &next_cluster);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
total_allocated_size = file_cluster_size + (num_append_cluster * cluster_size);
|
||||
}
|
||||
*p_size = total_allocated_size - file_cluster_size;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFCLUSTER_CombineFiles(PFCLUSTER_ENT_ITER* p_first_iter, PFCLUSTER_ENT_ITER* p_second_iter,
|
||||
PF_DIR_ENT* p_first_entry, PF_DIR_ENT* p_second_entry) {
|
||||
pf_s32 err;
|
||||
pf_u32 end_cluster;
|
||||
pf_u32 spare_cluster;
|
||||
pf_u32 cluster_size;
|
||||
pf_u32 first_used_clusters;
|
||||
pf_u32 second_used_clusters;
|
||||
pf_u32 first_spare_clusters;
|
||||
pf_u32 second_spare_clusters;
|
||||
pf_u32 excess_clusters;
|
||||
pf_u32 first_end_cluster;
|
||||
pf_u32 first_spare_cluster;
|
||||
pf_u32 second_spare_cluster;
|
||||
pf_u32 sig_eoc;
|
||||
PF_VOLUME* p_vol;
|
||||
|
||||
p_vol = p_first_entry->p_vol;
|
||||
first_used_clusters = 0;
|
||||
second_used_clusters = 0;
|
||||
first_spare_clusters = 0;
|
||||
second_spare_clusters = 0;
|
||||
first_spare_cluster = 0;
|
||||
err = PFFAT_TraceClustersChain(&p_first_iter->ffd, *p_first_iter->ffd.p_start_cluster,
|
||||
p_first_entry->file_size, &end_cluster, &spare_cluster);
|
||||
if (err != 0) return err;
|
||||
cluster_size = p_vol->bpb.bytes_per_sector << p_vol->bpb.log2_sectors_per_cluster;
|
||||
first_end_cluster = end_cluster;
|
||||
if (p_first_entry->file_size != 0) {
|
||||
first_used_clusters = p_first_entry->file_size / cluster_size;
|
||||
if (p_first_entry->file_size % cluster_size != 0) ++first_used_clusters;
|
||||
}
|
||||
sig_eoc = PFFAT_GetValueOfEOC2(p_vol);
|
||||
if (spare_cluster != sig_eoc) {
|
||||
if (p_first_entry->file_size != 0 && spare_cluster != 0) first_spare_cluster = spare_cluster;
|
||||
else first_spare_cluster = *p_first_iter->ffd.p_start_cluster;
|
||||
err = PFFAT_TraceClustersChain(&p_first_iter->ffd, first_spare_cluster, -1U, &end_cluster, &spare_cluster);
|
||||
if (err != 0) return err;
|
||||
if (*p_first_iter->ffd.p_start_cluster != 0) {
|
||||
first_spare_clusters = p_first_iter->ffd.last_cluster.max_chain_index + 1 - first_used_clusters;
|
||||
}
|
||||
}
|
||||
err = PFFAT_TraceClustersChain(&p_second_iter->ffd, *p_second_iter->ffd.p_start_cluster,
|
||||
p_second_entry->file_size, &end_cluster, &spare_cluster);
|
||||
if (err != 0) return err;
|
||||
if (p_second_entry->file_size != 0) {
|
||||
second_used_clusters = p_second_entry->file_size / cluster_size;
|
||||
if (p_second_entry->file_size % cluster_size != 0) ++second_used_clusters;
|
||||
}
|
||||
second_spare_cluster = spare_cluster;
|
||||
if (second_spare_cluster != sig_eoc) {
|
||||
if (p_second_entry->file_size != 0 && spare_cluster != 0) {
|
||||
second_spare_cluster = spare_cluster;
|
||||
} else second_spare_cluster = *p_second_iter->ffd.p_start_cluster;
|
||||
err = PFFAT_TraceClustersChain(&p_second_iter->ffd, second_spare_cluster, -1U, &end_cluster, &spare_cluster);
|
||||
if (err != 0) return err;
|
||||
if (*p_second_iter->ffd.p_start_cluster != 0) {
|
||||
second_spare_clusters = p_second_iter->ffd.last_cluster.max_chain_index + 1 - second_used_clusters;
|
||||
}
|
||||
if (-1U / cluster_size + 1 < (second_used_clusters + second_spare_clusters) + first_used_clusters) {
|
||||
excess_clusters = (second_used_clusters + second_spare_clusters) + first_used_clusters - (-1U / cluster_size + 1);
|
||||
err = PFFAT_TraceClustersChain(&p_second_iter->ffd, second_spare_cluster,
|
||||
cluster_size * ((p_second_iter->ffd.last_cluster.max_chain_index + 1 - excess_clusters) - second_used_clusters),
|
||||
&end_cluster, &spare_cluster);
|
||||
if (err != 0) return err;
|
||||
err = PFFAT_WriteValueToSpecifiedCluster(p_vol, end_cluster, sig_eoc);
|
||||
if (err != 0) return err;
|
||||
err = PFFAT_FreeChain(&p_second_iter->ffd, spare_cluster, -1U, excess_clusters * cluster_size);
|
||||
if (err != 0) return err;
|
||||
if (p_second_entry->file_size == 0 && second_spare_clusters == excess_clusters) {
|
||||
*p_second_iter->ffd.p_start_cluster = 0;
|
||||
p_second_entry->start_cluster = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (first_spare_clusters != 0) {
|
||||
err = PFFAT_FreeChain(&p_first_iter->ffd, first_spare_cluster, -1U, first_spare_clusters * cluster_size);
|
||||
if (err != 0) return err;
|
||||
if (p_first_entry->file_size == 0) {
|
||||
*p_first_iter->ffd.p_start_cluster = 0;
|
||||
p_first_entry->start_cluster = 0;
|
||||
}
|
||||
}
|
||||
if (*p_first_iter->ffd.p_start_cluster != 0 && *p_second_iter->ffd.p_start_cluster != 0) {
|
||||
err = PFFAT_WriteValueToSpecifiedCluster(p_vol, first_end_cluster, *p_second_iter->ffd.p_start_cluster);
|
||||
if (err != 0) return err;
|
||||
} else if (*p_first_iter->ffd.p_start_cluster == 0 && *p_second_iter->ffd.p_start_cluster != 0) {
|
||||
p_first_entry->start_cluster = p_second_entry->start_cluster;
|
||||
}
|
||||
p_first_entry->file_size = p_second_entry->file_size + first_used_clusters * cluster_size;
|
||||
return 0;
|
||||
}
|
||||
pf_s32 PFCLUSTER_DivideFile(PFCLUSTER_ENT_ITER* p_source_iter, PFCLUSTER_ENT_ITER* p_dest_iter,
|
||||
PF_DIR_ENT* p_source_entry, PF_DIR_ENT* p_dest_entry, pf_u32 split_size) {
|
||||
pf_s32 err;
|
||||
pf_u32 source_end;
|
||||
pf_u32 success_size;
|
||||
pf_u32 allocated_start;
|
||||
pf_u32 allocated_end;
|
||||
pf_u32 dest_cluster;
|
||||
PF_CACHE_PAGE* p_page;
|
||||
pf_bool cache_hit;
|
||||
pf_u32 source_sector;
|
||||
pf_u32 dest_sector;
|
||||
pf_u32 sector_index;
|
||||
pf_u32 cluster_size;
|
||||
pf_u32 last_cluster;
|
||||
pf_u32 allocated_size;
|
||||
pf_u32 dest_first;
|
||||
pf_u32 remaining;
|
||||
PF_VOLUME* p_vol;
|
||||
pf_u32 saved_next;
|
||||
pf_u32 sig_eoc;
|
||||
|
||||
allocated_start = 0;
|
||||
p_vol = p_source_entry->p_vol;
|
||||
dest_first = 0;
|
||||
last_cluster = 0;
|
||||
remaining = 0;
|
||||
|
||||
if (split_size == 0) {
|
||||
dest_cluster = p_source_entry->start_cluster;
|
||||
} else {
|
||||
err = PFFAT_TraceClustersChain(&p_source_iter->ffd, *p_source_iter->ffd.p_start_cluster,
|
||||
split_size, &source_end, &dest_cluster);
|
||||
if (err != 0) return err;
|
||||
saved_next = dest_cluster;
|
||||
sig_eoc = PFFAT_GetValueOfEOC2(p_vol);
|
||||
err = PFFAT_WriteValueToSpecifiedCluster(p_vol, source_end, sig_eoc);
|
||||
if (err != 0) return err;
|
||||
if (split_size == p_source_entry->file_size) {
|
||||
if (dest_cluster == sig_eoc) dest_cluster = 0;
|
||||
} else {
|
||||
cluster_size = p_vol->bpb.bytes_per_sector << p_vol->bpb.log2_sectors_per_cluster;
|
||||
remaining = split_size % cluster_size;
|
||||
if (remaining != 0) {
|
||||
for (allocated_size = 0; allocated_size < cluster_size; ) {
|
||||
err = PFFAT_AllocateNumClusters(&p_dest_iter->ffd, cluster_size,
|
||||
&allocated_start, &allocated_end, &success_size);
|
||||
if (err != 0) {
|
||||
PFFAT_WriteValueToSpecifiedCluster(p_vol, source_end, saved_next);
|
||||
return err;
|
||||
}
|
||||
if (success_size == 0) break;
|
||||
if (allocated_size == 0) {
|
||||
dest_first = allocated_start;
|
||||
} else {
|
||||
err = PFFAT_WriteValueToSpecifiedCluster(p_vol, last_cluster, allocated_start);
|
||||
if (err != 0) {
|
||||
PFFAT_FreeChain(&p_dest_iter->ffd, dest_first, -1U, allocated_size);
|
||||
PFFAT_WriteValueToSpecifiedCluster(p_vol, source_end, saved_next);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
allocated_size += success_size;
|
||||
last_cluster = allocated_end;
|
||||
}
|
||||
if (cluster_size != allocated_size) {
|
||||
if (allocated_size != 0) {
|
||||
err = PFFAT_FreeChain(&p_dest_iter->ffd, dest_first, -1U, allocated_size);
|
||||
if (err != 0) {
|
||||
PFFAT_WriteValueToSpecifiedCluster(p_vol, source_end, saved_next);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
PFFAT_FreeChain(&p_dest_iter->ffd, dest_first, -1U, allocated_size);
|
||||
PFFAT_WriteValueToSpecifiedCluster(p_vol, source_end, saved_next);
|
||||
return 6;
|
||||
}
|
||||
err = PFFAT_WriteValueToSpecifiedCluster(p_vol, last_cluster, dest_cluster);
|
||||
if (err != 0) {
|
||||
PFFAT_FreeChain(&p_dest_iter->ffd, dest_first, -1U, allocated_size);
|
||||
PFFAT_WriteValueToSpecifiedCluster(p_vol, source_end, saved_next);
|
||||
return err;
|
||||
}
|
||||
dest_cluster = dest_first;
|
||||
source_sector = p_vol->bpb.first_data_sector + ((source_end - 2) << p_vol->bpb.log2_sectors_per_cluster);
|
||||
dest_sector = p_vol->bpb.first_data_sector + ((allocated_start - 2) << p_vol->bpb.log2_sectors_per_cluster);
|
||||
err = PFCACHE_AllocateDataPage(p_vol, -1U, &p_page, &cache_hit);
|
||||
if (err != 0) {
|
||||
PFFAT_FreeChain(&p_dest_iter->ffd, dest_first, -1U, allocated_size);
|
||||
PFFAT_WriteValueToSpecifiedCluster(p_vol, source_end, saved_next);
|
||||
return err;
|
||||
}
|
||||
for (sector_index = 0; sector_index < p_vol->bpb.sectors_per_cluster; ++sector_index) {
|
||||
err = PFSEC_ReadData(p_vol, p_page->p_buf, source_sector, 0,
|
||||
p_vol->bpb.bytes_per_sector, &success_size, 0);
|
||||
if (err != 0) {
|
||||
PFFAT_FreeChain(&p_dest_iter->ffd, dest_first, -1U, allocated_size);
|
||||
PFFAT_WriteValueToSpecifiedCluster(p_vol, source_end, saved_next);
|
||||
return err;
|
||||
}
|
||||
if (success_size != p_vol->bpb.bytes_per_sector) {
|
||||
PFFAT_FreeChain(&p_dest_iter->ffd, dest_first, -1U, allocated_size);
|
||||
PFFAT_WriteValueToSpecifiedCluster(p_vol, source_end, saved_next);
|
||||
return 17;
|
||||
}
|
||||
err = PFSEC_WriteData(p_vol, p_page->p_buf, dest_sector, 0,
|
||||
p_vol->bpb.bytes_per_sector, &success_size, 0);
|
||||
if (err != 0) {
|
||||
PFFAT_FreeChain(&p_dest_iter->ffd, dest_first, -1U, allocated_size);
|
||||
PFFAT_WriteValueToSpecifiedCluster(p_vol, source_end, saved_next);
|
||||
return err;
|
||||
}
|
||||
if (success_size != p_vol->bpb.bytes_per_sector) {
|
||||
PFFAT_FreeChain(&p_dest_iter->ffd, dest_first, -1U, allocated_size);
|
||||
PFFAT_WriteValueToSpecifiedCluster(p_vol, source_end, saved_next);
|
||||
return 17;
|
||||
}
|
||||
++source_sector;
|
||||
++dest_sector;
|
||||
}
|
||||
PFCACHE_FreeDataPage(p_vol, p_page);
|
||||
}
|
||||
}
|
||||
}
|
||||
p_dest_entry->start_cluster = dest_cluster;
|
||||
p_dest_entry->file_size = p_source_entry->file_size - split_size + remaining;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFCLUSTER_InsertCluster(PFCLUSTER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent,
|
||||
pf_u32 cluster_index, pf_u32 num_clusters, pf_u32* p_inserted_clusters) {
|
||||
pf_s32 err;
|
||||
pf_u32 previous_cluster;
|
||||
pf_u32 next_cluster;
|
||||
pf_u32 success_size;
|
||||
pf_u32 allocated_start;
|
||||
pf_u32 allocated_end;
|
||||
pf_u32 cluster_size;
|
||||
pf_u32 allocated_size;
|
||||
pf_u32 first_cluster;
|
||||
pf_u32 last_cluster;
|
||||
pf_u32 requested_size;
|
||||
pf_u32 file_clusters;
|
||||
pf_u32 remainder;
|
||||
pf_u32 extra_size;
|
||||
PF_VOLUME* p_vol;
|
||||
|
||||
p_vol = p_ent->p_vol;
|
||||
cluster_size = p_vol->bpb.bytes_per_sector << p_vol->bpb.log2_sectors_per_cluster;
|
||||
first_cluster = 0;
|
||||
last_cluster = 0;
|
||||
err = PFFAT_TraceClustersChain(&p_iter->ffd, *p_iter->ffd.p_start_cluster,
|
||||
cluster_index * cluster_size, &previous_cluster, &next_cluster);
|
||||
if (err != 0) return err;
|
||||
file_clusters = p_ent->file_size / cluster_size;
|
||||
if (p_ent->file_size % cluster_size != 0) ++file_clusters;
|
||||
if (-1U / cluster_size + 1 < file_clusters + num_clusters) {
|
||||
num_clusters = file_clusters + num_clusters - (-1U / cluster_size + 1);
|
||||
}
|
||||
requested_size = num_clusters * cluster_size;
|
||||
for (allocated_size = 0; allocated_size < requested_size; ) {
|
||||
err = PFFAT_AllocateNumClusters(&p_iter->ffd, requested_size, &allocated_start, &allocated_end, &success_size);
|
||||
if (err != 0) return err;
|
||||
if (success_size == 0) {
|
||||
if (allocated_size != 0) break;
|
||||
return 6;
|
||||
}
|
||||
if (allocated_size == 0) first_cluster = allocated_start;
|
||||
else {
|
||||
err = PFFAT_WriteValueToSpecifiedCluster(p_vol, last_cluster, allocated_start);
|
||||
if (err != 0) return err;
|
||||
}
|
||||
allocated_size += success_size;
|
||||
last_cluster = allocated_end;
|
||||
}
|
||||
if (next_cluster == 0) {
|
||||
next_cluster = p_ent->start_cluster != 0 ? p_ent->start_cluster : PFFAT_GetValueOfEOC2(p_vol);
|
||||
}
|
||||
err = PFFAT_WriteValueToSpecifiedCluster(p_vol, last_cluster, next_cluster);
|
||||
if (err != 0) return err;
|
||||
if (cluster_index != 0) {
|
||||
err = PFFAT_WriteValueToSpecifiedCluster(p_vol, previous_cluster, first_cluster);
|
||||
if (err != 0) return err;
|
||||
} else p_ent->start_cluster = first_cluster;
|
||||
file_clusters = p_ent->file_size / cluster_size;
|
||||
remainder = p_ent->file_size % cluster_size;
|
||||
if (remainder != 0) ++file_clusters;
|
||||
extra_size = 0;
|
||||
if (cluster_index == file_clusters && remainder != 0) extra_size = cluster_size - remainder;
|
||||
p_ent->file_size += allocated_size + extra_size;
|
||||
*p_inserted_clusters = allocated_size / cluster_size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFCLUSTER_DeleteCluster(PFCLUSTER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent,
|
||||
pf_u32 cluster_index, pf_u32 num_clusters, pf_u32* p_deleted_clusters) {
|
||||
pf_s32 err;
|
||||
pf_u32 previous_cluster;
|
||||
pf_u32 next_cluster;
|
||||
pf_u32 first_deleted_cluster;
|
||||
pf_u32 last_deleted_cluster;
|
||||
PF_VOLUME* p_vol;
|
||||
pf_u32 cluster_size;
|
||||
pf_u32 byte_position;
|
||||
|
||||
p_vol = p_ent->p_vol;
|
||||
cluster_size = p_vol->bpb.bytes_per_sector << p_vol->bpb.log2_sectors_per_cluster;
|
||||
byte_position = cluster_index * cluster_size;
|
||||
err = PFFAT_TraceClustersChain(&p_iter->ffd, *p_iter->ffd.p_start_cluster,
|
||||
byte_position, &previous_cluster, &first_deleted_cluster);
|
||||
if (err != 0) return err;
|
||||
if (cluster_index == 0) first_deleted_cluster = p_ent->start_cluster;
|
||||
num_clusters = num_clusters * cluster_size;
|
||||
if (num_clusters > p_ent->file_size - byte_position) num_clusters = p_ent->file_size - byte_position;
|
||||
err = PFFAT_TraceClustersChain(&p_iter->ffd, first_deleted_cluster, num_clusters, &last_deleted_cluster, &next_cluster);
|
||||
if (err != 0) return err;
|
||||
if (cluster_index == 0) {
|
||||
if (next_cluster == PFFAT_GetValueOfEOC2(p_vol)) next_cluster = 0;
|
||||
p_ent->start_cluster = next_cluster;
|
||||
}
|
||||
p_ent->file_size -= num_clusters;
|
||||
PFENT_getcurrentDateTimeForEnt(&p_ent->modify_date, &p_ent->modify_time);
|
||||
p_ent->access_date = p_ent->modify_date;
|
||||
err = PFENT_updateEntry(p_ent, 1);
|
||||
if (err != 0) return err;
|
||||
if (p_vol->cache_mode & 4) {
|
||||
err = PFCACHE_FlushDataCacheSpecific(p_vol, PF_NULL);
|
||||
if (err != 0) return err;
|
||||
}
|
||||
err = PFFAT_FreeChain(&p_iter->ffd, first_deleted_cluster, -1U, num_clusters);
|
||||
if (err != 0) return err;
|
||||
if (cluster_index != 0) {
|
||||
err = PFFAT_WriteValueToSpecifiedCluster(p_vol, previous_cluster, next_cluster);
|
||||
if (err != 0) return err;
|
||||
}
|
||||
*p_deleted_clusters = num_clusters / cluster_size;
|
||||
if (num_clusters % cluster_size != 0) ++*p_deleted_clusters;
|
||||
return 0;
|
||||
}
|
||||
21
libs/RVL_SDK/src/fa/pf_code.c
Normal file
21
libs/RVL_SDK/src/fa/pf_code.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <private/vf/PrFILE2/pf_types.h>
|
||||
|
||||
// clang-format off
|
||||
const pf_u8 pf_valid_fn_char_8162E6B0[96] = {
|
||||
1, 3, 0, 3, 3, 3, 3, 3, 3, 3, 0, 1, 1, 3, 3, 0,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 1, 0, 1, 0, 0,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 0, 1, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 3, 3, 0,
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
pf_s32 PFCODE_Combine_Width(pf_s16 oem_width, pf_s16 uni_width) {
|
||||
return (oem_width << 16) + uni_width;
|
||||
}
|
||||
|
||||
void PFCODE_Divide_Width(pf_s32 width, pf_s16* oem_width, pf_s16* uni_width) {
|
||||
*oem_width = (width & 0xFFFF0000) >> 16;
|
||||
*uni_width = (width & 0x0000FFFF);
|
||||
}
|
||||
178
libs/RVL_SDK/src/fa/pf_cp932.c
Normal file
178
libs/RVL_SDK/src/fa/pf_cp932.c
Normal file
@@ -0,0 +1,178 @@
|
||||
#define PF_FA_CP932_TABLE
|
||||
#define VFiPFCODE_CP932_OEM2Unicode PFCODE_CP932_OEM2Unicode
|
||||
#define VFiPFCODE_CP932_OEMCharWidth PFCODE_CP932_OEMCharWidth
|
||||
#define VFiPFCODE_CP932_Unicode2OEM PFCODE_CP932_Unicode2OEM
|
||||
#define VFiPFCODE_CP932_UnicodeCharWidth PFCODE_CP932_UnicodeCharWidth
|
||||
#define VFiPFCODE_CP932_isOEMMBchar PFCODE_CP932_isOEMMBchar
|
||||
#define VFiPFCODE_CP932_isUnicodeMBchar PFCODE_CP932_isUnicodeMBchar
|
||||
#define VFiPFCODE_Combine_Width PFCODE_Combine_Width
|
||||
#define VFiPFCODE_Divide_Width PFCODE_Divide_Width
|
||||
|
||||
#include <private/vf/PrFILE2/local/pf_cp932.h>
|
||||
#include <private/vf/PrFILE2/local/pf_cp932_to_unicode.h>
|
||||
|
||||
#include <private/vf/PrFILE2/common/pf_code.h>
|
||||
|
||||
pf_s32 VFiPFCODE_CP932_OEM2Unicode(const pf_s8* cp932_src, pf_u16* uc_dst) {
|
||||
pf_u8 cp932_lead = *cp932_src++;
|
||||
pf_u8 cp932_trail = *cp932_src;
|
||||
pf_s32 lead_index;
|
||||
pf_s32 trail_index;
|
||||
|
||||
if (cp932_lead < 0x80) {
|
||||
*uc_dst = cp932_lead;
|
||||
return VFiPFCODE_Combine_Width(1, 2);
|
||||
}
|
||||
if (cp932_lead >= 0xA1 && cp932_lead <= 0xDF) {
|
||||
*uc_dst = cp932_lead + 0xFEC0;
|
||||
return VFiPFCODE_Combine_Width(1, 2);
|
||||
}
|
||||
if (cp932_lead == 0x80 || cp932_lead == 0x85 || cp932_lead == 0x86 || cp932_lead == 0xA0 || cp932_lead == 0xEB ||
|
||||
cp932_lead == 0xEC || (cp932_lead >= 0xEF && cp932_lead <= 0xF9) ||
|
||||
(cp932_lead >= 0xFD && cp932_lead == 0xFF)) {
|
||||
*uc_dst = '_';
|
||||
return VFiPFCODE_Combine_Width(1, 2);
|
||||
}
|
||||
if (cp932_trail >= 0xFD) {
|
||||
*uc_dst = '_';
|
||||
return VFiPFCODE_Combine_Width(1, 2);
|
||||
}
|
||||
if (cp932_lead >= 0x81 && cp932_lead <= 0x84) {
|
||||
lead_index = cp932_lead - 0x81;
|
||||
} else if (cp932_lead >= 0x87 && cp932_lead <= 0x9F) {
|
||||
lead_index = cp932_lead - 0x83;
|
||||
} else if (cp932_lead >= 0xE0 && cp932_lead <= 0xEA) {
|
||||
lead_index = cp932_lead - 0xC3;
|
||||
} else if (cp932_lead >= 0xED && cp932_lead <= 0xEE) {
|
||||
lead_index = cp932_lead - 0xC5;
|
||||
} else if (cp932_lead >= 0xFA && cp932_lead <= 0xFC) {
|
||||
lead_index = cp932_lead - 0xD0;
|
||||
} else {
|
||||
*uc_dst = '_';
|
||||
return VFiPFCODE_Combine_Width(1, 2);
|
||||
}
|
||||
|
||||
trail_index = cp932_trail - '@';
|
||||
if (trail_index < 0 || trail_index >= 189) {
|
||||
*uc_dst = '_';
|
||||
return VFiPFCODE_Combine_Width(1, 2);
|
||||
}
|
||||
*uc_dst = cp932_to_unicode[lead_index][trail_index] & 0xFFFF;
|
||||
if (*uc_dst == 0) {
|
||||
*uc_dst = '_';
|
||||
return VFiPFCODE_Combine_Width(1, 2);
|
||||
}
|
||||
return VFiPFCODE_Combine_Width(2, 2);
|
||||
}
|
||||
|
||||
pf_s32 VFiPFCODE_CP932_Unicode2OEM(const pf_u16* uc_src, pf_s8* cp932_dst) {
|
||||
pf_s32 i;
|
||||
pf_s32 j;
|
||||
pf_u16* p_table;
|
||||
pf_u8 uc_lead;
|
||||
pf_u8 uc_trail;
|
||||
pf_u16 uc;
|
||||
pf_u16 cp932;
|
||||
|
||||
j = 0;
|
||||
uc_lead = (pf_u8)(*uc_src >> 8);
|
||||
uc_trail = (pf_u8)*uc_src;
|
||||
if (uc_trail < 0x80 && uc_lead == 0) {
|
||||
cp932_dst[0] = uc_trail;
|
||||
cp932_dst[1] = 0;
|
||||
return VFiPFCODE_Combine_Width(1, 2);
|
||||
}
|
||||
uc = PF_CODE_C_TO_WC(uc_lead, uc_trail);
|
||||
if (0xFF61 <= uc && uc <= 0xFF9F) {
|
||||
cp932 = uc - 0xFEC0;
|
||||
cp932_dst[0] = cp932;
|
||||
cp932_dst[1] = 0;
|
||||
return VFiPFCODE_Combine_Width(1, 2);
|
||||
}
|
||||
if (uc == '_') {
|
||||
cp932_dst[0] = '_';
|
||||
return VFiPFCODE_Combine_Width(1, 2);
|
||||
}
|
||||
|
||||
for (i = 0; i < 45; i++) {
|
||||
for (j = 0, p_table = (pf_u16*)&cp932_to_unicode[i]; j < 189; j++, p_table++) {
|
||||
if (*p_table == uc) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j < 189) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j == 189) {
|
||||
cp932_dst[0] = '_';
|
||||
return VFiPFCODE_Combine_Width(1, 2);
|
||||
}
|
||||
|
||||
if (i >= 0 && i <= 3) {
|
||||
cp932 = ((i + 0x81) << 8) | (j + '@');
|
||||
} else if (i >= 4 && i <= 0x1C) {
|
||||
cp932 = ((i + 0x83) << 8) | (j + '@');
|
||||
} else if (i >= 0x1D && i <= '\'') {
|
||||
cp932 = ((i + 0xC3) << 8) | (j + '@');
|
||||
} else if (i >= '(' && i <= ')') {
|
||||
cp932 = ((i + 0xC5) << 8) | (j + '@');
|
||||
} else if (i >= '*' && i <= ',') {
|
||||
cp932 = ((i + 0xD0) << 8) | (j + '@');
|
||||
} else {
|
||||
cp932_dst[0] = '_';
|
||||
return VFiPFCODE_Combine_Width(1, 2);
|
||||
}
|
||||
|
||||
cp932_dst[0] = (pf_u8)(cp932 >> 8);
|
||||
cp932_dst[1] = (pf_u8)cp932;
|
||||
return VFiPFCODE_Combine_Width(2, 2);
|
||||
}
|
||||
|
||||
pf_s32 VFiPFCODE_CP932_OEMCharWidth(const pf_s8* buf) {
|
||||
pf_u16 tmp;
|
||||
pf_s32 width;
|
||||
pf_s16 oem_width;
|
||||
pf_s16 uni_width;
|
||||
|
||||
width = VFiPFCODE_CP932_OEM2Unicode(buf, &tmp);
|
||||
VFiPFCODE_Divide_Width(width, &oem_width, &uni_width);
|
||||
return (pf_s32)oem_width;
|
||||
}
|
||||
|
||||
pf_bool VFiPFCODE_CP932_isOEMMBchar(pf_s8 cp932, pf_u32 num) {
|
||||
pf_u8 code;
|
||||
pf_bool is_mb;
|
||||
|
||||
code = (pf_u8)cp932;
|
||||
|
||||
switch (num) {
|
||||
case 1: {
|
||||
is_mb = (code >= 0x81 && code <= 0x9F) || (code >= 0xE0 && code <= 0xFC);
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
is_mb = (code >= '@' && code <= '~') || (code >= 0x80 && code <= 0xFC);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
is_mb = PF_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return is_mb;
|
||||
}
|
||||
|
||||
pf_s32 VFiPFCODE_CP932_UnicodeCharWidth(const pf_u16* buf) {
|
||||
pf_s8 tmp[2];
|
||||
pf_s32 width;
|
||||
pf_s16 oem_width;
|
||||
pf_s16 uni_width;
|
||||
width = VFiPFCODE_CP932_Unicode2OEM(buf, tmp);
|
||||
VFiPFCODE_Divide_Width(width, &oem_width, &uni_width);
|
||||
return uni_width;
|
||||
}
|
||||
|
||||
pf_bool VFiPFCODE_CP932_isUnicodeMBchar(pf_u16 uc_src, pf_u32 num) {
|
||||
return PF_FALSE;
|
||||
}
|
||||
36
libs/RVL_SDK/src/fa/pf_create.c
Normal file
36
libs/RVL_SDK/src/fa/pf_create.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#define PF_FA_STR_LAYOUT
|
||||
#define VFiPFAPI_convertReturnValue2NULL PFAPI_convertReturnValue2NULL
|
||||
#define VFiPFFILE_fopen PFFILE_fopen
|
||||
#define VFiPFSTR_InitStr PFSTR_InitStr
|
||||
#include <private/vf/PrFILE2/standard/pf_create.h>
|
||||
|
||||
typedef struct PFAPI_GLOBAL_STATE {
|
||||
pf_u8 volume_state[0x40];
|
||||
pf_s32 last_error;
|
||||
} PFAPI_GLOBAL_STATE;
|
||||
extern PFAPI_GLOBAL_STATE pf_vol_set;
|
||||
|
||||
|
||||
#include <private/vf/PrFILE2/fatfs/pf_volume.h>
|
||||
#include <private/vf/PrFILE2/standard/pf_api_util.h>
|
||||
|
||||
PF_FILE* pf2_create(const pf_ch8* path, pf_int32 mode) {
|
||||
pf_u32 open_mode_create;
|
||||
PF_FILE* p_file;
|
||||
PF_STR path_str;
|
||||
pf_s32 err;
|
||||
|
||||
(void)mode;
|
||||
|
||||
open_mode_create = 0x19;
|
||||
|
||||
err = VFiPFSTR_InitStr(&path_str, (pf_s8*)path, 1U);
|
||||
if (err == 0) {
|
||||
err = VFiPFFILE_fopen(&path_str, open_mode_create, &p_file);
|
||||
} else {
|
||||
pf_vol_set.last_error = err;
|
||||
}
|
||||
p_file = VFiPFAPI_convertReturnValue2NULL(err, p_file);
|
||||
|
||||
return p_file;
|
||||
}
|
||||
13
libs/RVL_SDK/src/fa/pf_detach.c
Normal file
13
libs/RVL_SDK/src/fa/pf_detach.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#define PF_FA_STR_LAYOUT
|
||||
#define VFiPFAPI_convertReturnValue PFAPI_convertReturnValue
|
||||
#define VFiPFVOL_detach PFVOL_detach
|
||||
#include <private/vf/PrFILE2/standard/pf_detach.h>
|
||||
|
||||
#include <private/vf/PrFILE2/fatfs/pf_volume.h>
|
||||
#include <private/vf/PrFILE2/standard/pf_api_util.h>
|
||||
|
||||
pf_int32 pf2_detach(pf_ch8 drive) {
|
||||
pf_s32 err = VFiPFVOL_detach(drive);
|
||||
err = VFiPFAPI_convertReturnValue(err);
|
||||
return err;
|
||||
}
|
||||
442
libs/RVL_SDK/src/fa/pf_driver.c
Normal file
442
libs/RVL_SDK/src/fa/pf_driver.c
Normal file
@@ -0,0 +1,442 @@
|
||||
#include <private/vf/PrFILE2/pf_types.h>
|
||||
|
||||
typedef struct PFDRV_BPB {
|
||||
pf_u16 bytes_per_sector; // 0x00
|
||||
pf_u8 pad_02[0x12]; // 0x02
|
||||
pf_u16 fs_info_sector; // 0x14
|
||||
pf_u8 pad_16[0x6]; // 0x16
|
||||
pf_s32 fat_type; // 0x1C
|
||||
pf_u8 tail[0x38 - 0x20]; // 0x20
|
||||
} PFDRV_BPB;
|
||||
|
||||
typedef struct PFDRV_VOLUME {
|
||||
PFDRV_BPB bpb; // 0x00
|
||||
pf_u32 num_free_clusters; // 0x38
|
||||
pf_u32 last_free_cluster; // 0x3C
|
||||
pf_u8 file_and_dir_state[0x1648 - 0x40]; // 0x40
|
||||
pf_s8 label[12]; // 0x1648
|
||||
pf_u8 tail_1654[0x1F84 - 0x1654]; // 0x1654
|
||||
pf_s32 last_driver_error; // 0x1F84
|
||||
pf_u32 reserved_1f88; // 0x1F88
|
||||
pf_u16 flags; // 0x1F8C
|
||||
pf_u16 options; // 0x1F8E
|
||||
pf_u16 fsi_flag; // 0x1F90
|
||||
pf_u16 cluster_link_flags; // 0x1F92
|
||||
pf_u16 cluster_link_interval; // 0x1F94
|
||||
pf_u32* cluster_link_buffer; // 0x1F98
|
||||
pf_u32 cluster_link_capacity; // 0x1F9C
|
||||
void* driver_partition; // 0x1FA0
|
||||
pf_u8 gap_1fa4[4]; // 0x1FA4
|
||||
const pf_u8* format_options; // 0x1FA8
|
||||
} PFDRV_VOLUME;
|
||||
|
||||
typedef struct PFDRV_VOLUME_SET {
|
||||
pf_u8 state_prefix[0x40]; // 0x00
|
||||
pf_s32 last_error; // 0x40
|
||||
pf_s32 last_driver_error; // 0x44
|
||||
pf_u8 tail_48[0x88 - 0x48]; // 0x48
|
||||
PFDRV_VOLUME volumes[26]; // 0x88
|
||||
} PFDRV_VOLUME_SET;
|
||||
|
||||
extern PFDRV_VOLUME_SET pf_vol_set;
|
||||
|
||||
typedef struct PFDRV_CACHE_PAGE {
|
||||
pf_u16 stat;
|
||||
pf_u16 option;
|
||||
pf_u8* buffer;
|
||||
pf_u8* p_buf;
|
||||
pf_u8* p_mod_sbuf;
|
||||
pf_u8* p_mod_ebuf;
|
||||
pf_u32 size;
|
||||
pf_u32 sector;
|
||||
void* signature;
|
||||
struct PFDRV_CACHE_PAGE* p_next;
|
||||
struct PFDRV_CACHE_PAGE* p_prev;
|
||||
} PFDRV_CACHE_PAGE;
|
||||
|
||||
typedef struct PFDRV_PART_FUNC {
|
||||
void (*insert)(void* partition);
|
||||
void (*eject)(void* partition);
|
||||
} PFDRV_PART_FUNC;
|
||||
|
||||
typedef struct PFDRV_MEDIA_INFO {
|
||||
pf_u32 total_sectors; // 0x00
|
||||
pf_u16 cylinders; // 0x04
|
||||
pf_u8 heads; // 0x06
|
||||
pf_u8 sectors_per_track; // 0x07
|
||||
pf_u16 bytes_per_sector; // 0x08
|
||||
pf_u16 reserved_0a; // 0x0A
|
||||
pf_u32 media_attr; // 0x0C
|
||||
const pf_u8* format_param; // 0x10
|
||||
} PFDRV_MEDIA_INFO;
|
||||
|
||||
typedef struct PFDRV_VOLUME_INFO {
|
||||
pf_s8 label[12]; // 0x00
|
||||
pf_u8 tail[8]; // 0x0C
|
||||
} PFDRV_VOLUME_INFO;
|
||||
|
||||
enum {
|
||||
FAT_32 = 2
|
||||
};
|
||||
|
||||
extern void* pf_memcpy(void* dst, const void* src, pf_u32 length);
|
||||
|
||||
extern pf_s32 PFCACHE_AllocateDataPage(PFDRV_VOLUME* volume, pf_u32 sector, PFDRV_CACHE_PAGE** p_page, pf_u32* option);
|
||||
extern void PFCACHE_FreeDataPage(PFDRV_VOLUME* volume, PFDRV_CACHE_PAGE* p_page);
|
||||
|
||||
extern pf_s32 pdm_part_logical_read(void* partition, pf_u8* buffer, pf_u32 sector, pf_u32 num_sector, pf_u16 bps,
|
||||
pf_u32* p_num_success);
|
||||
extern pf_s32 pdm_part_logical_write(void* partition, const pf_u8* buffer, pf_u32 sector, pf_u32 num_sector, pf_u16 bps,
|
||||
pf_u32* p_num_success);
|
||||
extern pf_s32 pdm_part_register_callback(void* partition, const PFDRV_PART_FUNC* func);
|
||||
extern pf_s32 pdm_part_unregister_callback(void* partition);
|
||||
extern pf_s32 pdm_part_init(void* partition);
|
||||
extern pf_s32 pdm_part_finalize(void* partition);
|
||||
extern pf_s32 pdm_part_mount(void* partition);
|
||||
extern pf_s32 pdm_part_unmount(void* partition, pf_u32 mode);
|
||||
extern pf_s32 pdm_part_get_media_attribute(void* partition, PFDRV_MEDIA_INFO* info);
|
||||
extern pf_s32 pdm_part_get_driver_error_code(void* partition);
|
||||
extern pf_s32 pdm_part_format(void* partition, const pf_u8* format_param);
|
||||
extern pf_s32 pdm_bpb_InitVolumeWithBootSector(PFDRV_VOLUME* volume, const pf_u8* buf);
|
||||
extern pf_s32 pdm_bpb_InitVolumeWithFSINFOSector(PFDRV_VOLUME* volume, const pf_u8* buf, pf_u32* p_num_free_clusters,
|
||||
pf_u32* p_last_free_cluster);
|
||||
|
||||
void PFDRV_LoadVolumeLabelFromBuf(PFDRV_VOLUME* volume, const pf_u8* buf) {
|
||||
pf_memcpy(volume->label, buf, 0xB);
|
||||
volume->label[0xB] = 0;
|
||||
}
|
||||
|
||||
void PFDRV_StoreVolumeLabelToBuf(PFDRV_VOLUME_INFO* volume_info, PFDRV_VOLUME* volume) {
|
||||
pf_memcpy(volume_info->label, volume->label, 0xB);
|
||||
volume_info->label[0xB] = 0;
|
||||
}
|
||||
|
||||
pf_s32 PFDRV_StoreVolumeLabelToBPB(PFDRV_VOLUME* volume, const pf_s8* label) {
|
||||
PFDRV_CACHE_PAGE* p_page;
|
||||
pf_u32 option;
|
||||
pf_u32 num_sector;
|
||||
pf_s32 err;
|
||||
pf_s32 result;
|
||||
|
||||
err = PFCACHE_AllocateDataPage(volume, -1, &p_page, &option);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = pdm_part_logical_read(volume->driver_partition, p_page->p_buf, 0, 1, volume->bpb.bytes_per_sector, &num_sector);
|
||||
if (err != 0) {
|
||||
if (err == 0x15) {
|
||||
result = pdm_part_get_driver_error_code(volume->driver_partition);
|
||||
pf_vol_set.last_driver_error = result;
|
||||
volume->last_driver_error = result;
|
||||
result = 0x1000;
|
||||
} else {
|
||||
result = -1;
|
||||
}
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
if (result != 0) {
|
||||
PFCACHE_FreeDataPage(volume, p_page);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (num_sector != 1) {
|
||||
PFCACHE_FreeDataPage(volume, p_page);
|
||||
return 0x11;
|
||||
}
|
||||
|
||||
if (volume->bpb.fat_type == FAT_32) {
|
||||
pf_memcpy(p_page->p_buf + 0x47, label, 0xB);
|
||||
} else {
|
||||
pf_memcpy(p_page->p_buf + 0x2B, label, 0xB);
|
||||
}
|
||||
|
||||
err = pdm_part_logical_write(volume->driver_partition, p_page->p_buf, 0, 1, volume->bpb.bytes_per_sector,
|
||||
&num_sector);
|
||||
if (err != 0) {
|
||||
if (err == 0x15) {
|
||||
result = pdm_part_get_driver_error_code(volume->driver_partition);
|
||||
pf_vol_set.last_driver_error = result;
|
||||
volume->last_driver_error = result;
|
||||
result = 0x1000;
|
||||
} else {
|
||||
result = -1;
|
||||
}
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
PFCACHE_FreeDataPage(volume, p_page);
|
||||
if (result != 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (num_sector != 1) {
|
||||
return 0x11;
|
||||
}
|
||||
|
||||
pf_memcpy(volume->label, label, 0xB);
|
||||
volume->label[0xB] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PFDRV_MediaEject(void* partition) {
|
||||
PFDRV_VOLUME* p_vol;
|
||||
pf_u32 i;
|
||||
|
||||
p_vol = pf_vol_set.volumes;
|
||||
for (i = 0; i < 26; p_vol++, i++) {
|
||||
if (p_vol->driver_partition == partition) {
|
||||
if ((p_vol->flags & 0x08) != 0) {
|
||||
p_vol->flags |= 0x20;
|
||||
}
|
||||
p_vol->flags &= ~0x0C;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PFDRV_MediaInsert(void* partition) {
|
||||
PFDRV_VOLUME* p_vol;
|
||||
pf_u32 i;
|
||||
|
||||
p_vol = pf_vol_set.volumes;
|
||||
for (i = 0; i < 26; p_vol++, i++) {
|
||||
if (p_vol->driver_partition == partition) {
|
||||
p_vol->flags |= 0x14;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pf_s32 PFDRV_IsInserted(PFDRV_VOLUME* volume) {
|
||||
return (volume->flags >> 2) & 1;
|
||||
}
|
||||
|
||||
pf_s32 PFDRV_IsMountRequested(PFDRV_VOLUME* volume) {
|
||||
return (volume->flags >> 4) & 1;
|
||||
}
|
||||
|
||||
void PFDRV_ClearMountRequested(PFDRV_VOLUME* volume) {
|
||||
volume->flags &= ~0x10;
|
||||
}
|
||||
|
||||
pf_s32 PFDRV_IsUnmountRequested(PFDRV_VOLUME* volume) {
|
||||
return (volume->flags >> 5) & 1;
|
||||
}
|
||||
|
||||
void PFDRV_ClearUnmountRequested(PFDRV_VOLUME* volume) {
|
||||
volume->flags &= ~0x20;
|
||||
}
|
||||
|
||||
pf_s32 PFDRV_init(PFDRV_VOLUME* volume) {
|
||||
PFDRV_PART_FUNC func;
|
||||
pf_s32 err;
|
||||
|
||||
func.insert = PFDRV_MediaInsert;
|
||||
func.eject = PFDRV_MediaEject;
|
||||
|
||||
err = pdm_part_register_callback(volume->driver_partition, &func);
|
||||
if (err != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = pdm_part_init(volume->driver_partition);
|
||||
if (err != 0) {
|
||||
pdm_part_unregister_callback(volume->driver_partition);
|
||||
if (err == 0x15) {
|
||||
err = pdm_part_get_driver_error_code(volume->driver_partition);
|
||||
pf_vol_set.last_driver_error = err;
|
||||
volume->last_driver_error = err;
|
||||
return 0x1000;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFDRV_finalize(PFDRV_VOLUME* volume) {
|
||||
pf_s32 err;
|
||||
|
||||
err = pdm_part_unregister_callback(volume->driver_partition);
|
||||
if (err != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = pdm_part_finalize(volume->driver_partition);
|
||||
if (err != 0) {
|
||||
if (err == 0x15) {
|
||||
err = pdm_part_get_driver_error_code(volume->driver_partition);
|
||||
pf_vol_set.last_driver_error = err;
|
||||
volume->last_driver_error = err;
|
||||
return 0x1000;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFDRV_mount(PFDRV_VOLUME* volume) {
|
||||
PFDRV_MEDIA_INFO info;
|
||||
pf_u32 option;
|
||||
PFDRV_CACHE_PAGE* p_page;
|
||||
pf_u32 num_sector;
|
||||
pf_s32 err;
|
||||
|
||||
err = pdm_part_mount(volume->driver_partition);
|
||||
if (err != 0) {
|
||||
if (err == 0x15) {
|
||||
err = pdm_part_get_driver_error_code(volume->driver_partition);
|
||||
pf_vol_set.last_driver_error = err;
|
||||
volume->last_driver_error = err;
|
||||
return 0x1000;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = pdm_part_get_media_attribute(volume->driver_partition, &info);
|
||||
if (err != 0) {
|
||||
pdm_part_unmount(volume->driver_partition, 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((info.media_attr & 0x01) != 0) {
|
||||
volume->flags |= 0x02;
|
||||
} else {
|
||||
volume->flags &= ~0x02;
|
||||
}
|
||||
if ((info.media_attr & 0x02) != 0) {
|
||||
const pf_u8* format_param = info.format_param;
|
||||
volume->flags |= 0x40;
|
||||
volume->format_options = format_param;
|
||||
}
|
||||
if ((info.media_attr & 0x08) != 0) {
|
||||
volume->flags |= 0x80;
|
||||
}
|
||||
|
||||
PFCACHE_AllocateDataPage(volume, -1, &p_page, &option);
|
||||
|
||||
err = pdm_part_logical_read(volume->driver_partition, p_page->buffer, 0, 1, 0x200, &num_sector);
|
||||
if (err != 0) {
|
||||
if (err == 0x15) {
|
||||
err = pdm_part_get_driver_error_code(volume->driver_partition);
|
||||
pf_vol_set.last_driver_error = err;
|
||||
volume->last_driver_error = err;
|
||||
err = 0x1000;
|
||||
} else {
|
||||
err = -1;
|
||||
}
|
||||
PFCACHE_FreeDataPage(volume, p_page);
|
||||
pdm_part_unmount(volume->driver_partition, 0);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = pdm_bpb_InitVolumeWithBootSector(volume, p_page->buffer);
|
||||
if (err != 0) {
|
||||
PFCACHE_FreeDataPage(volume, p_page);
|
||||
pdm_part_unmount(volume->driver_partition, 0);
|
||||
return 7;
|
||||
}
|
||||
|
||||
volume->num_free_clusters = -1;
|
||||
volume->last_free_cluster = -1;
|
||||
|
||||
if (volume->bpb.fat_type == FAT_32) {
|
||||
err = pdm_part_logical_read(volume->driver_partition, p_page->buffer, volume->bpb.fs_info_sector, 1, 0x200,
|
||||
&num_sector);
|
||||
if (err != 0) {
|
||||
if (err == 0x15) {
|
||||
err = pdm_part_get_driver_error_code(volume->driver_partition);
|
||||
pf_vol_set.last_driver_error = err;
|
||||
volume->last_driver_error = err;
|
||||
err = 0x1000;
|
||||
} else {
|
||||
err = -1;
|
||||
}
|
||||
PFCACHE_FreeDataPage(volume, p_page);
|
||||
pdm_part_unmount(volume->driver_partition, 0);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = pdm_bpb_InitVolumeWithFSINFOSector(volume, p_page->buffer, &volume->num_free_clusters,
|
||||
&volume->last_free_cluster);
|
||||
if (err != 0) {
|
||||
PFCACHE_FreeDataPage(volume, p_page);
|
||||
pdm_part_unmount(volume->driver_partition, 0);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
PFCACHE_FreeDataPage(volume, p_page);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFDRV_unmount(PFDRV_VOLUME* volume, pf_u32 mode) {
|
||||
pf_s32 err;
|
||||
|
||||
err = pdm_part_unmount(volume->driver_partition, mode == 1);
|
||||
if (err != 0) {
|
||||
if (err == 0x15) {
|
||||
err = pdm_part_get_driver_error_code(volume->driver_partition);
|
||||
pf_vol_set.last_driver_error = err;
|
||||
volume->last_driver_error = err;
|
||||
return 0x1000;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFDRV_format(PFDRV_VOLUME* volume, const pf_u8* format_options) {
|
||||
pf_s32 err;
|
||||
|
||||
err = pdm_part_format(volume->driver_partition, format_options);
|
||||
if (err != 0) {
|
||||
if (err == 0x15) {
|
||||
err = pdm_part_get_driver_error_code(volume->driver_partition);
|
||||
pf_vol_set.last_driver_error = err;
|
||||
volume->last_driver_error = err;
|
||||
return 0x1000;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFDRV_lread(PFDRV_VOLUME* volume, pf_u8* buffer, pf_u32 sector, pf_u32 num_sector, pf_u32* p_num_success) {
|
||||
pf_s32 err;
|
||||
|
||||
err = pdm_part_logical_read(volume->driver_partition, buffer, sector, num_sector, volume->bpb.bytes_per_sector,
|
||||
p_num_success);
|
||||
if (err != 0) {
|
||||
if (err == 0x15) {
|
||||
err = pdm_part_get_driver_error_code(volume->driver_partition);
|
||||
pf_vol_set.last_driver_error = err;
|
||||
volume->last_driver_error = err;
|
||||
return 0x1000;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFDRV_lwrite(PFDRV_VOLUME* volume, const pf_u8* buffer, pf_u32 sector, pf_u32 num_sector, pf_u32* p_num_success) {
|
||||
pf_s32 err;
|
||||
|
||||
err = pdm_part_logical_write(volume->driver_partition, buffer, sector, num_sector, volume->bpb.bytes_per_sector,
|
||||
p_num_success);
|
||||
if (err != 0) {
|
||||
if (err == 0x15) {
|
||||
err = pdm_part_get_driver_error_code(volume->driver_partition);
|
||||
pf_vol_set.last_driver_error = err;
|
||||
volume->last_driver_error = err;
|
||||
return 0x1000;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
759
libs/RVL_SDK/src/fa/pf_entry.c
Normal file
759
libs/RVL_SDK/src/fa/pf_entry.c
Normal file
@@ -0,0 +1,759 @@
|
||||
#include <private/vf/PrFILE2/fatfs/pf_entry.h>
|
||||
|
||||
typedef struct PFENTRY_FAT_HINT {
|
||||
pf_u32 chain_index;
|
||||
pf_u32 cluster;
|
||||
pf_u32 previous_cluster;
|
||||
} PFENTRY_FAT_HINT;
|
||||
|
||||
typedef struct PFENTRY_FFD {
|
||||
pf_u32 start_cluster;
|
||||
pf_u32 current_start_cluster;
|
||||
pf_u32* p_start_cluster;
|
||||
PF_LAST_CLUSTER last_cluster;
|
||||
PF_FAT_LAST_ACCESS last_access_cluster;
|
||||
PF_CLUSTER_LINK cluster_link;
|
||||
PFENTRY_FAT_HINT* p_hint;
|
||||
PF_VOLUME* p_vol;
|
||||
} PFENTRY_FFD;
|
||||
|
||||
typedef struct PFENTRY_ENT_ITER {
|
||||
pf_u32 index;
|
||||
PF_VOLUME* p_vol;
|
||||
PFENTRY_FFD ffd;
|
||||
pf_u32 file_sector_index;
|
||||
pf_u32 sector;
|
||||
pf_u16 offset;
|
||||
pf_u16 offset_mask;
|
||||
pf_u8 buf[32];
|
||||
pf_u8 log2_entries_per_sector;
|
||||
} PFENTRY_ENT_ITER;
|
||||
|
||||
typedef struct PFENTRY_BPB {
|
||||
pf_u16 bytes_per_sector;
|
||||
pf_u16 num_reserved_sectors;
|
||||
pf_u16 num_root_dir_entries;
|
||||
pf_u8 sectors_per_cluster;
|
||||
pf_u8 num_FATs;
|
||||
pf_u32 total_sectors;
|
||||
pf_u32 sectors_per_FAT;
|
||||
pf_u32 root_dir_cluster;
|
||||
pf_u16 fs_info_sector;
|
||||
pf_u16 backup_boot_sector;
|
||||
pf_u16 ext_flags;
|
||||
pf_u8 media;
|
||||
pf_s32 fat_type;
|
||||
pf_u8 log2_bytes_per_sector;
|
||||
pf_u8 log2_sectors_per_cluster;
|
||||
pf_u8 num_active_FATs;
|
||||
pf_u16 num_root_dir_sectors;
|
||||
pf_u32 active_FAT_sector;
|
||||
pf_u32 first_root_dir_sector;
|
||||
pf_u32 first_data_sector;
|
||||
pf_u32 num_clusters;
|
||||
} PFENTRY_BPB;
|
||||
|
||||
struct PF_VOLUME {
|
||||
PFENTRY_BPB bpb;
|
||||
pf_u32 num_free_clusters;
|
||||
pf_u32 last_free_cluster;
|
||||
pf_u8 file_and_directory_state[0x1f74 - 0x40];
|
||||
struct {
|
||||
pf_u32 tracker_size;
|
||||
pf_u32 tracker_max;
|
||||
pf_u32* tracker_bits;
|
||||
} tail_entry;
|
||||
};
|
||||
|
||||
typedef struct PFENTRY_CONTEXT_VOLUME {
|
||||
pf_u32 stat;
|
||||
pf_s32 context_id;
|
||||
PF_VOLUME* p_vol;
|
||||
} PFENTRY_CONTEXT_VOLUME;
|
||||
|
||||
typedef struct PFENTRY_VOLUME_SET {
|
||||
pf_u32 flags;
|
||||
pf_u32 reserved;
|
||||
PF_VOLUME* current_volume;
|
||||
PFENTRY_CONTEXT_VOLUME context_volumes[3];
|
||||
pf_s32 num_attached;
|
||||
pf_s32 num_mounted;
|
||||
pf_u32 config;
|
||||
void* user_data;
|
||||
pf_s32 last_error;
|
||||
pf_s32 last_driver_error;
|
||||
void (*code_callbacks[6])(void);
|
||||
pf_u32 setting;
|
||||
} PFENTRY_VOLUME_SET;
|
||||
|
||||
typedef struct PFENTRY_SYS_DATE { pf_u32 sys_year, sys_month, sys_day; } PFENTRY_SYS_DATE;
|
||||
typedef struct PFENTRY_SYS_TIME { pf_u32 sys_hour, sys_min, sys_sec, sys_ms; } PFENTRY_SYS_TIME;
|
||||
|
||||
extern PFENTRY_VOLUME_SET pf_vol_set;
|
||||
void* pf_memcpy(void* dst, void* src, pf_u32 length);
|
||||
void* pf_memset(void* dst, pf_s32 c, pf_u32 length);
|
||||
void PF_LE16_TO_U16_STR(pf_u8* sSrc, pf_u32 num);
|
||||
pf_s32 PFPATH_cmpNameUni(const pf_u16* p_name, PF_STR* sPattern);
|
||||
pf_s32 PFPATH_cmpName(const pf_s8* sShort, PF_STR* p_pattern, pf_bool is_short_search);
|
||||
pf_s32 PFPATH_cmpTailSFN(const pf_s8* sfn_name, const pf_s8* pattern);
|
||||
pf_s32 PFPATH_putShortName(pf_u8* pDirEntry, const pf_s8* short_name, pf_u8 attr);
|
||||
pf_s32 PFPATH_getShortName(pf_s8* short_name, const pf_u8* pDirEntry, pf_u8 attr);
|
||||
void PFPATH_getLongNameformShortName(pf_s8* short_name, pf_s8* long_name, pf_u8 flag);
|
||||
pf_s32 PFPATH_transformInUnicode(pf_u16* sDestStr, const pf_s8* sSrcStr);
|
||||
pf_s32 PFPATH_parseShortNameNumeric(pf_s8* p_char, pf_u32 count);
|
||||
pf_u32 PFPATH_CheckExtShortNameSignature(PF_STR* p_str);
|
||||
pf_bool PFPATH_GetExtShortNameIndex(PF_STR* p_str, pf_u32* p_index);
|
||||
pf_s32 PFSEC_WriteData(PF_VOLUME* p_vol, const pf_u8* p_buf, pf_u32 sector, pf_u16 offset, pf_u32 size, pf_u32* p_success_size, pf_bool set_sig);
|
||||
pf_s32 PFCACHE_AllocateDataPage(PF_VOLUME*, pf_u32, PF_CACHE_PAGE**, pf_bool*);
|
||||
void PFCACHE_FreeDataPage(PF_VOLUME*, PF_CACHE_PAGE*);
|
||||
pf_s32 PFCACHE_FlushDataCacheSpecific(PF_VOLUME*, void*);
|
||||
pf_s32 PFFAT_InitFFD(PFENTRY_FFD*, PFENTRY_FAT_HINT*, PF_VOLUME*, pf_u32*);
|
||||
pf_s32 PFFAT_GetSectorSpecified(PFENTRY_FFD*, pf_u32, pf_u32, pf_u32*);
|
||||
pf_s32 PFFAT_MakeRootDir(PF_VOLUME*);
|
||||
pf_s32 PFENT_ITER_IteratorInitialize(PFENTRY_ENT_ITER*, pf_u32);
|
||||
pf_s32 PFENT_ITER_Advance(PFENTRY_ENT_ITER*, pf_u32);
|
||||
pf_s32 PFENT_ITER_Retreat(PFENTRY_ENT_ITER*, pf_u32);
|
||||
pf_bool PFENT_ITER_IsAtLogicalEnd(PFENTRY_ENT_ITER*);
|
||||
void PFDRV_LoadVolumeLabelFromBuf(PF_VOLUME*, const pf_u8*);
|
||||
void PFSYS_TimeStamp(PFENTRY_SYS_DATE*, PFENTRY_SYS_TIME*);
|
||||
void PFENT_LoadShortNameFromBuf(PF_DIR_ENT*, const pf_u8*);
|
||||
pf_u8 PFENT_CalcCheckSum(PF_DIR_ENT*);
|
||||
void PFENT_loadEntryNumericFieldsFromBuf(PF_DIR_ENT*, const pf_u8*);
|
||||
pf_s32 PFENT_LoadLFNEntryFieldsFromBuf(PF_DIR_ENT*, const pf_u8*);
|
||||
|
||||
static void PFENT_storeShortNameToBuf(pf_u8* buf, const PF_DIR_ENT* p_ent) {
|
||||
PFPATH_putShortName(buf, p_ent->short_name, p_ent->attr);
|
||||
|
||||
if (*buf == 0xE5) {
|
||||
*buf = 5;
|
||||
}
|
||||
}
|
||||
pf_s32 PFENT_compareEntry(PF_DIR_ENT* p_ent, const pf_u8* buf, PF_STR* p_pattern, pf_s32 attr,
|
||||
pf_u32 attr_required, pf_u32 attr_forbidden, pf_u32* p_lpos) {
|
||||
pf_s32 is_match = 1;
|
||||
pf_u32 is_valid = 1;
|
||||
if ((attr & 15) == 15) {
|
||||
is_match = 1;
|
||||
} else {
|
||||
if (attr == 0) attr = 0x40;
|
||||
if (attr_required & 0x80) {
|
||||
attr_required &= 0x7f;
|
||||
attr_forbidden &= 0x7f;
|
||||
if ((attr_required && (pf_s32)(attr_required & attr) != (pf_s32)attr_required) ||
|
||||
(attr_forbidden && (pf_s32)(attr_forbidden & attr) == (pf_s32)attr_forbidden)) is_valid = 0;
|
||||
} else if (attr_required != 0x7f && (pf_u32)attr != attr_required &&
|
||||
(!(attr & attr_required) || (attr & attr_forbidden))) is_valid = 0;
|
||||
if (is_valid == 0) {
|
||||
is_match = 1;
|
||||
} else {
|
||||
if (attr & 8) {
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
}
|
||||
PFENT_LoadShortNameFromBuf(p_ent, buf);
|
||||
if (p_ent->num_entry_LFNs && p_ent->ordinal == 1 && p_ent->check_sum == PFENT_CalcCheckSum(p_ent)) {
|
||||
is_match = PFPATH_cmpNameUni(p_ent->long_name, p_pattern) != 0;
|
||||
}
|
||||
if (is_match == 1) {
|
||||
if ((pf_vol_set.setting & 2) == 2 && !(attr & 8)) {
|
||||
if (PFPATH_cmpName(p_ent->short_name, p_pattern, 0) == 0) is_match = 0;
|
||||
} else {
|
||||
if (PFPATH_cmpName(p_ent->short_name, p_pattern, 1) == 0) is_match = 0;
|
||||
}
|
||||
}
|
||||
if (is_match == 1) ++*p_lpos;
|
||||
}
|
||||
}
|
||||
return is_match;
|
||||
}
|
||||
|
||||
pf_s32 PFENT_getEntry(PF_DIR_ENT* p_ent, PFENTRY_ENT_ITER* p_iter, PF_STR* p_pattern,
|
||||
pf_u32 attr_required, pf_u32 attr_forbidden, pf_u32* p_lpos) {
|
||||
pf_s32 err;
|
||||
pf_u8 attr = p_iter->buf[11];
|
||||
if (PFENT_compareEntry(p_ent, p_iter->buf, p_pattern, attr, attr_required, attr_forbidden, p_lpos) == 1) {
|
||||
if ((attr & 15) == 15) {
|
||||
err = PFENT_LoadLFNEntryFieldsFromBuf(p_ent, p_iter->buf);
|
||||
if (err != 0) {
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
}
|
||||
} else {
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
if (p_ent->num_entry_LFNs == 0 && (p_iter->buf[12] & 0x18)) {
|
||||
pf_s8 filename[13];
|
||||
pf_s32 length;
|
||||
PFPATH_getLongNameformShortName(p_ent->short_name, filename, p_iter->buf[12]);
|
||||
length = PFPATH_transformInUnicode(p_ent->long_name, filename);
|
||||
p_ent->num_entry_LFNs = length / 13 + ((length % 13) != 0);
|
||||
p_ent->check_sum = PFENT_CalcCheckSum(p_ent);
|
||||
p_ent->ordinal = 1;
|
||||
}
|
||||
PFENT_loadEntryNumericFieldsFromBuf(p_ent, p_iter->buf);
|
||||
p_ent->entry_sector = p_iter->sector;
|
||||
p_ent->entry_offset = p_iter->offset;
|
||||
if ((p_ent->attr & 0x10) && p_ent->start_cluster == 0) p_ent->start_cluster = 1;
|
||||
return 0;
|
||||
}
|
||||
pf_s32 PFENT_searchEmptyTailSFN(PFENTRY_FFD* p_ffd, pf_u32 tail_index, const pf_s8* pattern, pf_u32* p_tail_bit) {
|
||||
PFENTRY_ENT_ITER iter;
|
||||
pf_u8 attr;
|
||||
pf_s32 err = 0;
|
||||
pf_u32 bit_pos;
|
||||
pf_u32 sfn_taillen;
|
||||
pf_u32 sfn_baselen;
|
||||
pf_u32 i;
|
||||
pf_s8 sfnbuf[13];
|
||||
pf_s8 patbuf[13];
|
||||
PF_VOLUME* p_vol = p_ffd->p_vol;
|
||||
|
||||
pf_memset(p_tail_bit, 0, p_vol->tail_entry.tracker_size * 4);
|
||||
iter.ffd = *p_ffd;
|
||||
|
||||
for (err = PFENT_ITER_IteratorInitialize(&iter, 0); PFENT_ITER_IsAtLogicalEnd(&iter) == PF_FALSE;
|
||||
err = PFENT_ITER_Advance(&iter, PF_FALSE)) {
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
if (*iter.buf == 0) {
|
||||
break;
|
||||
}
|
||||
if (*iter.buf != 0xE5) {
|
||||
attr = iter.buf[11];
|
||||
if (((attr & (0x01 | 0x02 | 0x04 | 0x08)) != (0x01 | 0x02 | 0x04 | 0x08)) && ((attr & 8) == 0)) {
|
||||
PFPATH_getShortName((pf_s8*)&sfnbuf, (pf_u8*)&iter.buf, 0);
|
||||
for (sfn_taillen = 1; (sfnbuf[sfn_taillen] != 0x7E) && (sfnbuf[sfn_taillen] != 0) && (sfn_taillen < 7U); sfn_taillen++) {
|
||||
}
|
||||
|
||||
if (sfn_taillen < 7 && sfnbuf[sfn_taillen] == 0x7E) {
|
||||
for (sfn_baselen = sfn_taillen + 1; sfnbuf[sfn_baselen] >= 0x30 && sfnbuf[sfn_baselen] <= 0x39; sfn_baselen++) {
|
||||
}
|
||||
|
||||
if (sfnbuf[sfn_baselen] == '.' || sfnbuf[sfn_baselen] == 0) {
|
||||
i = (sfn_baselen - sfn_taillen) - 1;
|
||||
bit_pos = 0;
|
||||
for (; i != 0; i--) {
|
||||
bit_pos *= 10;
|
||||
bit_pos += (sfnbuf[sfn_baselen - i]) - 0x30;
|
||||
}
|
||||
|
||||
pf_strcpy((pf_s8*)&patbuf, pattern);
|
||||
PFPATH_parseShortNameNumeric((pf_s8*)&patbuf, bit_pos);
|
||||
if (PFPATH_cmpTailSFN((pf_s8*)&sfnbuf, (pf_s8*)&patbuf) == 0 && bit_pos >= tail_index &&
|
||||
bit_pos < (tail_index + (p_vol->tail_entry.tracker_size << 5))) {
|
||||
bit_pos -= tail_index;
|
||||
p_tail_bit[bit_pos >> 5] |= 1 << bit_pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFENT_findEmptyTailSFN(PF_DIR_ENT* p_ent_containig_dir, const pf_s8* name, pf_u32* p_tails) {
|
||||
PFENTRY_FFD ffd;
|
||||
PFENTRY_FAT_HINT hint;
|
||||
pf_s32 err;
|
||||
pf_u32 num;
|
||||
PF_VOLUME* p_vol = p_ent_containig_dir->p_vol;
|
||||
pf_u32 track_num;
|
||||
|
||||
*p_tails = 1;
|
||||
PFFAT_InitFFD(&ffd, &hint, p_ent_containig_dir->p_vol, &p_ent_containig_dir->start_cluster);
|
||||
|
||||
for (num = 1; num <= (1000000 - 1); num += p_vol->tail_entry.tracker_size << 5) {
|
||||
err = PFENT_searchEmptyTailSFN(&ffd, num, name, p_vol->tail_entry.tracker_bits);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
for (track_num = 0; track_num < p_vol->tail_entry.tracker_size; track_num += 1) {
|
||||
if (p_vol->tail_entry.tracker_bits[track_num] != -1) {
|
||||
for (; (p_vol->tail_entry.tracker_bits[track_num] & 1) != 0; p_vol->tail_entry.tracker_bits[track_num] >>= 1, (*p_tails)++) {
|
||||
}
|
||||
num = 1000000;
|
||||
break;
|
||||
} else {
|
||||
*p_tails += 0x20;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_u8 PFENT_CalcCheckSum(PF_DIR_ENT* p_ent) {
|
||||
pf_u16 i;
|
||||
pf_u8 sum;
|
||||
pf_u8 buf[13];
|
||||
|
||||
PFPATH_putShortName((pf_u8*)buf, p_ent->short_name, 0);
|
||||
|
||||
sum = 0;
|
||||
for (i = 0; i < 11; i++) {
|
||||
sum = ((sum & 1) != 0 ? 0x80 : 0) + (sum >> 1) + buf[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
void PFENT_LoadShortNameFromBuf(PF_DIR_ENT* p_ent, const pf_u8* buf) {
|
||||
PFPATH_getShortName(p_ent->short_name, buf, buf[11]);
|
||||
if (p_ent->short_name[0] == 5) {
|
||||
p_ent->short_name[0] = -0x1B;
|
||||
}
|
||||
}
|
||||
|
||||
void PFENT_loadEntryNumericFieldsFromBuf(PF_DIR_ENT* p_ent, const pf_u8* buf) {
|
||||
p_ent->attr = buf[0xB];
|
||||
p_ent->small_letter_flag = buf[0xC];
|
||||
p_ent->create_time_ms = buf[0xD];
|
||||
p_ent->create_time = PF_SWAP_16(*(pf_u16*)&buf[0xE]);
|
||||
p_ent->create_date = PF_SWAP_16(*(pf_u16*)&buf[0x10]);
|
||||
p_ent->access_date = PF_SWAP_16(*(pf_u16*)&buf[0x12]);
|
||||
p_ent->modify_time = PF_SWAP_16(*(pf_u16*)&buf[0x16]);
|
||||
p_ent->modify_date = PF_SWAP_16(*(pf_u16*)&buf[0x18]);
|
||||
p_ent->file_size = PF_SWAP_32(*(pf_u32*)&buf[0x1C]);
|
||||
p_ent->start_cluster = ((pf_u16)PF_SWAP_16(*(pf_u16*)&buf[0x14]) << 16) | (pf_u16)(PF_SWAP_16(*(pf_u16*)&buf[0x1A]));
|
||||
}
|
||||
|
||||
void PFENT_StoreEntryNumericFieldsToBuf(pf_u8* buf, const PF_DIR_ENT* p_ent) {
|
||||
buf[0x0B] = p_ent->attr;
|
||||
buf[0x0C] = p_ent->small_letter_flag;
|
||||
buf[0x0D] = p_ent->create_time_ms;
|
||||
*(pf_u16*)&buf[0x0E] = PF_SWAP_16(p_ent->create_time);
|
||||
*(pf_u16*)&buf[0x10] = PF_SWAP_16(p_ent->create_date);
|
||||
*(pf_u16*)&buf[0x12] = PF_SWAP_16(p_ent->access_date);
|
||||
*(pf_u16*)&buf[0x16] = PF_SWAP_16(p_ent->modify_time);
|
||||
*(pf_u16*)&buf[0x18] = PF_SWAP_16(p_ent->modify_date);
|
||||
*(pf_u16*)&buf[0x14] = PF_SWAP_16((pf_u16)(p_ent->start_cluster >> 16));
|
||||
*(pf_u16*)&buf[0x1A] = PF_SWAP_16((pf_u16)(p_ent->start_cluster));
|
||||
*(pf_u32*)&buf[0x1C] = PF_SWAP_32(p_ent->file_size);
|
||||
}
|
||||
|
||||
pf_s32 PFENT_LoadLFNEntryFieldsFromBuf(PF_DIR_ENT* p_ent, const pf_u8* buf) {
|
||||
pf_u8 ordinal;
|
||||
pf_u8 check_sum;
|
||||
pf_u32 is_last_LFN_ent;
|
||||
pf_u8* p;
|
||||
pf_u16* q;
|
||||
pf_u16* q_after;
|
||||
|
||||
ordinal = buf[0];
|
||||
check_sum = buf[13];
|
||||
if ((ordinal & ~0x40U) > 0x14U) {
|
||||
p_ent->ordinal = 0;
|
||||
p_ent->check_sum = 0;
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
return 33;
|
||||
}
|
||||
if ((buf[0] & 0x40) != 0) {
|
||||
ordinal &= ~0x40;
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
is_last_LFN_ent = 1;
|
||||
} else {
|
||||
is_last_LFN_ent = 0;
|
||||
if (p_ent->num_entry_LFNs == 0) return 33;
|
||||
if (ordinal != p_ent->ordinal - 1 || check_sum != p_ent->check_sum) {
|
||||
p_ent->ordinal = 0;
|
||||
p_ent->check_sum = 0;
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
return 33;
|
||||
}
|
||||
}
|
||||
p_ent->ordinal = ordinal;
|
||||
p_ent->check_sum = check_sum;
|
||||
p = (pf_u8*)p_ent->long_name;
|
||||
p += (ordinal - 1) * 0x1A;
|
||||
pf_memcpy(&p[0x0], (pf_s8*)&buf[0x1], 10);
|
||||
pf_memcpy(&p[10], (pf_s8*)&buf[0xE], 0xC);
|
||||
pf_memcpy(&p[0x16], (pf_s8*)&buf[0x1C], 4U);
|
||||
PF_LE16_TO_U16_STR(&p[0x0], 10);
|
||||
PF_LE16_TO_U16_STR(&p[10], 0xC);
|
||||
PF_LE16_TO_U16_STR(&p[0x16], 4U);
|
||||
if (is_last_LFN_ent != 0) {
|
||||
((pf_u16*)p)[13] = 0;
|
||||
q = (pf_u16*)p;
|
||||
q_after = (pf_u16*)&p[0x1A];
|
||||
for (; q < q_after; q++) {
|
||||
if (*q == 0) {
|
||||
q++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (; q < q_after; q++) {
|
||||
if (*q != 0xFFFF) {
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
return 33;
|
||||
}
|
||||
}
|
||||
}
|
||||
p_ent->num_entry_LFNs++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PFENT_storeLFNEntryFieldsToBuf(pf_u8* buf, PF_DIR_ENT* p_ent, pf_u8 ord, pf_u8 sum, pf_bool is_last) {
|
||||
pf_u8* p_seg;
|
||||
pf_u16* p;
|
||||
pf_u16* p_after;
|
||||
|
||||
if (is_last) {
|
||||
*buf = ord | 0x40;
|
||||
} else {
|
||||
*buf = ord;
|
||||
}
|
||||
buf[0xB] = (0x01 | 0x02 | 0x04 | 0x08);
|
||||
buf[0xD] = sum;
|
||||
buf[0xC] = 0;
|
||||
*(pf_u16*)&buf[0x1A] = 0;
|
||||
p_seg = (pf_u8*)p_ent->long_name;
|
||||
p_seg += (ord - 1) * 0x1A;
|
||||
if (is_last != 0) {
|
||||
p = (pf_u16*)p_seg;
|
||||
p_after = (pf_u16*)&p_seg[0x1A];
|
||||
for (; p < p_after; p++) {
|
||||
if (*p == 0x0000) {
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (; p < p_after; p++) {
|
||||
*p = 0xFFFF;
|
||||
}
|
||||
}
|
||||
pf_memcpy(&buf[1], p_seg, 10);
|
||||
pf_memcpy(&buf[0xE], &p_seg[10], 0xC);
|
||||
pf_memcpy(&buf[0x1C], &p_seg[0x16], 4);
|
||||
PF_LE16_TO_U16_STR(&buf[1], 10);
|
||||
PF_LE16_TO_U16_STR(&buf[0xE], 0xC);
|
||||
PF_LE16_TO_U16_STR(&buf[0x1C], 4);
|
||||
}
|
||||
|
||||
pf_s32 PFENT_findEntryPos(PFENTRY_FFD* p_ffd, PF_DIR_ENT* p_ent, pf_u32 index_search_from, PF_STR* p_pattern,
|
||||
pf_u32 attr_required, pf_u32 attr_forbidden, pf_u32* p_lpos, pf_u32* p_ppos) {
|
||||
pf_s32 err;
|
||||
PFENTRY_ENT_ITER iter;
|
||||
pf_u32 lpos;
|
||||
pf_bool is_extsfn = 0;
|
||||
*p_lpos = 0;
|
||||
*p_ppos = 0;
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->ordinal = 0;
|
||||
p_ent->check_sum = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
lpos = 0;
|
||||
if ((pf_vol_set.setting & 2) == 2) is_extsfn = PFPATH_GetExtShortNameIndex(p_pattern, &index_search_from);
|
||||
iter.ffd = *p_ffd;
|
||||
if (is_extsfn == 1) {
|
||||
err = PFENT_ITER_IteratorInitialize(&iter, index_search_from - 1);
|
||||
{
|
||||
if (err != 0) {
|
||||
*p_lpos = 999999;
|
||||
*p_ppos = 999999;
|
||||
return err;
|
||||
}
|
||||
if (PFENT_getEntry(p_ent, &iter, p_pattern, attr_required, attr_forbidden, &lpos) == 0) {
|
||||
*p_lpos = 999999;
|
||||
*p_ppos = 999999;
|
||||
return 3;
|
||||
}
|
||||
if (iter.buf[0] & 0x40) {
|
||||
err = PFENT_ITER_IteratorInitialize(&iter, index_search_from);
|
||||
if (err != 0) {
|
||||
*p_lpos = 999999;
|
||||
*p_ppos = 999999;
|
||||
return err;
|
||||
}
|
||||
if (PFENT_getEntry(p_ent, &iter, p_pattern, attr_required, attr_forbidden, &lpos) == 0) {
|
||||
p_ent->p_vol = p_ffd->p_vol;
|
||||
*p_lpos = lpos;
|
||||
*p_ppos = iter.index;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (err = PFENT_ITER_IteratorInitialize(&iter, index_search_from); !PFENT_ITER_IsAtLogicalEnd(&iter); err = PFENT_ITER_Advance(&iter, 0)) {
|
||||
if (err != 0) {
|
||||
*p_lpos = 999999;
|
||||
*p_ppos = 999999;
|
||||
return err;
|
||||
}
|
||||
if (iter.buf[0] == 0) break;
|
||||
if (iter.buf[0] == 0xe5) {
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
} else if (PFENT_getEntry(p_ent, &iter, p_pattern, attr_required, attr_forbidden, &lpos) == 0) {
|
||||
p_ent->p_vol = p_ffd->p_vol;
|
||||
*p_lpos = lpos;
|
||||
*p_ppos = iter.index;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
*p_lpos = 999999;
|
||||
*p_ppos = 999999;
|
||||
return 3;
|
||||
}
|
||||
|
||||
pf_s32 PFENT_findEntry(PFENTRY_FFD* p_ffd, PF_DIR_ENT* p_ent, pf_u32 index_search_from, PF_STR* p_pattern,
|
||||
pf_u32 attr_required, pf_u32 attr_forbidden) {
|
||||
pf_u32 lpos;
|
||||
pf_u32 ppos;
|
||||
return PFENT_findEntryPos(p_ffd, p_ent, index_search_from, p_pattern, attr_required, attr_forbidden, &lpos, &ppos);
|
||||
}
|
||||
|
||||
pf_s32 PFENT_allocateEntryPos(PF_DIR_ENT* p_ent, pf_u32 num_entries, PFENTRY_FFD* p_ffd, pf_u32* p_prev_chain,
|
||||
PF_STR* p_filename, pf_u32* p_pos) {
|
||||
pf_s32 err;
|
||||
PFENTRY_ENT_ITER iter;
|
||||
PF_DIR_ENT current_ent;
|
||||
PF_VOLUME* p_vol;
|
||||
pf_u32 next_sector;
|
||||
pf_u32 logical_scratch;
|
||||
pf_u32 saved_sector;
|
||||
pf_u16 saved_offset;
|
||||
pf_u32 current_sector;
|
||||
pf_u32 previous_sector0;
|
||||
pf_u32 previous_sector1;
|
||||
pf_bool is_found;
|
||||
pf_u32 num_free_entries;
|
||||
pf_u32 logical_position;
|
||||
if ((pf_vol_set.setting & 2) == 2 && PFPATH_CheckExtShortNameSignature(p_filename) == 1) return 1;
|
||||
p_vol = p_ffd->p_vol;
|
||||
saved_sector = -1U;
|
||||
p_prev_chain[0] = p_prev_chain[1] = saved_sector;
|
||||
num_free_entries = 0;
|
||||
logical_position = 0;
|
||||
saved_offset = 0;
|
||||
current_sector = -1U;
|
||||
previous_sector1 = -1U;
|
||||
previous_sector0 = -1U;
|
||||
is_found = 0;
|
||||
iter.sector = 0;
|
||||
iter.index = 0;
|
||||
iter.ffd = *p_ffd;
|
||||
for (err = PFENT_ITER_IteratorInitialize(&iter, 0);; err = PFENT_ITER_Advance(&iter, 1)) {
|
||||
if (err != 0) {
|
||||
if (err == 16) break;
|
||||
return err;
|
||||
}
|
||||
if (iter.sector == -1U) break;
|
||||
if (is_found == 0 && num_free_entries == 0) {
|
||||
saved_offset = iter.offset;
|
||||
saved_sector = iter.sector;
|
||||
current_sector = iter.sector;
|
||||
}
|
||||
if (is_found == 0) {
|
||||
if (iter.buf[0] == 0 || iter.buf[0] == 0xe5) {
|
||||
if (current_sector != iter.sector) {
|
||||
pf_bool is_first = previous_sector0 == -1U;
|
||||
if (is_first) previous_sector0 = iter.sector;
|
||||
if (!is_first) previous_sector1 = iter.sector;
|
||||
current_sector = iter.sector;
|
||||
}
|
||||
++num_free_entries;
|
||||
} else {
|
||||
num_free_entries = 0;
|
||||
previous_sector0 = -1U;
|
||||
previous_sector1 = -1U;
|
||||
}
|
||||
}
|
||||
if (num_free_entries >= num_entries) {
|
||||
if (is_found == 0) {
|
||||
logical_position = iter.index;
|
||||
is_found = 1;
|
||||
}
|
||||
if (iter.buf[0] == 0) break;
|
||||
}
|
||||
if (iter.buf[0] != 0 && iter.buf[0] != 0xe5 && PFENT_getEntry(¤t_ent, &iter, p_filename, 0x7f, 0, &logical_scratch) == 0) {
|
||||
*p_ent = current_ent;
|
||||
p_ent->p_vol = p_ffd->p_vol;
|
||||
return 8;
|
||||
}
|
||||
if (iter.offset + 32 == p_vol->bpb.bytes_per_sector) {
|
||||
err = PFFAT_GetSectorSpecified(p_ffd, iter.file_sector_index + 1, 0, &next_sector);
|
||||
if (err != 0) return err;
|
||||
if (next_sector == -1U && is_found == 1) break;
|
||||
}
|
||||
}
|
||||
if (is_found == 0) return 5;
|
||||
p_prev_chain[0] = previous_sector0;
|
||||
p_prev_chain[1] = previous_sector1;
|
||||
p_ent->entry_sector = saved_sector;
|
||||
p_ent->entry_offset = saved_offset;
|
||||
*p_pos = logical_position;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFENT_allocateEntry(PF_DIR_ENT* p_ent, pf_u32 num_entries, PFENTRY_FFD* p_ffd, pf_u32* p_prev_chain, PF_STR* p_filename) {
|
||||
pf_u32 position;
|
||||
return PFENT_allocateEntryPos(p_ent, num_entries, p_ffd, p_prev_chain, p_filename, &position);
|
||||
}
|
||||
|
||||
pf_s32 PFENT_GetRootDir(PF_VOLUME* p_vol, PF_DIR_ENT* p_ent) {
|
||||
p_ent->long_name[0] = 0x5C;
|
||||
p_ent->long_name[1] = 0;
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->ordinal = 0;
|
||||
p_ent->check_sum = 0;
|
||||
p_ent->short_name[0] = 0x5C;
|
||||
p_ent->short_name[1] = 0;
|
||||
p_ent->small_letter_flag = 0;
|
||||
p_ent->attr = 0x10;
|
||||
p_ent->create_time_ms = 0;
|
||||
p_ent->create_time = 0;
|
||||
p_ent->create_date = 0;
|
||||
p_ent->access_date = 0;
|
||||
p_ent->modify_time = 0;
|
||||
p_ent->modify_date = 0;
|
||||
p_ent->file_size = 0;
|
||||
p_ent->p_vol = p_vol;
|
||||
p_ent->path_len = 3;
|
||||
p_ent->start_cluster = 1;
|
||||
p_ent->entry_sector = -1;
|
||||
p_ent->entry_offset = 0;
|
||||
return 0;
|
||||
}
|
||||
pf_s32 PFENT_MakeRootDir(PF_VOLUME* p_vol) {
|
||||
PF_CACHE_PAGE* p_page;
|
||||
pf_u32 sector;
|
||||
pf_u32 success_size;
|
||||
pf_bool hit;
|
||||
pf_s32 err;
|
||||
switch (p_vol->bpb.fat_type) {
|
||||
case FAT_32:
|
||||
PFFAT_MakeRootDir(p_vol);
|
||||
break;
|
||||
case FAT_12:
|
||||
case FAT_16:
|
||||
err = PFCACHE_AllocateDataPage(p_vol, -1U, &p_page, &hit);
|
||||
if (err != 0) return err;
|
||||
pf_memset(p_page->p_buf, 0, p_vol->bpb.bytes_per_sector);
|
||||
for (sector = p_vol->bpb.first_root_dir_sector; sector < p_vol->bpb.first_data_sector; ++sector) {
|
||||
err = PFSEC_WriteData(p_vol, p_page->p_buf, sector, 0, p_vol->bpb.bytes_per_sector, &success_size, 0);
|
||||
if (err != 0) {
|
||||
PFCACHE_FreeDataPage(p_vol, p_page);
|
||||
return err;
|
||||
}
|
||||
if (success_size != p_vol->bpb.bytes_per_sector) {
|
||||
PFCACHE_FreeDataPage(p_vol, p_page);
|
||||
return 17;
|
||||
}
|
||||
}
|
||||
PFCACHE_FreeDataPage(p_vol, p_page);
|
||||
break;
|
||||
default:
|
||||
return 7;
|
||||
}
|
||||
PFDRV_LoadVolumeLabelFromBuf(p_vol, (pf_u8*)"NO NAME ");
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFENT_updateEntry(PF_DIR_ENT* p_ent, pf_u32 flag) {
|
||||
PF_VOLUME* p_vol;
|
||||
pf_u32 success_size;
|
||||
pf_u8 buf[32];
|
||||
pf_s32 err;
|
||||
|
||||
p_vol = p_ent->p_vol;
|
||||
if (p_ent->start_cluster == 1) {
|
||||
return 0xE;
|
||||
}
|
||||
if (flag == 1) {
|
||||
p_ent->attr |= (pf_u8)0x20;
|
||||
}
|
||||
PFENT_storeShortNameToBuf(buf, p_ent);
|
||||
PFENT_StoreEntryNumericFieldsToBuf(buf, p_ent);
|
||||
err = PFSEC_WriteData(p_vol, buf, p_ent->entry_sector, p_ent->entry_offset, 32, &success_size, 0U);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
if (success_size != 0x20) {
|
||||
return 0x11;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
pf_s32 PFENT_AdjustSFN(PF_DIR_ENT* p_ent, pf_s8* p_short_name) {
|
||||
pf_u32 i = 0;
|
||||
pf_u32 tail_num;
|
||||
pf_s32 err = 0;
|
||||
|
||||
for (i = 1; (p_short_name[i] != 0x7E) && (p_short_name[i] != 0) && (i < 7U); i++) {
|
||||
}
|
||||
if ((i < 7U) && (p_short_name[i] == 0x7E)) {
|
||||
for (i++; (p_short_name[i] >= 0x30) && (p_short_name[i] <= 0x39); i++) {
|
||||
}
|
||||
if ((p_short_name[i] == '.') || (p_short_name[i] == 0)) {
|
||||
err = PFENT_findEmptyTailSFN(p_ent, p_short_name, &tail_num);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
if (tail_num != 1) {
|
||||
PFPATH_parseShortNameNumeric(p_short_name, tail_num);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
pf_u8 PFENT_getcurrentDateTimeForEnt(pf_u16* p_date, pf_u16* p_time) {
|
||||
PFENTRY_SYS_DATE sys_date;
|
||||
PFENTRY_SYS_TIME sys_time;
|
||||
|
||||
PFSYS_TimeStamp(&sys_date, &sys_time);
|
||||
*p_date = ((sys_date.sys_day & 0x1F) | ((sys_date.sys_month << 5) & 0x1E0)) | (((sys_date.sys_year - 0x7BC) << 9) & 0xFE00);
|
||||
*p_time = (((sys_time.sys_sec >> 1) & 0x1F) | ((sys_time.sys_min << 5) & 0x7E0)) | ((sys_time.sys_hour << 0xB) & 0xF800);
|
||||
|
||||
return sys_time.sys_ms;
|
||||
}
|
||||
pf_s32 PFENT_RemoveEntry(PF_DIR_ENT* p_ent, PFENTRY_ENT_ITER* p_iter) {
|
||||
pf_u32 success_size;
|
||||
pf_s32 err = 0;
|
||||
pf_u32 entry_sector;
|
||||
pf_u16 entry_offset;
|
||||
pf_u32 i;
|
||||
PF_VOLUME* p_vol = PF_NULL;
|
||||
const pf_u8 dir_fb_free[1] = {0xE5};
|
||||
|
||||
p_vol = p_ent->p_vol;
|
||||
entry_sector = p_ent->entry_sector;
|
||||
entry_offset = p_ent->entry_offset;
|
||||
if ((p_ent->num_entry_LFNs != 0) && ((p_ent->small_letter_flag & 0x18) == 0)) {
|
||||
for (i = 1; i <= p_ent->num_entry_LFNs; i++) {
|
||||
err = PFENT_ITER_Retreat(p_iter, 0);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
entry_sector = p_iter->sector;
|
||||
entry_offset = p_iter->offset;
|
||||
err = PFSEC_WriteData(p_vol, (pf_u8*)&dir_fb_free, entry_sector, entry_offset, 1, &success_size, 0);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
if (success_size != 1) {
|
||||
return 17;
|
||||
}
|
||||
}
|
||||
}
|
||||
err = PFSEC_WriteData(p_vol, (pf_u8*)&dir_fb_free, p_ent->entry_sector, p_ent->entry_offset, 1, &success_size, 0);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
if (success_size != 1) {
|
||||
return 17;
|
||||
}
|
||||
err = PFCACHE_FlushDataCacheSpecific(p_vol, PF_NULL);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
747
libs/RVL_SDK/src/fa/pf_entry_iterator.c
Normal file
747
libs/RVL_SDK/src/fa/pf_entry_iterator.c
Normal file
@@ -0,0 +1,747 @@
|
||||
#include <private/vf/PrFILE2/fatfs/pf_entry.h>
|
||||
|
||||
typedef struct PFITER_FAT_HINT {
|
||||
pf_u32 chain_index;
|
||||
pf_u32 cluster;
|
||||
pf_u32 previous_cluster;
|
||||
} PFITER_FAT_HINT;
|
||||
|
||||
typedef struct PFITER_FFD {
|
||||
pf_u32 start_cluster;
|
||||
pf_u32 current_start_cluster;
|
||||
pf_u32* p_start_cluster;
|
||||
PF_LAST_CLUSTER last_cluster;
|
||||
PF_FAT_LAST_ACCESS last_access_cluster;
|
||||
PF_CLUSTER_LINK cluster_link;
|
||||
PFITER_FAT_HINT* p_hint;
|
||||
PF_VOLUME* p_vol;
|
||||
} PFITER_FFD;
|
||||
|
||||
typedef struct PFITER_ENT_ITER {
|
||||
pf_u32 index;
|
||||
PF_VOLUME* p_vol;
|
||||
PFITER_FFD ffd;
|
||||
pf_u32 file_sector_index;
|
||||
pf_u32 sector;
|
||||
pf_u16 offset;
|
||||
pf_u16 offset_mask;
|
||||
pf_u8 buf[32];
|
||||
pf_u8 log2_entries_per_sector;
|
||||
} PFITER_ENT_ITER;
|
||||
|
||||
typedef struct PFITER_BPB {
|
||||
pf_u16 bytes_per_sector;
|
||||
pf_u16 num_reserved_sectors;
|
||||
pf_u16 num_root_dir_entries;
|
||||
pf_u8 sectors_per_cluster;
|
||||
pf_u8 num_FATs;
|
||||
pf_u32 total_sectors;
|
||||
pf_u32 sectors_per_FAT;
|
||||
pf_u32 root_dir_cluster;
|
||||
pf_u16 fs_info_sector;
|
||||
pf_u16 backup_boot_sector;
|
||||
pf_u16 ext_flags;
|
||||
pf_u8 media;
|
||||
pf_s32 fat_type;
|
||||
pf_u8 log2_bytes_per_sector;
|
||||
pf_u8 log2_sectors_per_cluster;
|
||||
pf_u8 num_active_FATs;
|
||||
pf_u16 num_root_dir_sectors;
|
||||
pf_u32 active_FAT_sector;
|
||||
pf_u32 first_root_dir_sector;
|
||||
pf_u32 first_data_sector;
|
||||
pf_u32 num_clusters;
|
||||
} PFITER_BPB;
|
||||
|
||||
struct PF_VOLUME {
|
||||
PFITER_BPB bpb;
|
||||
};
|
||||
|
||||
typedef struct PFITER_CONTEXT_VOLUME {
|
||||
pf_u32 stat;
|
||||
pf_s32 context_id;
|
||||
PF_VOLUME* p_vol;
|
||||
} PFITER_CONTEXT_VOLUME;
|
||||
|
||||
typedef struct PFITER_VOLUME_SET {
|
||||
pf_u32 flags;
|
||||
pf_u32 reserved;
|
||||
PF_VOLUME* current_volume;
|
||||
PFITER_CONTEXT_VOLUME context_volumes[3];
|
||||
pf_s32 num_attached;
|
||||
pf_s32 num_mounted;
|
||||
pf_u32 config;
|
||||
void* user_data;
|
||||
pf_s32 last_error;
|
||||
pf_s32 last_driver_error;
|
||||
void (*code_callbacks[6])(void);
|
||||
pf_u32 setting;
|
||||
} PFITER_VOLUME_SET;
|
||||
|
||||
extern PFITER_VOLUME_SET pf_vol_set;
|
||||
pf_s8* PFSTR_GetStrPos(PF_STR*, pf_u32);
|
||||
pf_u32 PFSTR_GetCodeMode(PF_STR* p_str);
|
||||
void PFSTR_MoveStrPos(PF_STR* p_str, pf_s16 num_char);
|
||||
pf_u16 PFSTR_StrLen(PF_STR* p_str);
|
||||
pf_u16 PFSTR_StrNumChar(PF_STR* p_str, pf_u32 target);
|
||||
pf_s32 PFSTR_StrCmp(const PF_STR* p_str, const pf_s8* s);
|
||||
pf_s32 PFSTR_StrNCmp(PF_STR* p_str, const pf_s8* s, pf_u32 target, pf_s16 offset, pf_u16 num);
|
||||
void* pf_memcpy(void* dst, void* src, pf_u32 length);
|
||||
void* pf_memset(void* dst, pf_s32 c, pf_u32 length);
|
||||
pf_s32 pf_strncmp(const pf_s8* s1, const pf_s8* s2, pf_u32 length);
|
||||
pf_u8 PFENT_CalcCheckSum(PF_DIR_ENT* p_ent);
|
||||
void PFENT_LoadShortNameFromBuf(PF_DIR_ENT* p_ent, const pf_u8* buf);
|
||||
void PFENT_loadEntryNumericFieldsFromBuf(PF_DIR_ENT* p_ent, const pf_u8* buf);
|
||||
pf_s32 PFENT_LoadLFNEntryFieldsFromBuf(PF_DIR_ENT* p_ent, const pf_u8* buf);
|
||||
pf_s32 PFENT_GetRootDir(PF_VOLUME* p_vol, PF_DIR_ENT* p_ent);
|
||||
pf_s32 PFFAT_GetSectorSpecified(PFITER_FFD* p_ffd, pf_u32 file_sector_index, pf_u32 may_allocate, pf_u32* p_sector);
|
||||
pf_s32 PFFAT_getBeforeChain(PF_VOLUME* p_vol, pf_u32 start_cluster, pf_u32 lActive, pf_u32* p_cluster);
|
||||
pf_s32 PFFAT_ResetFFD(PFITER_FFD* p_ffd, pf_u32* p_start_cluster);
|
||||
pf_s32 PFFAT_InitFFD(PFITER_FFD* p_ffd, PFITER_FAT_HINT* p_hint, PF_VOLUME* p_vol, pf_u32* p_start_cluster);
|
||||
void PFPATH_InitTokenOfPath(PF_STR* p_str, pf_s8* path, pf_u32 code_mode);
|
||||
pf_s32 PFPATH_GetNextTokenOfPath(PF_STR* p_str, pf_bool wildcard);
|
||||
pf_bool PFPATH_MatchFileNameWithPattern(const pf_s8* file_name, PF_STR* p_pattern, pf_bool is_long_name);
|
||||
void PFPATH_getLongNameformShortName(pf_s8* short_name, pf_s8* long_name, pf_u8 flag);
|
||||
pf_u32 PFPATH_GetLengthFromShortname(const pf_s8* sSrc);
|
||||
pf_u32 PFPATH_GetLengthFromUnicode(const pf_u16* sSrc);
|
||||
pf_s32 PFPATH_transformInUnicode(pf_u16* sDestStr, const pf_s8* sSrcStr);
|
||||
pf_bool PFPATH_GetExtShortNameIndex(PF_STR* p_str, pf_u32* p_index);
|
||||
pf_s32 PFSEC_ReadData(PF_VOLUME* p_vol, pf_u8* p_buf, pf_u32 sector, pf_u16 offset, pf_u32 size, pf_u32* p_success_size, pf_bool set_sig);
|
||||
pf_s32 PFSEC_WriteData(PF_VOLUME* p_vol, const pf_u8* p_buf, pf_u32 sector, pf_u16 offset, pf_u32 size, pf_u32* p_success_size, pf_bool set_sig);
|
||||
pf_s32 PFVOL_GetCurrentDir(PF_VOLUME*, PF_DIR_ENT*);
|
||||
pf_s32 PFCACHE_AllocateDataPage(PF_VOLUME*, pf_u32, PF_CACHE_PAGE**, pf_bool*);
|
||||
pf_s32 PFCACHE_FreeDataPage(PF_VOLUME*, PF_CACHE_PAGE*);
|
||||
pf_s32 PFENT_RecalcEntryIterator(PFITER_ENT_ITER*, pf_u32);
|
||||
pf_s32 PFENT_ITER_IteratorInitialize(PFITER_ENT_ITER*, pf_u32);
|
||||
pf_bool PFENT_ITER_IsAtLogicalEnd(PFITER_ENT_ITER*);
|
||||
pf_s32 PFENT_ITER_MoveTo(PFITER_ENT_ITER*, pf_u32, pf_u32);
|
||||
pf_s32 PFENT_ITER_Advance(PFITER_ENT_ITER*, pf_u32);
|
||||
pf_s32 PFENT_ITER_Retreat(PFITER_ENT_ITER*, pf_u32);
|
||||
pf_s32 PFENT_ITER_FindDirEntryFromCluster(PFITER_ENT_ITER*, PF_DIR_ENT*, pf_u32, pf_bool*);
|
||||
|
||||
#pragma dont_inline on
|
||||
pf_s32 PFENT_RecalcEntryIterator(PFITER_ENT_ITER* p_iter, pf_u32 may_allocate) {
|
||||
pf_u32 file_sector_index;
|
||||
pf_u32 previous_fsindex;
|
||||
pf_u32 sector_count;
|
||||
pf_s32 err;
|
||||
PF_CACHE_PAGE* page;
|
||||
pf_u32 success_size;
|
||||
pf_bool hit;
|
||||
file_sector_index = p_iter->index >> p_iter->log2_entries_per_sector;
|
||||
previous_fsindex = p_iter->file_sector_index;
|
||||
if (file_sector_index != p_iter->file_sector_index) {
|
||||
p_iter->file_sector_index = file_sector_index;
|
||||
err = PFFAT_GetSectorSpecified(&p_iter->ffd, file_sector_index, 0, &p_iter->sector);
|
||||
if (err != 0) return err;
|
||||
if (p_iter->sector == -1U && may_allocate != 0) {
|
||||
err = PFFAT_GetSectorSpecified(&p_iter->ffd, file_sector_index, 1, &p_iter->sector);
|
||||
if (err != 0) return err;
|
||||
if (p_iter->sector != -1U && previous_fsindex != -1U) {
|
||||
err = PFCACHE_AllocateDataPage(p_iter->p_vol, -1U, &page, &hit);
|
||||
if (err != 0) return err;
|
||||
pf_memset(page->p_buf, 0, p_iter->p_vol->bpb.bytes_per_sector);
|
||||
for (sector_count = 0; sector_count < p_iter->p_vol->bpb.sectors_per_cluster; ++sector_count) {
|
||||
err = PFSEC_WriteData(p_iter->p_vol, page->p_buf, p_iter->sector + sector_count, 0,
|
||||
p_iter->p_vol->bpb.bytes_per_sector, &success_size, 0);
|
||||
if (err != 0) {
|
||||
PFCACHE_FreeDataPage(p_iter->p_vol, page);
|
||||
return err;
|
||||
}
|
||||
if (success_size != p_iter->p_vol->bpb.bytes_per_sector) {
|
||||
PFCACHE_FreeDataPage(p_iter->p_vol, page);
|
||||
return 17;
|
||||
}
|
||||
}
|
||||
PFCACHE_FreeDataPage(p_iter->p_vol, page);
|
||||
}
|
||||
}
|
||||
}
|
||||
p_iter->offset = (p_iter->index & p_iter->offset_mask) * 32;
|
||||
return 0;
|
||||
}
|
||||
#pragma dont_inline reset
|
||||
|
||||
static inline pf_s32 PFENT_ITER_LoadEntry(PFITER_ENT_ITER* p_iter) {
|
||||
pf_u32 success_size;
|
||||
pf_s32 err;
|
||||
|
||||
if (p_iter->sector == -1) {
|
||||
return 16;
|
||||
}
|
||||
err = PFSEC_ReadData(p_iter->p_vol, p_iter->buf, p_iter->sector, p_iter->offset, 0x20U, &success_size, 0U);
|
||||
if (success_size != 0x20) {
|
||||
return 17;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static inline pf_s32 PFENT_ITER_DoMoveTo(PFITER_ENT_ITER* p_iter, pf_u32 index, pf_u32 may_allocate) {
|
||||
pf_u32 prev_index = p_iter->index;
|
||||
pf_s32 err;
|
||||
|
||||
p_iter->index = index;
|
||||
err = PFENT_RecalcEntryIterator(p_iter, may_allocate);
|
||||
if (err != 0) {
|
||||
p_iter->index = prev_index;
|
||||
PFENT_RecalcEntryIterator(p_iter, 0U);
|
||||
return err;
|
||||
}
|
||||
err = PFENT_ITER_LoadEntry(p_iter);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void PFENT_ITER_MakeLongFileName(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent) {
|
||||
pf_s32 lengthName;
|
||||
signed char filename[13];
|
||||
|
||||
lengthName = 0;
|
||||
PFPATH_getLongNameformShortName(p_ent->short_name, filename, p_iter->buf[0xC]);
|
||||
lengthName = PFPATH_transformInUnicode(p_ent->long_name, filename);
|
||||
p_ent->num_entry_LFNs = ((lengthName % 13) ? 1 : 0) + (lengthName / 13);
|
||||
p_ent->check_sum = PFENT_CalcCheckSum(p_ent);
|
||||
p_ent->ordinal = 1;
|
||||
}
|
||||
|
||||
static inline pf_s32 InitializeIterator(PFITER_ENT_ITER* p_iter, pf_u32 index) {
|
||||
p_iter->p_vol = p_iter->ffd.p_vol;
|
||||
p_iter->log2_entries_per_sector = p_iter->p_vol->bpb.log2_bytes_per_sector - 5;
|
||||
p_iter->offset_mask = (1 << p_iter->log2_entries_per_sector) - 1;
|
||||
p_iter->file_sector_index = -1U;
|
||||
return PFENT_ITER_DoMoveTo(p_iter, index, 0);
|
||||
}
|
||||
|
||||
static inline pf_s32 AdvanceIterator(PFITER_ENT_ITER* p_iter, pf_u32 may_allocate) {
|
||||
pf_s32 err = PFENT_ITER_DoMoveTo(p_iter, p_iter->index + 1, may_allocate);
|
||||
if (err != 0) return err;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void LoadNumericEntry(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent) {
|
||||
PFENT_loadEntryNumericFieldsFromBuf(p_ent, p_iter->buf);
|
||||
p_ent->entry_sector = p_iter->sector;
|
||||
p_ent->entry_offset = p_iter->offset;
|
||||
p_ent->p_vol = p_iter->ffd.p_vol;
|
||||
if ((p_ent->attr & 0x10) && p_ent->start_cluster == 0) p_ent->start_cluster = 1;
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_DoFindEntry(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent, PF_STR* p_pattern,
|
||||
pf_u32 attr_required, pf_u32 attr_forbidden, pf_bool* p_is_found) {
|
||||
pf_s32 err = 0;
|
||||
pf_u32 index_search_from;
|
||||
pf_u32 is_extsfn = 0;
|
||||
*p_is_found = 0;
|
||||
if (PFSTR_StrCmp(p_pattern, (pf_s8*)"..") == 0 && (p_ent->attr & 0x10) && p_ent->start_cluster == 1) return 2;
|
||||
if (PFSTR_StrCmp(p_pattern, (pf_s8*)".") == 0) {
|
||||
*p_is_found = 1;
|
||||
return 0;
|
||||
}
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->ordinal = 0;
|
||||
p_ent->check_sum = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
if ((pf_vol_set.setting & 2) == 2) is_extsfn = PFPATH_GetExtShortNameIndex(p_pattern, &index_search_from);
|
||||
if (is_extsfn == 1) {
|
||||
for (err = InitializeIterator(p_iter, index_search_from - 1);; err = PFENT_ITER_Retreat(p_iter, 0)) {
|
||||
pf_s32 attr;
|
||||
if (err != 0) return err;
|
||||
if ((p_iter->buf[11] & 15) == 15) {
|
||||
if (PFENT_LoadLFNEntryFieldsFromBuf(p_ent, p_iter->buf) != 0) return 3;
|
||||
if (!(p_iter->buf[0] & 0x40)) continue;
|
||||
} else return 0;
|
||||
err = InitializeIterator(p_iter, index_search_from);
|
||||
if (err != 0) return err;
|
||||
attr = p_iter->buf[11];
|
||||
if (attr == 0) attr = 0x40;
|
||||
if (attr_required & 0x80) {
|
||||
attr_required &= 0x7f;
|
||||
attr_forbidden &= 0x7f;
|
||||
if ((attr_required && (pf_s32)(attr_required & attr) != (pf_s32)attr_required) ||
|
||||
(attr_forbidden && (pf_s32)(attr_forbidden & attr) == (pf_s32)attr_forbidden)) err = -1;
|
||||
} else if (attr_required != 0x7f && attr != attr_required &&
|
||||
(!(attr & attr_required) || (attr & attr_forbidden))) err = -1;
|
||||
if (err == -1) return 0;
|
||||
if (attr & 8) return 3;
|
||||
PFENT_LoadShortNameFromBuf(p_ent, p_iter->buf);
|
||||
if (PFPATH_MatchFileNameWithPattern(p_ent->short_name, p_pattern, 0)) {
|
||||
LoadNumericEntry(p_iter, p_ent);
|
||||
*p_is_found = 1;
|
||||
return 0;
|
||||
}
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
for (; PFENT_ITER_IsAtLogicalEnd(p_iter) == PF_FALSE; err = AdvanceIterator(p_iter, 0)) {
|
||||
pf_s32 attr;
|
||||
if (err != 0) return err;
|
||||
if (p_iter->buf[0] == 0) break;
|
||||
if (p_iter->buf[0] == 0xe5) {
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
continue;
|
||||
}
|
||||
attr = p_iter->buf[11];
|
||||
if ((attr & 15) == 15) {
|
||||
if (PFENT_LoadLFNEntryFieldsFromBuf(p_ent, p_iter->buf) != 0) {
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (attr == 0) attr = 0x40;
|
||||
if (attr_required & 0x80) {
|
||||
attr_required &= 0x7f;
|
||||
attr_forbidden &= 0x7f;
|
||||
if ((attr_required && (pf_s32)(attr_required & attr) != (pf_s32)attr_required) ||
|
||||
(attr_forbidden && (pf_s32)(attr_forbidden & attr) == (pf_s32)attr_forbidden)) err = -1;
|
||||
} else if ((pf_u8)attr_required != 0x7f && (pf_u32)attr != (pf_u8)attr_required &&
|
||||
(!(attr & (pf_u8)attr_required) || (attr & (pf_u8)attr_forbidden))) err = -1;
|
||||
if (err == -1) {
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
continue;
|
||||
}
|
||||
if (attr & 8) {
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
}
|
||||
PFENT_LoadShortNameFromBuf(p_ent, p_iter->buf);
|
||||
if (p_ent->num_entry_LFNs && p_ent->ordinal == 1 && p_ent->check_sum == PFENT_CalcCheckSum(p_ent) &&
|
||||
PFPATH_MatchFileNameWithPattern((pf_s8*)p_ent->long_name, p_pattern, 1)) {
|
||||
LoadNumericEntry(p_iter, p_ent);
|
||||
*p_is_found = 1;
|
||||
return 0;
|
||||
}
|
||||
if (PFPATH_MatchFileNameWithPattern(p_ent->short_name, p_pattern, 0)) {
|
||||
if (p_iter->buf[12] & 0x18) PFENT_ITER_MakeLongFileName(p_iter, p_ent);
|
||||
LoadNumericEntry(p_iter, p_ent);
|
||||
*p_is_found = 1;
|
||||
return 0;
|
||||
}
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
}
|
||||
finish:
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_DoGetEntry(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent, PF_VOLUME* p_vol, PF_STR* p_path, pf_bool wildcard,
|
||||
pf_bool no_look_last_token) {
|
||||
pf_s8* p;
|
||||
PF_STR token;
|
||||
pf_bool is_found;
|
||||
PFITER_FAT_HINT hint;
|
||||
pf_u32 start_cluster;
|
||||
PF_DIR_ENT current_ent;
|
||||
pf_s32 err;
|
||||
pf_u32 code_mode;
|
||||
|
||||
if (PFSTR_StrNCmp(p_path, (pf_s8*)":", 1, 1, 1) == 0) {
|
||||
PFSTR_MoveStrPos(p_path, 2);
|
||||
}
|
||||
if ((PFSTR_StrNCmp(p_path, (pf_s8*)"\\", 1, 0, 1) == 0 || PFSTR_StrNCmp(p_path, (pf_s8*)"/", 1, 0, 1) == 0)) {
|
||||
err = PFENT_GetRootDir(p_vol, p_ent);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
if (PFSTR_StrNumChar(p_path, 1) == 1 && (PFSTR_StrNCmp(p_path, (pf_s8*)"\0", 2, 0, 1) == 0)) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
err = PFVOL_GetCurrentDir(p_vol, p_ent);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
p = PFSTR_GetStrPos(p_path, 1);
|
||||
PFFAT_InitFFD(&p_iter->ffd, &hint, p_vol, &p_iter->ffd.current_start_cluster);
|
||||
p_iter->ffd.current_start_cluster = p_ent->start_cluster;
|
||||
code_mode = PFSTR_GetCodeMode(p_path);
|
||||
PFPATH_InitTokenOfPath(&token, p, code_mode);
|
||||
|
||||
for (err = PFPATH_GetNextTokenOfPath(&token, wildcard); token.p_head != 0; err = PFPATH_GetNextTokenOfPath(&token, wildcard)) {
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
if (no_look_last_token != 0 && (PFSTR_StrNCmp(&token, (pf_s8*)"\0", 2, 0, 1) == 0)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ((p_ent->attr & 0x10) == 0) {
|
||||
return 2;
|
||||
}
|
||||
if (PFSTR_StrLen(&token) == 0) {
|
||||
return 2;
|
||||
}
|
||||
p_iter->ffd.current_start_cluster = p_ent->start_cluster;
|
||||
PFFAT_ResetFFD(&p_iter->ffd, &p_iter->ffd.current_start_cluster);
|
||||
err = InitializeIterator(p_iter, 0);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
start_cluster = *p_iter->ffd.p_start_cluster;
|
||||
err = PFENT_ITER_DoFindEntry(p_iter, p_ent, &token, 0x7F, 0, &is_found);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
if (!is_found) {
|
||||
err = PFPATH_GetNextTokenOfPath(&token, wildcard);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
return (token.p_head == PF_NULL) + 2;
|
||||
}
|
||||
if (!wildcard) {
|
||||
if ((p_ent->attr & 0x10) != 0 && p_ent->start_cluster == 1) {
|
||||
p_ent->path_len = 3;
|
||||
continue;
|
||||
}
|
||||
if ((p_ent->attr & 0x10) != 0 && p_ent->short_name[0] == '.' && p_ent->short_name[1] == '.') {
|
||||
PFFAT_ResetFFD(&p_iter->ffd, &p_ent->start_cluster);
|
||||
err = InitializeIterator(p_iter, 0);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
current_ent.attr = p_ent->attr;
|
||||
current_ent.start_cluster = p_ent->start_cluster;
|
||||
err = PFENT_ITER_FindDirEntryFromCluster(p_iter, ¤t_ent, start_cluster, &is_found);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
if (is_found == 0) {
|
||||
return 2;
|
||||
}
|
||||
if (current_ent.num_entry_LFNs != 0) {
|
||||
p_ent->path_len -= PFPATH_GetLengthFromUnicode(current_ent.long_name);
|
||||
} else {
|
||||
p_ent->path_len -= PFPATH_GetLengthFromShortname(¤t_ent.short_name[0]);
|
||||
}
|
||||
p_ent->path_len--;
|
||||
continue;
|
||||
}
|
||||
if ((p_ent->attr & 0x10) == 0 || p_ent->short_name[0] != '.') {
|
||||
p_ent->path_len = (PFSTR_StrNumChar(&token, 1) + 1) + p_ent->path_len;
|
||||
if ((PFSTR_StrNCmp(&token, (pf_s8*)"\0", 2, 0, 1) != 0)) {
|
||||
p_ent->path_len -= PFSTR_StrNumChar(&token, 2);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_IteratorInitialize(PFITER_ENT_ITER* p_iter, pf_u32 index_start_from) {
|
||||
pf_s32 err;
|
||||
|
||||
p_iter->p_vol = p_iter->ffd.p_vol;
|
||||
p_iter->log2_entries_per_sector = p_iter->p_vol->bpb.log2_bytes_per_sector - 5;
|
||||
p_iter->offset_mask = (1 << p_iter->log2_entries_per_sector) - 1;
|
||||
p_iter->file_sector_index = -1;
|
||||
err = PFENT_ITER_DoMoveTo(p_iter, index_start_from, 0U);
|
||||
return err;
|
||||
}
|
||||
|
||||
pf_bool PFENT_ITER_IsAtLogicalEnd(PFITER_ENT_ITER* p_iter) {
|
||||
pf_s32 err;
|
||||
pf_u32 save_index;
|
||||
pf_u32 save_fsindex;
|
||||
|
||||
if (p_iter->sector == -1U || p_iter->buf[0] == 0 || p_iter->index >= (1000000 - 1)) {
|
||||
save_index = p_iter->index;
|
||||
save_fsindex = p_iter->file_sector_index;
|
||||
p_iter->index = (p_iter->file_sector_index + 1) << p_iter->log2_entries_per_sector;
|
||||
err = PFENT_RecalcEntryIterator(p_iter, PF_FALSE);
|
||||
if (err != 0) {
|
||||
p_iter->index = save_index;
|
||||
p_iter->file_sector_index = save_fsindex;
|
||||
return PF_TRUE;
|
||||
}
|
||||
if (p_iter->sector != -1) {
|
||||
err = PFENT_ITER_LoadEntry(p_iter);
|
||||
if (err != 0) {
|
||||
return PF_TRUE;
|
||||
}
|
||||
return PF_FALSE;
|
||||
}
|
||||
return PF_TRUE;
|
||||
}
|
||||
return PF_FALSE;
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_MoveTo(PFITER_ENT_ITER* p_iter, pf_u32 index, pf_u32 may_allocate) {
|
||||
pf_s32 err;
|
||||
|
||||
if (p_iter->index != index || p_iter->sector != -1U || may_allocate == PF_FALSE) {
|
||||
err = PFENT_ITER_DoMoveTo(p_iter, index, may_allocate);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_Advance(PFITER_ENT_ITER* p_iter, pf_u32 may_allocate) {
|
||||
return PFENT_ITER_MoveTo(p_iter, p_iter->index + 1, may_allocate);
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_FindCluster(PF_DIR_ENT* p_ent, pf_u32 cluster, pf_bool* p_is_found) {
|
||||
PFITER_FAT_HINT hint;
|
||||
pf_u32 entries_per_sector;
|
||||
pf_u32 current_cluster;
|
||||
PFITER_ENT_ITER iter;
|
||||
pf_u32 sector_index;
|
||||
pf_s32 err;
|
||||
*p_is_found = 0;
|
||||
if (p_ent->entry_sector < p_ent->p_vol->bpb.first_data_sector) return 0;
|
||||
current_cluster = (p_ent->entry_sector - p_ent->p_vol->bpb.first_data_sector) >> p_ent->p_vol->bpb.log2_sectors_per_cluster;
|
||||
sector_index = (p_ent->p_vol->bpb.sectors_per_cluster - 1) & (p_ent->entry_sector - p_ent->p_vol->bpb.first_data_sector);
|
||||
if (current_cluster == cluster) {
|
||||
*p_is_found = 1;
|
||||
return 0;
|
||||
}
|
||||
iter.ffd.p_start_cluster = ¤t_cluster;
|
||||
iter.ffd.p_hint = &hint;
|
||||
iter.ffd.p_vol = p_ent->p_vol;
|
||||
iter.ffd.start_cluster = 1;
|
||||
iter.ffd.cluster_link.buffer = PF_NULL;
|
||||
iter.log2_entries_per_sector = p_ent->p_vol->bpb.log2_bytes_per_sector - 5;
|
||||
iter.file_sector_index = sector_index;
|
||||
entries_per_sector = 1 << iter.log2_entries_per_sector;
|
||||
iter.offset_mask = entries_per_sector - 1;
|
||||
iter.p_vol = p_ent->p_vol;
|
||||
iter.sector = p_ent->entry_sector;
|
||||
iter.offset = p_ent->entry_offset;
|
||||
iter.index = ((pf_u32)p_ent->entry_offset >> 5) + sector_index * entries_per_sector;
|
||||
hint.chain_index = 0;
|
||||
hint.cluster = current_cluster;
|
||||
hint.previous_cluster = 1;
|
||||
if (iter.index < 2) {
|
||||
hint.chain_index = 1;
|
||||
iter.file_sector_index += p_ent->p_vol->bpb.sectors_per_cluster;
|
||||
iter.index += entries_per_sector << p_ent->p_vol->bpb.log2_sectors_per_cluster;
|
||||
}
|
||||
while (iter.index != 0) {
|
||||
err = PFENT_ITER_LoadEntry(&iter);
|
||||
if (err != 0) return err;
|
||||
if (pf_strncmp((pf_s8*)iter.buf, (pf_s8*)"..", 2) == 0) break;
|
||||
err = PFENT_ITER_Retreat(&iter, 0);
|
||||
if (err != 0) return err;
|
||||
if (current_cluster == cluster) {
|
||||
*p_is_found = 1;
|
||||
return 0;
|
||||
}
|
||||
if (current_cluster <= 2) return 0;
|
||||
if (iter.index < 1) {
|
||||
++hint.chain_index;
|
||||
iter.file_sector_index += p_ent->p_vol->bpb.sectors_per_cluster;
|
||||
iter.index += (1 << iter.log2_entries_per_sector) << p_ent->p_vol->bpb.log2_sectors_per_cluster;
|
||||
}
|
||||
}
|
||||
current_cluster = (PF_SWAP_16(*(pf_u16*)&iter.buf[20]) << 16) | PF_SWAP_16(*(pf_u16*)&iter.buf[26]);
|
||||
hint.chain_index = 0;
|
||||
iter.file_sector_index = 0;
|
||||
hint.cluster = current_cluster;
|
||||
iter.sector = p_ent->p_vol->bpb.first_data_sector + ((current_cluster - 2) << p_ent->p_vol->bpb.log2_sectors_per_cluster);
|
||||
iter.offset = 32;
|
||||
iter.index = 1;
|
||||
while (current_cluster > 2) {
|
||||
err = PFENT_ITER_LoadEntry(&iter);
|
||||
if (err != 0) return err;
|
||||
if (pf_strncmp((pf_s8*)iter.buf, (pf_s8*)"..", 2) == 0) {
|
||||
if (current_cluster == cluster) {
|
||||
*p_is_found = 1;
|
||||
return 0;
|
||||
}
|
||||
current_cluster = (PF_SWAP_16(*(pf_u16*)&iter.buf[20]) << 16) | PF_SWAP_16(*(pf_u16*)&iter.buf[26]);
|
||||
hint.cluster = current_cluster;
|
||||
iter.sector = p_ent->p_vol->bpb.first_data_sector + ((current_cluster - 2) << p_ent->p_vol->bpb.log2_sectors_per_cluster);
|
||||
} else return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_Retreat(PFITER_ENT_ITER* p_iter, pf_u32 may_allocate) {
|
||||
pf_u32 before_cluster;
|
||||
pf_u32 cur_cluster;
|
||||
pf_s32 err;
|
||||
|
||||
if (p_iter->index == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (p_iter->file_sector_index != ((p_iter->index - 1) >> p_iter->log2_entries_per_sector)) {
|
||||
cur_cluster = ((p_iter->sector - p_iter->p_vol->bpb.first_data_sector) >> p_iter->p_vol->bpb.log2_sectors_per_cluster) + 2;
|
||||
if ((p_iter->file_sector_index % p_iter->p_vol->bpb.sectors_per_cluster) == 0 || p_iter->p_vol->bpb.sectors_per_cluster == 1) {
|
||||
if (p_iter->p_vol->bpb.fat_type == FAT_32 ||
|
||||
(*p_iter->ffd.p_start_cluster > 1 && p_iter->p_vol->bpb.first_data_sector <= p_iter->sector)) {
|
||||
err = PFFAT_getBeforeChain(p_iter->p_vol, cur_cluster, cur_cluster, &before_cluster);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
if (before_cluster == -1) {
|
||||
return 14;
|
||||
}
|
||||
} else {
|
||||
before_cluster = *p_iter->ffd.p_start_cluster;
|
||||
}
|
||||
} else {
|
||||
before_cluster = cur_cluster;
|
||||
}
|
||||
p_iter->index--;
|
||||
p_iter->file_sector_index--;
|
||||
if (p_iter->p_vol->bpb.fat_type == FAT_32 || *p_iter->ffd.p_start_cluster > 1 && p_iter->p_vol->bpb.first_data_sector <= p_iter->sector) {
|
||||
p_iter->sector = (p_iter->p_vol->bpb.first_data_sector + ((before_cluster - 2) << p_iter->p_vol->bpb.log2_sectors_per_cluster)) +
|
||||
(p_iter->file_sector_index & (p_iter->p_vol->bpb.sectors_per_cluster - 1));
|
||||
} else {
|
||||
p_iter->sector--;
|
||||
}
|
||||
p_iter->offset = (p_iter->index & p_iter->offset_mask) * 0x20;
|
||||
return 0;
|
||||
}
|
||||
return PFENT_ITER_MoveTo(p_iter, p_iter->index - 1, may_allocate);
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_FindDirEntryFromCluster(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent, pf_u32 cluster, pf_bool* p_is_found) {
|
||||
pf_u8 attr;
|
||||
pf_s32 err = 0;
|
||||
|
||||
*p_is_found = PF_FALSE;
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->ordinal = 0;
|
||||
p_ent->check_sum = 0;
|
||||
if ((p_ent->attr & 0x10) && p_ent->start_cluster == 1) return 2;
|
||||
for (; PFENT_ITER_IsAtLogicalEnd(p_iter) == PF_FALSE; err = AdvanceIterator(p_iter, PF_FALSE)) {
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
if (p_iter->buf[0] == 0xE5) {
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
continue;
|
||||
}
|
||||
attr = p_iter->buf[0xB];
|
||||
if ((attr & (0x01 | 0x02 | 0x04 | 0x08)) == (0x01 | 0x02 | 0x04 | 0x08)) {
|
||||
err = PFENT_LoadLFNEntryFieldsFromBuf(p_ent, p_iter->buf);
|
||||
if (err != 0) {
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if ((attr & 0x08) != 0) {
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
continue;
|
||||
}
|
||||
if ((attr & 0x10) == 0) {
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
continue;
|
||||
}
|
||||
PFENT_LoadShortNameFromBuf(p_ent, p_iter->buf);
|
||||
if (p_ent->num_entry_LFNs != 0 && p_ent->ordinal == 1 && p_ent->check_sum == PFENT_CalcCheckSum(p_ent)) {
|
||||
PFENT_loadEntryNumericFieldsFromBuf(p_ent, p_iter->buf);
|
||||
p_ent->entry_sector = p_iter->sector;
|
||||
p_ent->entry_offset = p_iter->offset;
|
||||
p_ent->p_vol = p_iter->ffd.p_vol;
|
||||
if ((p_ent->attr & 0x10) != 0 && p_ent->start_cluster != cluster) {
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
continue;
|
||||
}
|
||||
if ((p_ent->attr & 0x10) != 0 && p_ent->start_cluster == 0) {
|
||||
p_ent->start_cluster = 1;
|
||||
}
|
||||
*p_is_found = 1;
|
||||
}
|
||||
if ((p_iter->buf[0xC] & (0x10 | 0x08)) != 0) {
|
||||
PFENT_ITER_MakeLongFileName(p_iter, p_ent);
|
||||
}
|
||||
PFENT_loadEntryNumericFieldsFromBuf(p_ent, p_iter->buf);
|
||||
p_ent->entry_sector = p_iter->sector;
|
||||
p_ent->entry_offset = p_iter->offset;
|
||||
p_ent->p_vol = p_iter->ffd.p_vol;
|
||||
|
||||
if ((p_ent->attr & 0x10) && p_ent->start_cluster != cluster) {
|
||||
p_ent->num_entry_LFNs = 0;
|
||||
p_ent->long_name[0] = 0;
|
||||
*p_is_found = 0;
|
||||
continue;
|
||||
}
|
||||
if ((p_ent->attr & 0x10) && p_ent->start_cluster == 0) p_ent->start_cluster = 1;
|
||||
*p_is_found = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_FindEntry(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent, PF_STR* p_pattern,
|
||||
pf_u32 attr_required, pf_u32 attr_forbidden, pf_bool* p_is_found) {
|
||||
pf_s32 err;
|
||||
*p_is_found = 0;
|
||||
if (attr_required & attr_forbidden) return 10;
|
||||
if (PFSTR_StrNCmp(p_pattern, (pf_s8*)":", 1, 1, 1) == 0) PFSTR_MoveStrPos(p_pattern, 2);
|
||||
if (PFSTR_StrNCmp(p_pattern, (pf_s8*)"\\", 1, 0, 1) == 0 || PFSTR_StrNCmp(p_pattern, (pf_s8*)"/", 1, 0, 1) == 0) {
|
||||
err = PFENT_GetRootDir(p_iter->p_vol, p_ent);
|
||||
if (err != 0) return err;
|
||||
if (PFSTR_StrNumChar(p_pattern, 1) == 1 && PFSTR_StrNCmp(p_pattern, (pf_s8*)"\0", 2, 0, 1) == 0) return 0;
|
||||
} else {
|
||||
err = PFVOL_GetCurrentDir(p_iter->p_vol, p_ent);
|
||||
if (err != 0) return err;
|
||||
}
|
||||
err = PFENT_ITER_DoFindEntry(p_iter, p_ent, p_pattern, attr_required, attr_forbidden, p_is_found);
|
||||
if (err != 0) return err;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_FindEntryNoPathCheck(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent, PF_STR* p_pattern,
|
||||
pf_u32 attr_required, pf_u32 attr_forbidden, pf_bool* p_is_found) {
|
||||
pf_s32 err;
|
||||
*p_is_found = 0;
|
||||
if (attr_required & attr_forbidden) return 10;
|
||||
err = PFENT_ITER_DoFindEntry(p_iter, p_ent, p_pattern, attr_required, attr_forbidden, p_is_found);
|
||||
if (err != 0) return err;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_GetEntryOfPath(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent, PF_VOLUME* p_vol, PF_STR* p_path, pf_u32 no_look_last_token) {
|
||||
return PFENT_ITER_DoGetEntry(p_iter, p_ent, p_vol, p_path, 0, no_look_last_token);
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_GetEntryOfPattern(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent, PF_VOLUME* p_vol, PF_STR* p_path) {
|
||||
return PFENT_ITER_DoGetEntry(p_iter, p_ent, p_vol, p_path, 1, 1);
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_GetEntryOfIter(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent) {
|
||||
PFENT_LoadShortNameFromBuf(p_ent, p_iter->buf);
|
||||
PFENT_loadEntryNumericFieldsFromBuf(p_ent, p_iter->buf);
|
||||
p_ent->entry_sector = p_iter->sector;
|
||||
p_ent->entry_offset = p_iter->offset;
|
||||
p_ent->p_vol = p_iter->p_vol;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFENT_ITER_GetLFNEntryName(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent) {
|
||||
pf_u32 i;
|
||||
pf_s32 err;
|
||||
if (p_ent->num_entry_LFNs != 0 && !(p_ent->small_letter_flag & 0x18)) {
|
||||
for (i = 0; i < p_ent->num_entry_LFNs; ++i) {
|
||||
pf_u16* destination;
|
||||
err = PFENT_ITER_Retreat(p_iter, 0);
|
||||
if (err != 0) return err;
|
||||
err = PFENT_ITER_LoadEntry(p_iter);
|
||||
if (err != 0) return err;
|
||||
destination = &p_ent->long_name[(i * 26U) / 2U];
|
||||
pf_memcpy(destination, &p_iter->buf[1], 10);
|
||||
pf_memcpy(destination + 5, &p_iter->buf[14], 12);
|
||||
pf_memcpy(destination + 11, &p_iter->buf[28], 4);
|
||||
}
|
||||
p_ent->long_name[(p_ent->num_entry_LFNs * 26U) / 2U] = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
248
libs/RVL_SDK/src/fa/pf_fat12.c
Normal file
248
libs/RVL_SDK/src/fa/pf_fat12.c
Normal file
@@ -0,0 +1,248 @@
|
||||
#define PF_FA_STR_LAYOUT
|
||||
#define VFiPFCACHE_ReadFATPage PFCACHE_ReadFATPage
|
||||
#define VFiPFCACHE_UpdateModifiedSector PFCACHE_UpdateModifiedSector
|
||||
#define VFiPFFAT12_ReadFATEntry PFFAT12_ReadFATEntry
|
||||
#define VFiPFFAT12_ReadFATEntryPage PFFAT12_ReadFATEntryPage
|
||||
#define VFiPFFAT12_WriteFATEntry PFFAT12_WriteFATEntry
|
||||
#define VFiPFFAT12_WriteFATEntryPage PFFAT12_WriteFATEntryPage
|
||||
#define VFiPFFAT_UpdateFATEntry PFFAT_UpdateFATEntry
|
||||
#define VFiPFSEC_ReadFAT PFSEC_ReadFAT
|
||||
#define VFiPFSEC_WriteFAT PFSEC_WriteFAT
|
||||
#include <private/fa/pf_volume.h>
|
||||
#include <private/vf/PrFILE2/fatfs/pf_fat.h>
|
||||
#include <private/vf/PrFILE2/fatfs/pf_fat12.h>
|
||||
|
||||
#include <private/vf/PrFILE2/fatfs/pf_sector.h>
|
||||
#include <private/vf/PrFILE2/fatfs/pf_volume.h>
|
||||
|
||||
#include <private/vf/PrFILE2/common/pf_code.h>
|
||||
|
||||
pf_s32 VFiPFFAT12_ReadFATEntry(PF_VOLUME* p_vol, pf_u16 cluster, pf_u32* p_value) {
|
||||
pf_u16 fat_sector;
|
||||
pf_s32 err;
|
||||
pf_u16 fat_offset;
|
||||
pf_u16 offset_in_sector;
|
||||
pf_u16 word;
|
||||
pf_u8 buf[sizeof(pf_u16)];
|
||||
pf_u32 current_fat;
|
||||
pf_s32 result;
|
||||
|
||||
fat_offset = cluster + (cluster >> 1);
|
||||
fat_sector = p_vol->bpb.active_FAT_sector + (fat_offset >> p_vol->bpb.log2_bytes_per_sector);
|
||||
offset_in_sector = fat_offset & (p_vol->bpb.bytes_per_sector - 1);
|
||||
if ((p_vol->bpb.ext_flags & 0x80) != 0) {
|
||||
current_fat = p_vol->bpb.ext_flags & (0x01 | 0x02 | 0x04);
|
||||
} else {
|
||||
current_fat = 1;
|
||||
}
|
||||
|
||||
do {
|
||||
if (offset_in_sector < (p_vol->bpb.bytes_per_sector - 1)) {
|
||||
err = VFiPFSEC_ReadFAT(p_vol, &buf[0], (pf_u32)fat_sector, offset_in_sector, 2);
|
||||
} else {
|
||||
err = VFiPFSEC_ReadFAT(p_vol, &buf[0], (pf_u32)fat_sector, offset_in_sector, 1);
|
||||
if (err == 0) {
|
||||
err = VFiPFSEC_ReadFAT(p_vol, &buf[1], fat_sector + 1, 0U, 1);
|
||||
}
|
||||
}
|
||||
if (err == 0x1000 && p_vol->p_callback != PF_NULL) {
|
||||
result = ((PF_VOLUME_CB)p_vol->p_callback)(p_vol->last_driver_error);
|
||||
if (result == 0) {
|
||||
continue;
|
||||
}
|
||||
if (result == 1 && p_vol->bpb.num_active_FATs >= 2 && current_fat < p_vol->bpb.num_active_FATs) {
|
||||
current_fat++;
|
||||
fat_sector += (pf_u16)p_vol->bpb.sectors_per_FAT;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (err != 0) {
|
||||
*p_value = -1;
|
||||
return err;
|
||||
}
|
||||
} while (err != 0);
|
||||
|
||||
word = PF_SWAP_16(*(pf_u16*)buf);
|
||||
if ((cluster & 0x01) != 0) {
|
||||
*p_value = (word >> 4);
|
||||
} else {
|
||||
*p_value = word & 0xFFF;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 VFiPFFAT12_WriteFATEntry(PF_VOLUME* p_vol, pf_u16 cluster, pf_u16 value) {
|
||||
pf_s32 err;
|
||||
pf_u16 fat_offset;
|
||||
pf_u16 fat_sector;
|
||||
pf_u16 offset_in_sector;
|
||||
pf_u16 fat_sector2;
|
||||
pf_u16 offset_in_sector2;
|
||||
pf_u16 word;
|
||||
pf_u16 current_fat;
|
||||
pf_s32 result;
|
||||
pf_u8 buf[sizeof(pf_u16)];
|
||||
|
||||
fat_offset = cluster + (cluster >> 1);
|
||||
fat_sector = p_vol->bpb.active_FAT_sector + (fat_offset >> p_vol->bpb.log2_bytes_per_sector);
|
||||
offset_in_sector = fat_offset & (p_vol->bpb.bytes_per_sector - 1);
|
||||
if ((cluster & 0x01) != 0) {
|
||||
err = VFiPFSEC_ReadFAT(p_vol, &buf[0], fat_sector, offset_in_sector, 1);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
word = (pf_u16)((value << 4) + (buf[0] & 0xF));
|
||||
} else {
|
||||
fat_sector2 = p_vol->bpb.active_FAT_sector + ((fat_offset + 1) >> p_vol->bpb.log2_bytes_per_sector);
|
||||
offset_in_sector2 = (fat_offset + 1) & (p_vol->bpb.bytes_per_sector - 1);
|
||||
err = VFiPFSEC_ReadFAT(p_vol, &buf[0], fat_sector2, offset_in_sector2, 1);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
word = (pf_u16)buf[0] << 8;
|
||||
word = (word & 0xF000) + (pf_u16)(value & 0xFFF);
|
||||
}
|
||||
*(pf_u16*)buf = PF_SWAP_16(word);
|
||||
result = 0;
|
||||
for (current_fat = 0; current_fat < p_vol->bpb.num_active_FATs; current_fat++) {
|
||||
if (offset_in_sector < (p_vol->bpb.bytes_per_sector - 1)) {
|
||||
err = VFiPFSEC_WriteFAT(p_vol, &buf[0], fat_sector, offset_in_sector, 2);
|
||||
if (err != 0 && result == 0) { result = err; }
|
||||
} else {
|
||||
err = VFiPFSEC_WriteFAT(p_vol, &buf[0], fat_sector, offset_in_sector, 1U);
|
||||
if (err != 0 && result == 0) { result = err; }
|
||||
err = VFiPFSEC_WriteFAT(p_vol, &buf[1], fat_sector + 1, 0U, 1);
|
||||
if (err != 0 && result == 0) { result = err; }
|
||||
}
|
||||
fat_sector += p_vol->bpb.sectors_per_FAT;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
pf_s32 PFFAT12_WriteFATEntryWithBuf(PF_VOLUME* p_vol, pf_s16 cluster, pf_u16 value, PF_CACHE_PAGE* p_page) {
|
||||
pf_s32 err;
|
||||
pf_u32 offset_in_sector;
|
||||
pf_u16 current_fat;
|
||||
pf_s32 fat_offset;
|
||||
pf_u32 fat_sector;
|
||||
pf_s32 result;
|
||||
fat_offset = (pf_u16)(cluster + (cluster >> 1));
|
||||
fat_sector = (pf_u16)(p_vol->bpb.active_FAT_sector + (fat_offset >> p_vol->bpb.log2_bytes_per_sector));
|
||||
offset_in_sector = fat_offset & (p_vol->bpb.bytes_per_sector - 1);
|
||||
err = 0;
|
||||
result = 0;
|
||||
#define FLUSH_FAT_BUFFER() \
|
||||
for (current_fat = 0; current_fat < p_vol->bpb.num_active_FATs; current_fat++) { \
|
||||
err = VFiPFSEC_WriteFAT(p_vol, p_page->p_buf, p_page->sector + current_fat * p_vol->bpb.sectors_per_FAT, 0, p_vol->bpb.bytes_per_sector); \
|
||||
if (err != 0 && result == 0) { result = err; } \
|
||||
}
|
||||
if (p_page->sector != fat_sector) {
|
||||
FLUSH_FAT_BUFFER();
|
||||
err = VFiPFSEC_ReadFAT(p_vol, p_page->p_buf, fat_sector, 0, p_vol->bpb.bytes_per_sector);
|
||||
if (err != 0) { return err; }
|
||||
p_page->sector = fat_sector;
|
||||
}
|
||||
if (cluster & 1) {
|
||||
p_page->p_buf[(pf_u16)offset_in_sector] = (p_page->p_buf[(pf_u16)offset_in_sector] & 0xF) | ((value << 4) & 0xF0);
|
||||
if ((pf_u16)offset_in_sector == (pf_u32)(p_vol->bpb.bytes_per_sector - 1)) {
|
||||
FLUSH_FAT_BUFFER();
|
||||
offset_in_sector = fat_sector + 1;
|
||||
err = VFiPFSEC_ReadFAT(p_vol, p_page->p_buf, offset_in_sector, 0, p_vol->bpb.bytes_per_sector);
|
||||
if (err != 0) { return err; }
|
||||
p_page->sector = offset_in_sector;
|
||||
p_page->p_buf[0] = value >> 4;
|
||||
} else {
|
||||
((pf_u16)offset_in_sector + p_page->p_buf)[1] = value >> 4;
|
||||
}
|
||||
} else {
|
||||
p_page->p_buf[(pf_u16)offset_in_sector] = value;
|
||||
if ((pf_u16)offset_in_sector == (pf_u32)(p_vol->bpb.bytes_per_sector - 1)) {
|
||||
FLUSH_FAT_BUFFER();
|
||||
offset_in_sector = fat_sector + 1;
|
||||
err = VFiPFSEC_ReadFAT(p_vol, p_page->p_buf, offset_in_sector, 0, p_vol->bpb.bytes_per_sector);
|
||||
if (err != 0) { return err; }
|
||||
p_page->sector = offset_in_sector;
|
||||
p_page->p_buf[0] = (p_page->p_buf[0] & 0xF0) | ((pf_u8)(value >> 8));
|
||||
} else {
|
||||
((pf_u16)offset_in_sector + p_page->p_buf)[1] = (((pf_u16)offset_in_sector + p_page->p_buf)[1] & 0xF0) | ((pf_u8)(value >> 8));
|
||||
}
|
||||
}
|
||||
if (err != 0) { result = err; }
|
||||
return result;
|
||||
#undef FLUSH_FAT_BUFFER
|
||||
}
|
||||
|
||||
pf_s32 PFFAT12_ReadFATEntryWithBuf(PF_VOLUME* p_vol , pf_u16 cluster , pf_u32* p_value ,
|
||||
PF_CACHE_PAGE* p_page ) {
|
||||
pf_s32 err;
|
||||
pf_u32 current_fat;
|
||||
pf_u32 sector;
|
||||
pf_u32 offset;
|
||||
pf_s32 result;
|
||||
|
||||
#define LOAD_FAT_SECTOR(next_sector) \
|
||||
if (p_page->sector != sector + (next_sector)) { \
|
||||
if (p_page->option == 1) { \
|
||||
for (err = 0; (pf_u16)err < p_vol->bpb.num_active_FATs; err++) { \
|
||||
VFiPFSEC_WriteFAT(p_vol, p_page->p_buf, p_page->sector + (pf_u16)err * p_vol->bpb.sectors_per_FAT, 0, p_vol->bpb.bytes_per_sector); \
|
||||
} \
|
||||
} \
|
||||
err = VFiPFSEC_ReadFAT(p_vol, p_page->p_buf, sector + (next_sector), 0, p_vol->bpb.bytes_per_sector); \
|
||||
if (err != 0) { continue; } \
|
||||
p_page->sector = sector + (next_sector); \
|
||||
}
|
||||
|
||||
offset = (pf_u16)(cluster + (cluster >> 1));
|
||||
sector = p_vol->bpb.active_FAT_sector + (offset >> p_vol->bpb.log2_bytes_per_sector) & 0xFFFF;
|
||||
if ((p_vol->bpb.ext_flags & 0x80) != 0) {
|
||||
current_fat = p_vol->bpb.ext_flags & (0x01 | 0x02 | 0x04);
|
||||
} else {
|
||||
current_fat = 1;
|
||||
}
|
||||
err = 0;
|
||||
while (PF_TRUE) {
|
||||
if (err == 0x1000 && p_vol->p_callback != PF_NULL) {
|
||||
result = ((PF_VOLUME_CB)p_vol->p_callback)(p_vol->last_driver_error);
|
||||
if (result == 0) {
|
||||
err = 0;
|
||||
continue;
|
||||
}
|
||||
if (result == 1 && p_vol->bpb.num_active_FATs >= 2 && current_fat < p_vol->bpb.num_active_FATs) {
|
||||
current_fat++;
|
||||
sector += p_vol->bpb.sectors_per_FAT;
|
||||
err = 0;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
LOAD_FAT_SECTOR(0);
|
||||
offset &= p_vol->bpb.bytes_per_sector - 1;
|
||||
if (offset == (p_vol->bpb.bytes_per_sector - 1)) {
|
||||
*p_value = *(p_page->p_buf + offset);
|
||||
if (p_page->option == 1) {
|
||||
for (err = 0; (pf_u16)err < p_vol->bpb.num_active_FATs; err++) {
|
||||
VFiPFSEC_WriteFAT(p_vol, p_page->p_buf, p_page->sector + (pf_u16)err * p_vol->bpb.sectors_per_FAT, 0, p_vol->bpb.bytes_per_sector);
|
||||
}
|
||||
}
|
||||
err = VFiPFSEC_ReadFAT(p_vol, p_page->p_buf, sector + 1, 0, p_vol->bpb.bytes_per_sector);
|
||||
if (err != 0) { continue; }
|
||||
p_page->sector = sector + 1;
|
||||
*p_value += (pf_u16)(*p_page->p_buf) << 8;
|
||||
} else {
|
||||
*p_value = ((pf_u16)p_page->p_buf[offset + 1] << 8) + *(p_page->p_buf + offset);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (err != 0) {
|
||||
*p_value = -1;
|
||||
return err;
|
||||
}
|
||||
if ((cluster & 0x01) != 0) {
|
||||
*p_value = *p_value >> 4;
|
||||
} else {
|
||||
*p_value &= 0xFFF;
|
||||
}
|
||||
return 0;
|
||||
|
||||
#undef LOAD_FAT_SECTOR
|
||||
}
|
||||
158
libs/RVL_SDK/src/fa/pf_fat16.c
Normal file
158
libs/RVL_SDK/src/fa/pf_fat16.c
Normal file
@@ -0,0 +1,158 @@
|
||||
#define PF_FA_STR_LAYOUT
|
||||
#define VFiPFCACHE_ReadFATPage PFCACHE_ReadFATPage
|
||||
#define VFiPFCACHE_UpdateModifiedSector PFCACHE_UpdateModifiedSector
|
||||
#define VFiPFFAT16_ReadFATEntry PFFAT16_ReadFATEntry
|
||||
#define VFiPFFAT16_ReadFATEntryPage PFFAT16_ReadFATEntryPage
|
||||
#define VFiPFFAT16_WriteFATEntry PFFAT16_WriteFATEntry
|
||||
#define VFiPFFAT16_WriteFATEntryPage PFFAT16_WriteFATEntryPage
|
||||
#define VFiPFFAT_UpdateFATEntry PFFAT_UpdateFATEntry
|
||||
#define VFiPFSEC_ReadFAT PFSEC_ReadFAT
|
||||
#define VFiPFSEC_WriteFAT PFSEC_WriteFAT
|
||||
#include <private/fa/pf_volume.h>
|
||||
#include <private/vf/PrFILE2/fatfs/pf_fat.h>
|
||||
#include <private/vf/PrFILE2/fatfs/pf_fat16.h>
|
||||
|
||||
#include <private/vf/PrFILE2/fatfs/pf_sector.h>
|
||||
#include <private/vf/PrFILE2/fatfs/pf_volume.h>
|
||||
|
||||
pf_s32 VFiPFFAT16_ReadFATEntry(PF_VOLUME* p_vol, pf_u32 cluster, pf_u32* p_value) {
|
||||
pf_u32 fat_offset;
|
||||
pf_u32 fat_sector;
|
||||
pf_u16 offset_in_sector;
|
||||
pf_u8 buf[sizeof(pf_u16)];
|
||||
pf_s32 err;
|
||||
pf_u32 current_fat;
|
||||
pf_s32 result;
|
||||
|
||||
fat_offset = cluster * sizeof(pf_u16);
|
||||
fat_sector = (pf_u16)(p_vol->bpb.active_FAT_sector + ((cluster * sizeof(pf_u16)) >> p_vol->bpb.log2_bytes_per_sector));
|
||||
offset_in_sector = fat_offset & (p_vol->bpb.bytes_per_sector - 1);
|
||||
if ((p_vol->bpb.ext_flags & 0x80) != 0) {
|
||||
current_fat = p_vol->bpb.ext_flags & (0x01 | 0x02 | 0x04);
|
||||
} else {
|
||||
current_fat = 1;
|
||||
}
|
||||
do {
|
||||
err = VFiPFSEC_ReadFAT(p_vol, buf, fat_sector, offset_in_sector, 2);
|
||||
if (err == 0x1000 && p_vol->p_callback != PF_NULL) {
|
||||
result = ((PF_VOLUME_CB)p_vol->p_callback)(p_vol->last_driver_error);
|
||||
if (result == 0) {
|
||||
continue;
|
||||
}
|
||||
if (result == 1 && p_vol->bpb.num_active_FATs >= 2 && current_fat < p_vol->bpb.num_active_FATs) {
|
||||
current_fat++;
|
||||
fat_sector += p_vol->bpb.sectors_per_FAT;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (err != 0) {
|
||||
*p_value = -1;
|
||||
return err;
|
||||
}
|
||||
} while (err != 0);
|
||||
|
||||
*p_value = PF_SWAP_16(*(pf_u16*)buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 VFiPFFAT16_WriteFATEntry(PF_VOLUME* p_vol, pf_u32 cluster, pf_u32 value) {
|
||||
pf_s32 err;
|
||||
pf_u32 fat_offset;
|
||||
pf_u16 fat_sector;
|
||||
pf_u16 offset_in_sector;
|
||||
pf_u32 current_fat;
|
||||
pf_s32 result;
|
||||
pf_u8 buf[sizeof(pf_u16)];
|
||||
|
||||
fat_offset = cluster * sizeof(pf_u16);
|
||||
fat_sector = p_vol->bpb.active_FAT_sector + ((cluster * sizeof(pf_u16)) >> p_vol->bpb.log2_bytes_per_sector);
|
||||
offset_in_sector = fat_offset & (p_vol->bpb.bytes_per_sector - 1);
|
||||
*(pf_u16*)buf = PF_SWAP_16(value);
|
||||
result = 0;
|
||||
for (current_fat = 0; current_fat < p_vol->bpb.num_active_FATs; current_fat++) {
|
||||
err = VFiPFSEC_WriteFAT(p_vol, buf, fat_sector, offset_in_sector, 2);
|
||||
if (err != 0 && result == 0) {
|
||||
result = err;
|
||||
}
|
||||
fat_sector += p_vol->bpb.sectors_per_FAT;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
pf_s32 PFFAT16_WriteFATEntryWithBuf(PF_VOLUME* p_vol, pf_u32 cluster, pf_u32 value, PF_CACHE_PAGE* p_page) {
|
||||
pf_u16 offset_in_sector;
|
||||
pf_s32 err;
|
||||
pf_u32 fat_offset;
|
||||
pf_u16 fat_sector;
|
||||
pf_u32 current_fat;
|
||||
pf_s32 result;
|
||||
fat_offset = cluster * sizeof(pf_u16);
|
||||
fat_sector = (pf_u16)(p_vol->bpb.active_FAT_sector + (fat_offset >> p_vol->bpb.log2_bytes_per_sector));
|
||||
offset_in_sector = (pf_u16)(fat_offset & (p_vol->bpb.bytes_per_sector - 1));
|
||||
err = 0;
|
||||
result = 0;
|
||||
if (p_page->sector != fat_sector) {
|
||||
for (current_fat = 0; current_fat < p_vol->bpb.num_active_FATs; current_fat++) {
|
||||
err = VFiPFSEC_WriteFAT(p_vol, p_page->p_buf, p_page->sector + current_fat * p_vol->bpb.sectors_per_FAT, 0, p_vol->bpb.bytes_per_sector);
|
||||
if (err != 0 && result == 0) {
|
||||
result = err;
|
||||
}
|
||||
}
|
||||
p_page->sector = fat_sector;
|
||||
err = VFiPFSEC_ReadFAT(p_vol, p_page->p_buf, fat_sector, 0, p_vol->bpb.bytes_per_sector);
|
||||
}
|
||||
p_page->p_buf[offset_in_sector] = value;
|
||||
(offset_in_sector + p_page->p_buf)[1] = value >> 8;
|
||||
if (err != 0) {
|
||||
result = err;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
pf_s32 PFFAT16_ReadFATEntryWithBuf(PF_VOLUME* p_vol, pf_u32 cluster, pf_u32* p_value, PF_CACHE_PAGE* p_page) {
|
||||
pf_u32 sector;
|
||||
pf_s32 err;
|
||||
pf_u32 offset;
|
||||
pf_u32 current_fat;
|
||||
pf_s32 result;
|
||||
|
||||
offset = cluster * sizeof(pf_u16);
|
||||
sector = (pf_u16)(p_vol->bpb.active_FAT_sector + (offset >> p_vol->bpb.log2_bytes_per_sector));
|
||||
current_fat = 1;
|
||||
if ((p_vol->bpb.ext_flags & 0x80) != 0) {
|
||||
current_fat = p_vol->bpb.ext_flags & 7;
|
||||
}
|
||||
if (p_page->sector != sector) {
|
||||
if (p_page->option == 1) {
|
||||
pf_u16 fat;
|
||||
for (fat = 0; fat < p_vol->bpb.num_active_FATs; fat++) {
|
||||
VFiPFSEC_WriteFAT(p_vol, p_page->p_buf, p_page->sector + fat * p_vol->bpb.sectors_per_FAT, 0, p_vol->bpb.bytes_per_sector);
|
||||
}
|
||||
}
|
||||
do {
|
||||
err = VFiPFSEC_ReadFAT(p_vol, p_page->p_buf, sector, 0, p_vol->bpb.bytes_per_sector);
|
||||
if (err != 0x1000 || p_vol->p_callback == PF_NULL) {
|
||||
goto block_22;
|
||||
}
|
||||
result = ((PF_VOLUME_CB)p_vol->p_callback)(p_vol->last_driver_error);
|
||||
if (result != 0) {
|
||||
if (result == 1 && p_vol->bpb.num_active_FATs >= 2 && current_fat < p_vol->bpb.num_active_FATs) {
|
||||
current_fat++;
|
||||
sector += p_vol->bpb.sectors_per_FAT;
|
||||
} else {
|
||||
goto block_22;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
block_22:
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
p_page->sector = sector;
|
||||
} while (err != 0);
|
||||
}
|
||||
offset &= p_vol->bpb.bytes_per_sector - 1;
|
||||
*p_value = PF_SWAP_16(*((pf_u16*)(p_page->p_buf + offset)));
|
||||
|
||||
return 0;
|
||||
}
|
||||
168
libs/RVL_SDK/src/fa/pf_fat32.c
Normal file
168
libs/RVL_SDK/src/fa/pf_fat32.c
Normal file
@@ -0,0 +1,168 @@
|
||||
#define PF_FA_STR_LAYOUT
|
||||
#define VFiPFCACHE_ReadFATPage PFCACHE_ReadFATPage
|
||||
#define VFiPFCACHE_UpdateModifiedSector PFCACHE_UpdateModifiedSector
|
||||
#define VFiPFFAT32_ReadFATEntry PFFAT32_ReadFATEntry
|
||||
#define VFiPFFAT32_ReadFATEntryPage PFFAT32_ReadFATEntryPage
|
||||
#define VFiPFFAT32_WriteFATEntry PFFAT32_WriteFATEntry
|
||||
#define VFiPFFAT32_WriteFATEntryPage PFFAT32_WriteFATEntryPage
|
||||
#define VFiPFFAT_UpdateFATEntry PFFAT_UpdateFATEntry
|
||||
#define VFiPFSEC_ReadFAT PFSEC_ReadFAT
|
||||
#define VFiPFSEC_WriteFAT PFSEC_WriteFAT
|
||||
#include <private/fa/pf_volume.h>
|
||||
#include <private/vf/PrFILE2/fatfs/pf_fat.h>
|
||||
#include <private/vf/PrFILE2/fatfs/pf_fat32.h>
|
||||
|
||||
#include <private/vf/PrFILE2/fatfs/pf_sector.h>
|
||||
#include <private/vf/PrFILE2/fatfs/pf_volume.h>
|
||||
|
||||
pf_s32 VFiPFFAT32_ReadFATEntry(PF_VOLUME* p_vol, pf_u32 cluster, pf_u32* p_value) {
|
||||
pf_u32 fat_offset;
|
||||
pf_u32 fat_sector;
|
||||
pf_u16 offset_in_sector;
|
||||
pf_u8 buf[sizeof(pf_u32)];
|
||||
pf_s32 err;
|
||||
pf_u32 current_fat;
|
||||
pf_s32 result;
|
||||
|
||||
fat_offset = cluster * sizeof(pf_u32);
|
||||
fat_sector = (pf_u16)(p_vol->bpb.active_FAT_sector + (fat_offset >> p_vol->bpb.log2_bytes_per_sector));
|
||||
offset_in_sector = fat_offset & (p_vol->bpb.bytes_per_sector - 1);
|
||||
if ((p_vol->bpb.ext_flags & 0x80) != 0) {
|
||||
current_fat = p_vol->bpb.ext_flags & (0x01 | 0x02 | 0x04);
|
||||
} else {
|
||||
current_fat = 1;
|
||||
}
|
||||
do {
|
||||
err = VFiPFSEC_ReadFAT(p_vol, buf, fat_sector, offset_in_sector, 4);
|
||||
if (err == 0x1000 && p_vol->p_callback != PF_NULL) {
|
||||
result = ((PF_VOLUME_CB)p_vol->p_callback)(p_vol->last_driver_error);
|
||||
if (result == 0) {
|
||||
continue;
|
||||
}
|
||||
if (result == 1 && p_vol->bpb.num_active_FATs >= 2 && current_fat < p_vol->bpb.num_active_FATs) {
|
||||
current_fat++;
|
||||
fat_sector += p_vol->bpb.sectors_per_FAT;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (err != 0) {
|
||||
*p_value = -1;
|
||||
return err;
|
||||
}
|
||||
} while (err != 0);
|
||||
|
||||
*p_value = PF_SWAP_32(*(pf_u32*)buf) & 0x0FFFFFFF;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 VFiPFFAT32_WriteFATEntry(PF_VOLUME* p_vol, pf_u32 cluster, pf_u32 value) {
|
||||
pf_s32 err;
|
||||
pf_u32 fat_offset;
|
||||
pf_u32 fat_sector;
|
||||
pf_u16 offset_in_sector;
|
||||
pf_u16 current_fat;
|
||||
pf_s32 result;
|
||||
pf_u8 buf[sizeof(pf_u32)];
|
||||
pf_u32 dword;
|
||||
|
||||
fat_offset = cluster * sizeof(pf_u32);
|
||||
fat_sector = (pf_u16)(p_vol->bpb.active_FAT_sector + (fat_offset >> p_vol->bpb.log2_bytes_per_sector));
|
||||
offset_in_sector = fat_offset & (p_vol->bpb.bytes_per_sector - 1);
|
||||
err = VFiPFSEC_ReadFAT(p_vol, buf, fat_sector, offset_in_sector, 4);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
dword = (value & 0x0FFFFFFF) | (PF_SWAP_32(*(pf_u32*)buf) & 0xF0000000);
|
||||
*(pf_u32*)buf = PF_SWAP_32(dword);
|
||||
result = 0;
|
||||
for (current_fat = 0; current_fat < p_vol->bpb.num_active_FATs; current_fat++) {
|
||||
err = VFiPFSEC_WriteFAT(p_vol, buf, fat_sector, offset_in_sector, 4);
|
||||
if (err != 0 && result == 0) {
|
||||
result = err;
|
||||
}
|
||||
fat_sector += p_vol->bpb.sectors_per_FAT;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
pf_s32 PFFAT32_WriteFATEntryWithBuf(PF_VOLUME* p_vol, pf_u32 cluster, pf_u32 value, PF_CACHE_PAGE* p_page) {
|
||||
pf_u32 merged_value;
|
||||
pf_u16 offset_in_sector;
|
||||
pf_s32 err;
|
||||
pf_u32 fat_offset;
|
||||
pf_u32 fat_sector;
|
||||
pf_u16 current_fat;
|
||||
pf_s32 result;
|
||||
fat_offset = cluster * sizeof(pf_u32);
|
||||
fat_sector = (pf_u16)(p_vol->bpb.active_FAT_sector + (fat_offset >> p_vol->bpb.log2_bytes_per_sector));
|
||||
offset_in_sector = (pf_u16)(fat_offset & (p_vol->bpb.bytes_per_sector - 1));
|
||||
err = 0;
|
||||
result = 0;
|
||||
if (p_page->sector != fat_sector) {
|
||||
for (current_fat = 0; current_fat < p_vol->bpb.num_active_FATs; current_fat++) {
|
||||
err = VFiPFSEC_WriteFAT(p_vol, p_page->p_buf, p_page->sector + current_fat * p_vol->bpb.sectors_per_FAT, 0, p_vol->bpb.bytes_per_sector);
|
||||
if (err != 0 && result == 0) {
|
||||
result = err;
|
||||
}
|
||||
}
|
||||
err = VFiPFSEC_ReadFAT(p_vol, p_page->p_buf, fat_sector, 0, p_vol->bpb.bytes_per_sector);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
p_page->sector = fat_sector;
|
||||
}
|
||||
merged_value = (value & 0x0FFFFFFF) | (PF_SWAP_32(*(pf_u32*)&p_page->p_buf[offset_in_sector]) & 0xF0000000);
|
||||
*(pf_u32*)&p_page->p_buf[offset_in_sector] = PF_SWAP_32(merged_value);
|
||||
if (err != 0) {
|
||||
result = err;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
pf_s32 PFFAT32_ReadFATEntryWithBuf(PF_VOLUME* p_vol, pf_u32 cluster, pf_u32* p_value, PF_CACHE_PAGE* p_page) {
|
||||
pf_u32 sector;
|
||||
pf_s32 err;
|
||||
pf_u32 offset;
|
||||
pf_u32 current_fat;
|
||||
pf_s32 result;
|
||||
|
||||
offset = cluster * sizeof(pf_u32);
|
||||
sector = (pf_u16)(p_vol->bpb.active_FAT_sector + (offset >> p_vol->bpb.log2_bytes_per_sector));
|
||||
current_fat = 1;
|
||||
if ((p_vol->bpb.ext_flags & 0x80) != 0) {
|
||||
current_fat = p_vol->bpb.ext_flags & 7;
|
||||
}
|
||||
if (p_page->sector != sector) {
|
||||
if (p_page->option == 1) {
|
||||
pf_u16 fat;
|
||||
for (fat = 0; fat < p_vol->bpb.num_active_FATs; fat++) {
|
||||
VFiPFSEC_WriteFAT(p_vol, p_page->p_buf, p_page->sector + fat * p_vol->bpb.sectors_per_FAT, 0, p_vol->bpb.bytes_per_sector);
|
||||
}
|
||||
}
|
||||
do {
|
||||
err = VFiPFSEC_ReadFAT(p_vol, p_page->p_buf, sector, 0, p_vol->bpb.bytes_per_sector);
|
||||
if (err != 0x1000 || p_vol->p_callback == PF_NULL) {
|
||||
goto block_22;
|
||||
}
|
||||
result = ((PF_VOLUME_CB)p_vol->p_callback)(p_vol->last_driver_error);
|
||||
if (result != 0) {
|
||||
if (result == 1 && p_vol->bpb.num_active_FATs >= 2 && current_fat < p_vol->bpb.num_active_FATs) {
|
||||
current_fat++;
|
||||
sector += p_vol->bpb.sectors_per_FAT;
|
||||
} else {
|
||||
goto block_22;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
block_22:
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
p_page->sector = sector;
|
||||
} while (err != 0);
|
||||
}
|
||||
offset &= p_vol->bpb.bytes_per_sector - 1;
|
||||
*p_value = PF_SWAP_32(*((pf_u32*)(p_page->p_buf + offset))) & 0x0FFFFFFF;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -3,6 +3,13 @@
|
||||
#include <private/vf/PrFILE2/fatfs/pf_path.h>
|
||||
#include <private/vf/PrFILE2/pf_types.h>
|
||||
|
||||
typedef struct PFDIR_STR {
|
||||
const pf_s8* p_head;
|
||||
const pf_s8* p_tail;
|
||||
const pf_s8* p_current;
|
||||
pf_u32 code_mode;
|
||||
} PFDIR_STR;
|
||||
|
||||
typedef struct PFFILE_FAT_HINT {
|
||||
pf_u32 chain_index;
|
||||
pf_u32 cluster;
|
||||
@@ -144,27 +151,27 @@ extern pf_s32 PFCLUSTER_AdjustCluster(PFFILE_FILE* file);
|
||||
extern pf_s32 PFCLUSTER_GetAppendSize(PFFILE_FILE* file, pf_u32* append_size);
|
||||
extern pf_s32 PFFAT_InitFFD(PFFILE_FFD* ffd, void* hint, PF_VOLUME* volume, pf_u32* start_cluster);
|
||||
extern void* pf_memset(void* destination, pf_s32 value, pf_u32 size);
|
||||
extern pf_u32 PFSTR_StrNumChar(PF_STR* path_string, pf_u32 mode);
|
||||
extern pf_u32 PFSTR_GetCodeMode(PF_STR* path_string);
|
||||
extern void* PFSTR_GetStrPos(PF_STR* path_string, pf_u32 mode);
|
||||
extern pf_s32 PFPATH_parseShortName(pf_s8* short_name, PF_STR* path_string);
|
||||
extern pf_u16 PFSTR_StrNumChar(PFDIR_STR* path_string, pf_u32 mode);
|
||||
extern pf_u32 PFSTR_GetCodeMode(PFDIR_STR* path_string);
|
||||
extern void* PFSTR_GetStrPos(PFDIR_STR* path_string, pf_u32 mode);
|
||||
extern pf_s32 PFPATH_parseShortName(pf_s8* short_name, PFDIR_STR* path_string);
|
||||
extern pf_s32 PFENT_AdjustSFN(PF_DIR_ENT* entry, pf_s8* short_name);
|
||||
extern void PFPATH_transformInUnicode(PF_DIR_ENT* entry, void* unicode_text);
|
||||
extern pf_u16* pf_w_strcpy(pf_u16* destination, const pf_u16* source);
|
||||
extern pf_u8 PFENT_getcurrentDateTimeForEnt(pf_u16* date, pf_u16* time);
|
||||
extern pf_s32 PFENT_allocateEntry(PF_DIR_ENT* entry, pf_u32 count, PFFILE_FFD* ffd,
|
||||
pf_u32* previous_sectors, PF_STR* filename);
|
||||
pf_u32* previous_sectors, PFDIR_STR* filename);
|
||||
extern pf_s32 PFENT_allocateEntryPos(PF_DIR_ENT* entry, pf_u32 count, PFFILE_FFD* ffd,
|
||||
pf_u32* previous_sectors, PF_STR* filename,
|
||||
pf_u32* previous_sectors, PFDIR_STR* filename,
|
||||
pf_u32* position);
|
||||
extern void PFPATH_AdjustExtShortName(pf_s8* short_name, pf_u32 position);
|
||||
extern pf_u8 PFENT_CalcCheckSum(PF_DIR_ENT* entry);
|
||||
extern void PFENT_storeLFNEntryFieldsToBuf(pf_u8* buffer, PF_DIR_ENT* entry, pf_u8 ordinal,
|
||||
pf_u8 checksum, pf_bool is_last);
|
||||
extern pf_s32 PFENT_updateEntry(PF_DIR_ENT* entry, pf_u32 update_archive);
|
||||
extern pf_s32 PFPATH_SplitPath(PF_STR* path, PF_STR* directory, PF_STR* filename);
|
||||
extern pf_s32 PFPATH_SplitPath(PFDIR_STR* path, PFDIR_STR* directory, PFDIR_STR* filename);
|
||||
extern pf_s32 PFENT_ITER_GetEntryOfPath(PFFILE_ENT_ITER* iter, PF_DIR_ENT* entry,
|
||||
PF_VOLUME* volume, PF_STR* path, pf_u32 no_look_last);
|
||||
PF_VOLUME* volume, PFDIR_STR* path, pf_u32 no_look_last);
|
||||
extern pf_s32 PFENT_RemoveEntry(PF_DIR_ENT* entry, PFFILE_ENT_ITER* iter);
|
||||
extern pf_s32 PFFAT_FreeChain(PFFILE_FFD* ffd, pf_u32 start_cluster, pf_u32 chain_index,
|
||||
pf_u32 size);
|
||||
@@ -172,7 +179,7 @@ extern pf_s32 PFCACHE_AllocateDataPage(PF_VOLUME* volume, pf_u32 sector,
|
||||
PF_CACHE_PAGE** page, pf_u32* option);
|
||||
extern void PFCACHE_FreeDataPage(PF_VOLUME* volume, PF_CACHE_PAGE* page);
|
||||
extern pf_s32 PFENT_findEntry(PFFILE_FFD* ffd, PF_DIR_ENT* entry, pf_u32 start,
|
||||
PF_STR* pattern, pf_u8 attr_required, pf_u32 flags);
|
||||
PFDIR_STR* pattern, pf_u8 attr_required, pf_u32 flags);
|
||||
extern pf_s32 PFCLUSTER_CombineFiles(PFFILE_ENT_ITER* first_iter,
|
||||
PFFILE_ENT_ITER* second_iter_copy,
|
||||
PF_DIR_ENT* first_entry, PF_DIR_ENT* second_entry);
|
||||
@@ -189,9 +196,9 @@ extern pf_s32 PFCACHE_FlushDataCacheSpecific(PF_VOLUME* volume, void* signature)
|
||||
extern pf_s32 PFCACHE_FlushFATCache(PF_VOLUME* volume);
|
||||
extern void PFFAT_InitHint(void* hint);
|
||||
extern void PFFAT_FinalizeFFD(PFFILE_FFD* ffd);
|
||||
extern void PFSTR_SetLocalStr(PF_STR* path_string, const pf_s8* converted_path);
|
||||
extern void PFSTR_SetLocalStr(PFDIR_STR* path_string, const pf_s8* converted_path);
|
||||
extern pf_s32 PFPATH_transformFromUnicodeToNormal(pf_s8* destination, const pf_u16* source);
|
||||
extern PF_VOLUME* PFPATH_GetVolumeFromPath(PF_STR* path_string);
|
||||
extern PF_VOLUME* PFPATH_GetVolumeFromPath(PFDIR_STR* path_string);
|
||||
extern pf_s32 PFVOL_CheckForWrite(PF_VOLUME* volume);
|
||||
extern pf_s32 PFVOL_CheckForRead(PF_VOLUME* volume);
|
||||
extern pf_s32 PFDRV_IsWProtected(PF_VOLUME* volume);
|
||||
@@ -414,16 +421,29 @@ pf_s32 PFFILE_Cursor_Read(PFFILE_FILE* file, pf_u8* buffer, pf_u32 size, pf_u32*
|
||||
return 0;
|
||||
}
|
||||
|
||||
static pf_bool PFFILE_Cursor_AdvanceToWrite(PFFILE_FILE* file, pf_u32 size, pf_u32 sector) {
|
||||
pf_bool result = PF_TRUE;
|
||||
PF_VOLUME* volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol;
|
||||
pf_u32 work_sector = sector + ((file->cursor.offset_in_sector + size) >> volume->bpb.log2_bytes_per_sector);
|
||||
|
||||
if (((volume->bpb.bytes_per_sector - 1) & (file->cursor.offset_in_sector + size)) != 0) {
|
||||
file->cursor.sector = sector + ((file->cursor.offset_in_sector + size) >> volume->bpb.log2_bytes_per_sector);
|
||||
} else {
|
||||
file->cursor.sector = -1;
|
||||
}
|
||||
file->cursor.position += size;
|
||||
if (file->cursor.position > file->p_sfd->dir_entry.file_size) {
|
||||
file->p_sfd->dir_entry.file_size = file->cursor.position;
|
||||
}
|
||||
PFFILE_Cursor_Recalc(file);
|
||||
PFCLUSTER_UpdateLastAccessCluster(file, work_sector);
|
||||
return result;
|
||||
}
|
||||
|
||||
pf_s32 PFFILE_Cursor_WriteHeadSector(PFFILE_FILE* file, const pf_u8* buffer, pf_u32 size,
|
||||
pf_u32* size_written) {
|
||||
pf_s32 error;
|
||||
pf_u32 success_size;
|
||||
pf_u32 next_position;
|
||||
pf_u32 new_position;
|
||||
pf_u32 current_sector;
|
||||
pf_u32 written_size;
|
||||
pf_u32 sector_advance;
|
||||
pf_u32 next_sector;
|
||||
PF_VOLUME* volume;
|
||||
|
||||
*size_written = 0;
|
||||
@@ -452,24 +472,7 @@ pf_s32 PFFILE_Cursor_WriteHeadSector(PFFILE_FILE* file, const pf_u8* buffer, pf_
|
||||
return error;
|
||||
}
|
||||
*size_written = success_size;
|
||||
current_sector = file->cursor.sector;
|
||||
written_size = success_size;
|
||||
volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol;
|
||||
next_position = file->cursor.offset_in_sector + written_size;
|
||||
sector_advance = next_position >> volume->bpb.log2_bytes_per_sector;
|
||||
next_sector = current_sector + sector_advance;
|
||||
if (((volume->bpb.bytes_per_sector - 1) & next_position) != 0) {
|
||||
file->cursor.sector = next_sector;
|
||||
} else {
|
||||
file->cursor.sector = -1;
|
||||
}
|
||||
new_position = file->cursor.position + success_size;
|
||||
file->cursor.position = new_position;
|
||||
if (new_position > file->p_sfd->dir_entry.file_size) {
|
||||
file->p_sfd->dir_entry.file_size = new_position;
|
||||
}
|
||||
PFFILE_Cursor_Recalc(file);
|
||||
PFCLUSTER_UpdateLastAccessCluster(file);
|
||||
PFFILE_Cursor_AdvanceToWrite(file, success_size, file->cursor.sector);
|
||||
if (success_size != size) {
|
||||
return error;
|
||||
}
|
||||
@@ -481,7 +484,6 @@ pf_s32 PFFILE_Cursor_WriteBodySectors(PFFILE_FILE* file, const pf_u8* buffer, pf
|
||||
pf_s32 error;
|
||||
pf_u32 num_sectors;
|
||||
pf_u32 success_size;
|
||||
pf_u32 next_position;
|
||||
PF_VOLUME* volume;
|
||||
|
||||
*size_written = 0;
|
||||
@@ -506,18 +508,7 @@ pf_s32 PFFILE_Cursor_WriteBodySectors(PFFILE_FILE* file, const pf_u8* buffer, pf
|
||||
return error;
|
||||
}
|
||||
*size_written = success_size;
|
||||
next_position = file->cursor.offset_in_sector + success_size;
|
||||
if (((volume->bpb.bytes_per_sector - 1) & next_position) != 0) {
|
||||
file->cursor.sector += next_position >> volume->bpb.log2_bytes_per_sector;
|
||||
} else {
|
||||
file->cursor.sector = -1;
|
||||
}
|
||||
file->cursor.position += success_size;
|
||||
if (file->cursor.position > file->p_sfd->dir_entry.file_size) {
|
||||
file->p_sfd->dir_entry.file_size = file->cursor.position;
|
||||
}
|
||||
PFFILE_Cursor_Recalc(file);
|
||||
PFCLUSTER_UpdateLastAccessCluster(file);
|
||||
PFFILE_Cursor_AdvanceToWrite(file, success_size, file->cursor.sector);
|
||||
if (success_size != size - (size & (volume->bpb.bytes_per_sector - 1))) {
|
||||
return error;
|
||||
}
|
||||
@@ -528,12 +519,6 @@ pf_s32 PFFILE_Cursor_WriteTailSector(PFFILE_FILE* file, const pf_u8* buffer, pf_
|
||||
pf_u32* size_written) {
|
||||
pf_s32 error;
|
||||
pf_u32 success_size;
|
||||
pf_u32 next_position;
|
||||
pf_u32 current_sector;
|
||||
pf_u32 written_size;
|
||||
pf_u32 sector_advance;
|
||||
pf_u32 next_sector;
|
||||
pf_u32 new_position;
|
||||
PF_VOLUME* volume;
|
||||
|
||||
*size_written = 0;
|
||||
@@ -563,24 +548,7 @@ pf_s32 PFFILE_Cursor_WriteTailSector(PFFILE_FILE* file, const pf_u8* buffer, pf_
|
||||
return error;
|
||||
}
|
||||
*size_written = success_size;
|
||||
current_sector = file->cursor.sector;
|
||||
written_size = success_size;
|
||||
volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol;
|
||||
next_position = file->cursor.offset_in_sector + written_size;
|
||||
sector_advance = next_position >> volume->bpb.log2_bytes_per_sector;
|
||||
next_sector = current_sector + sector_advance;
|
||||
if (((volume->bpb.bytes_per_sector - 1) & next_position) != 0) {
|
||||
file->cursor.sector = next_sector;
|
||||
} else {
|
||||
file->cursor.sector = -1;
|
||||
}
|
||||
new_position = file->cursor.position + success_size;
|
||||
file->cursor.position = new_position;
|
||||
if (new_position > file->p_sfd->dir_entry.file_size) {
|
||||
file->p_sfd->dir_entry.file_size = new_position;
|
||||
}
|
||||
PFFILE_Cursor_Recalc(file);
|
||||
PFCLUSTER_UpdateLastAccessCluster(file);
|
||||
PFFILE_Cursor_AdvanceToWrite(file, success_size, file->cursor.sector);
|
||||
if (success_size != size) {
|
||||
return error;
|
||||
}
|
||||
@@ -689,23 +657,28 @@ void PFFILE_Cursor_MoveToClusterEnd(PFFILE_FILE* file, pf_u32 size) {
|
||||
}
|
||||
}
|
||||
|
||||
PFFILE_SFD* PFFILE_GetSFD(PF_VOLUME* volume, PF_DIR_ENT* entry) {
|
||||
PFFILE_VOLUME_DIRS* volume_dirs = (PFFILE_VOLUME_DIRS*)volume;
|
||||
PFFILE_SFD* first_free_sfd = PF_NULL;
|
||||
PFFILE_SFD* sfd = volume_dirs->sfds;
|
||||
pf_u32 first_free_index = 0;
|
||||
pf_u32 index = 0;
|
||||
PFFILE_SFD* PFFILE_GetSFD(PFFILE_VOLUME_DIRS* volume_dirs, PF_DIR_ENT* entry) {
|
||||
pf_u32 index;
|
||||
pf_u32 first_free_index;
|
||||
PFFILE_SFD* first_free_sfd;
|
||||
|
||||
for (; index < 5; index++, sfd++) {
|
||||
if ((sfd->stat & 1) == 0 || (sfd->stat & 2) == 0) {
|
||||
first_free_index = 0;
|
||||
first_free_sfd = PF_NULL;
|
||||
|
||||
for (index = 0; index < 5; index++) {
|
||||
if ((volume_dirs->sfds[index].stat & 1) == 0 ||
|
||||
((volume_dirs->sfds[index].stat & 1) != 0 &&
|
||||
((volume_dirs->sfds[index].stat == 0) & 2) != 0)) {
|
||||
if (first_free_sfd == PF_NULL) {
|
||||
first_free_sfd = sfd;
|
||||
first_free_sfd = &volume_dirs->sfds[index];
|
||||
first_free_index = index;
|
||||
}
|
||||
} else if (entry->p_vol == sfd->dir_entry.p_vol &&
|
||||
entry->entry_sector == sfd->dir_entry.entry_sector &&
|
||||
entry->entry_offset == sfd->dir_entry.entry_offset) {
|
||||
return sfd;
|
||||
continue;
|
||||
}
|
||||
if (entry->p_vol == volume_dirs->sfds[index].dir_entry.p_vol &&
|
||||
entry->entry_sector == volume_dirs->sfds[index].dir_entry.entry_sector &&
|
||||
entry->entry_offset == volume_dirs->sfds[index].dir_entry.entry_offset) {
|
||||
return &volume_dirs->sfds[index];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -741,23 +714,27 @@ PFFILE_SFD* PFFILE_GetSFD(PF_VOLUME* volume, PF_DIR_ENT* entry) {
|
||||
return first_free_sfd;
|
||||
}
|
||||
|
||||
pf_s32 PFFILE_createEmptyFile(PF_VOLUME* volume, PF_DIR_ENT* entry, PF_STR* filename) {
|
||||
pf_s32 PFFILE_createEmptyFile(PF_VOLUME* volume, PF_DIR_ENT* entry, PFDIR_STR* filename) {
|
||||
PF_DIR_ENT parent_entry = *entry;
|
||||
PFFILE_FFD ffd;
|
||||
PF_FAT_HINT hint;
|
||||
PFFILE_FAT_HINT hint;
|
||||
pf_u32 previous_sectors[2];
|
||||
pf_u32 entry_position;
|
||||
pf_u32 num_chars;
|
||||
pf_u32 num_entries;
|
||||
pf_u32* previous_sector_ptr;
|
||||
pf_u32 success_size;
|
||||
pf_s32 num_chars;
|
||||
pf_u8 num_entries;
|
||||
pf_u32 ordinal;
|
||||
pf_u32 sector;
|
||||
pf_u32 success_size;
|
||||
pf_u32 entry_position;
|
||||
pf_u8 checksum;
|
||||
pf_s32 error;
|
||||
pf_u8 short_entry_buffer[13];
|
||||
pf_u8 long_entry_buffer[32];
|
||||
|
||||
num_chars = PFSTR_StrNumChar(filename, 1) & 0xFFFF;
|
||||
if (num_chars + parent_entry.path_len >= 0x104 || num_chars >= 0x100) {
|
||||
num_chars = PFSTR_StrNumChar(filename, 1);
|
||||
if (num_chars + parent_entry.path_len > 0x103) {
|
||||
return 1;
|
||||
}
|
||||
if (num_chars > 0xFF) {
|
||||
return 1;
|
||||
}
|
||||
PFFAT_InitFFD(&ffd, &hint, parent_entry.p_vol, &parent_entry.start_cluster);
|
||||
@@ -768,9 +745,7 @@ pf_s32 PFFILE_createEmptyFile(PF_VOLUME* volume, PF_DIR_ENT* entry, PF_STR* file
|
||||
if (error != 0 && entry->short_name[0] == 0) {
|
||||
return 1;
|
||||
}
|
||||
if (error == 0) {
|
||||
entry->long_name[0] = 0;
|
||||
} else {
|
||||
if (error != 0) {
|
||||
error = PFENT_AdjustSFN(&parent_entry, entry->short_name);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
@@ -780,8 +755,14 @@ pf_s32 PFFILE_createEmptyFile(PF_VOLUME* volume, PF_DIR_ENT* entry, PF_STR* file
|
||||
} else {
|
||||
pf_w_strcpy(entry->long_name, (const pf_u16*)PFSTR_GetStrPos(filename, 1));
|
||||
}
|
||||
} else {
|
||||
entry->long_name[0] = 0;
|
||||
}
|
||||
if (volume->bpb.fat_type == FAT_32) {
|
||||
entry->start_cluster = 1;
|
||||
} else {
|
||||
entry->start_cluster = 0;
|
||||
}
|
||||
entry->start_cluster = volume->bpb.fat_type == FAT_32 ? 1 : 0;
|
||||
entry->file_size = 0;
|
||||
entry->p_vol = volume;
|
||||
entry->small_letter_flag = 0;
|
||||
@@ -798,14 +779,16 @@ pf_s32 PFFILE_createEmptyFile(PF_VOLUME* volume, PF_DIR_ENT* entry, PF_STR* file
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if ((pf_vol_set.file_settings & 2) != 0) {
|
||||
if ((pf_vol_set.file_settings & 2) == 2) {
|
||||
PFPATH_AdjustExtShortName(entry->short_name, entry_position);
|
||||
}
|
||||
entry->num_entry_LFNs = num_entries;
|
||||
sector = entry->entry_sector;
|
||||
for (ordinal = num_entries; ordinal != 0; ordinal--) {
|
||||
checksum = PFENT_CalcCheckSum(entry);
|
||||
previous_sector_ptr = previous_sectors;
|
||||
for (ordinal = num_entries; ordinal >= 1; ordinal--) {
|
||||
PFENT_storeLFNEntryFieldsToBuf(long_entry_buffer, entry, ordinal,
|
||||
PFENT_CalcCheckSum(entry), ordinal == num_entries);
|
||||
checksum, ordinal == num_entries);
|
||||
error = PFSEC_WriteData(volume, long_entry_buffer, sector, entry->entry_offset,
|
||||
0x20, &success_size, 0);
|
||||
if (error != 0) {
|
||||
@@ -817,8 +800,8 @@ pf_s32 PFFILE_createEmptyFile(PF_VOLUME* volume, PF_DIR_ENT* entry, PF_STR* file
|
||||
entry->entry_offset += 0x20;
|
||||
if (entry->entry_offset >= volume->bpb.bytes_per_sector) {
|
||||
entry->entry_offset = 0;
|
||||
sector = previous_sectors[0];
|
||||
previous_sectors[0] = previous_sectors[1];
|
||||
sector = *previous_sector_ptr;
|
||||
previous_sector_ptr++;
|
||||
}
|
||||
}
|
||||
entry->entry_sector = sector;
|
||||
@@ -834,14 +817,30 @@ pf_s32 PFFILE_createEmptyFile(PF_VOLUME* volume, PF_DIR_ENT* entry, PF_STR* file
|
||||
return PFENT_updateEntry(entry, 1);
|
||||
}
|
||||
|
||||
pf_s32 PFFILE_p_remove(PF_VOLUME* volume, PF_STR* path) {
|
||||
PF_STR directory;
|
||||
PF_STR filename;
|
||||
static pf_bool PFFILE_IsEntryOpened(PFFILE_VOLUME_DIRS* volume_dirs, PF_DIR_ENT* entry) {
|
||||
PFFILE_SFD* sfd;
|
||||
pf_u32 index;
|
||||
|
||||
for (index = 0, sfd = volume_dirs->sfds; index < 5; index++, sfd++) {
|
||||
if ((sfd->stat & 1) != 0 && (sfd->stat & 2) != 0 &&
|
||||
entry->p_vol == sfd->dir_entry.p_vol &&
|
||||
entry->entry_sector == sfd->dir_entry.entry_sector &&
|
||||
entry->entry_offset == sfd->dir_entry.entry_offset) {
|
||||
return PF_TRUE;
|
||||
}
|
||||
}
|
||||
return PF_FALSE;
|
||||
}
|
||||
|
||||
pf_s32 PFFILE_p_remove(PF_VOLUME* volume, PFDIR_STR* path) {
|
||||
PFDIR_STR directory;
|
||||
PFDIR_STR filename;
|
||||
PF_DIR_ENT entry;
|
||||
PFFILE_ENT_ITER iter;
|
||||
PFFILE_VOLUME_DIRS* volume_dirs = (PFFILE_VOLUME_DIRS*)volume;
|
||||
PFFILE_FAT_HINT hint;
|
||||
PFFILE_VOLUME_DIRS* volume_dirs;
|
||||
pf_u32 start_cluster;
|
||||
pf_s32 error;
|
||||
pf_u32 index;
|
||||
|
||||
error = PFPATH_SplitPath(path, &directory, &filename);
|
||||
if (error != 0) {
|
||||
@@ -851,37 +850,35 @@ pf_s32 PFFILE_p_remove(PF_VOLUME* volume, PF_STR* path) {
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
hint = *(PFFILE_FAT_HINT*)iter.ffd.p_hint;
|
||||
if ((entry.attr & 0x19) != 0) {
|
||||
return 0xB;
|
||||
}
|
||||
for (index = 0; index < 5; index++) {
|
||||
if ((volume_dirs->sfds[index].stat & 1) != 0 &&
|
||||
(volume_dirs->sfds[index].stat & 2) != 0 &&
|
||||
entry.p_vol == volume_dirs->sfds[index].dir_entry.p_vol &&
|
||||
entry.entry_sector == volume_dirs->sfds[index].dir_entry.entry_sector &&
|
||||
entry.entry_offset == volume_dirs->sfds[index].dir_entry.entry_offset) {
|
||||
return 0x13;
|
||||
}
|
||||
volume_dirs = (PFFILE_VOLUME_DIRS*)entry.p_vol;
|
||||
if (PFFILE_IsEntryOpened(volume_dirs, &entry)) {
|
||||
return 0x13;
|
||||
}
|
||||
iter.ffd.p_hint = (PF_FAT_HINT*)&hint;
|
||||
start_cluster = entry.start_cluster;
|
||||
error = PFENT_RemoveEntry(&entry, &iter);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
return PFFAT_FreeChain(&iter.ffd, entry.start_cluster, 0xFFFFFFFF, entry.file_size);
|
||||
return PFFAT_FreeChain(&iter.ffd, start_cluster, 0xFFFFFFFF, entry.file_size);
|
||||
}
|
||||
|
||||
pf_s32 PFFILE_p_fopen(PF_VOLUME* volume, PF_STR* path, pf_u32 open_mode,
|
||||
pf_s32 PFFILE_p_fopen(PF_VOLUME* volume, PFDIR_STR* path, pf_u32 open_mode,
|
||||
PFFILE_FILE** result) {
|
||||
PF_STR directory;
|
||||
PF_STR filename;
|
||||
PFDIR_STR filename;
|
||||
PFDIR_STR directory;
|
||||
PF_DIR_ENT entry;
|
||||
PFFILE_ENT_ITER iter;
|
||||
PFFILE_FFD ffd;
|
||||
PF_FAT_HINT hint;
|
||||
PFFILE_SFD* sfd;
|
||||
PFFILE_FAT_HINT hint;
|
||||
PFFILE_FILE* file;
|
||||
PFFILE_SFD* sfd;
|
||||
pf_s8 normalized_filename[0x200];
|
||||
pf_u32 num_chars;
|
||||
pf_s32 num_chars;
|
||||
pf_u32 index;
|
||||
pf_u32 success_size;
|
||||
pf_u16 access_time;
|
||||
@@ -900,7 +897,7 @@ pf_s32 PFFILE_p_fopen(PF_VOLUME* volume, PF_STR* path, pf_u32 open_mode,
|
||||
return 1;
|
||||
}
|
||||
if (PFSTR_GetCodeMode(&filename) == 2) {
|
||||
num_chars = PFSTR_StrNumChar(&filename, 1) & 0xFFFF;
|
||||
num_chars = PFSTR_StrNumChar(&filename, 1);
|
||||
if (num_chars > 0xFF) {
|
||||
return 1;
|
||||
}
|
||||
@@ -908,49 +905,7 @@ pf_s32 PFFILE_p_fopen(PF_VOLUME* volume, PF_STR* path, pf_u32 open_mode,
|
||||
(const pf_u16*)PFSTR_GetStrPos(&filename, 1));
|
||||
}
|
||||
PFSTR_SetLocalStr(&filename, normalized_filename);
|
||||
if ((open_mode & 2) == 0) {
|
||||
error = PFFILE_createEmptyFile(volume, &entry, &filename);
|
||||
if (error == 8) {
|
||||
if ((open_mode & 0x10) != 0) {
|
||||
return 8;
|
||||
}
|
||||
if ((open_mode & 1) != 0) {
|
||||
for (index = 0; index < 5; index++) {
|
||||
if ((((PFFILE_VOLUME_DIRS*)entry.p_vol)->sfds[index].stat & 3) == 3 &&
|
||||
entry.p_vol ==
|
||||
((PFFILE_VOLUME_DIRS*)entry.p_vol)->sfds[index].dir_entry.p_vol &&
|
||||
entry.entry_sector ==
|
||||
((PFFILE_VOLUME_DIRS*)entry.p_vol)->sfds[index].dir_entry.entry_sector &&
|
||||
entry.entry_offset ==
|
||||
((PFFILE_VOLUME_DIRS*)entry.p_vol)->sfds[index].dir_entry.entry_offset) {
|
||||
return 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((entry.attr & 1) != 0 &&
|
||||
((open_mode & 1) != 0 || (open_mode & 4) != 0 || (open_mode & 8) != 0)) {
|
||||
return 0xA;
|
||||
}
|
||||
if ((entry.attr & 0x10) != 0) {
|
||||
return 0x17;
|
||||
}
|
||||
if ((open_mode & 1) != 0) {
|
||||
PFFAT_InitFFD(&ffd, &hint, entry.p_vol, &entry.start_cluster);
|
||||
if (entry.start_cluster > 1 && entry.start_cluster != 0xFFFFFFFF &&
|
||||
entry.file_size != 0) {
|
||||
PFFAT_FreeChain(&ffd, entry.start_cluster, 0xFFFFFFFF, entry.file_size);
|
||||
}
|
||||
entry.start_cluster = 0;
|
||||
entry.file_size = 0;
|
||||
PFENT_getcurrentDateTimeForEnt(&entry.modify_date, &entry.modify_time);
|
||||
entry.access_date = entry.modify_date;
|
||||
} else {
|
||||
PFENT_getcurrentDateTimeForEnt(&entry.access_date, &access_time);
|
||||
}
|
||||
} else if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
} else {
|
||||
if ((open_mode & 2) != 0) {
|
||||
PFFAT_InitFFD(&ffd, &hint, entry.p_vol, &entry.start_cluster);
|
||||
error = PFENT_findEntry(&ffd, &entry, 0, &filename, 0x7F, 0);
|
||||
if (error != 0) {
|
||||
@@ -963,9 +918,41 @@ pf_s32 PFFILE_p_fopen(PF_VOLUME* volume, PF_STR* path, pf_u32 open_mode,
|
||||
return 0x17;
|
||||
}
|
||||
PFENT_getcurrentDateTimeForEnt(&entry.access_date, &access_time);
|
||||
} else {
|
||||
error = PFFILE_createEmptyFile(volume, &entry, &filename);
|
||||
if (error == 8) {
|
||||
if ((open_mode & 0x10) != 0) {
|
||||
return 8;
|
||||
}
|
||||
if ((open_mode & 1) != 0 && PFFILE_IsOpened(&entry)) {
|
||||
return 8;
|
||||
}
|
||||
if ((entry.attr & 1) != 0 &&
|
||||
((open_mode & 1) != 0 || (open_mode & 4) != 0 || (open_mode & 8) != 0)) {
|
||||
return 0xA;
|
||||
}
|
||||
if ((entry.attr & 0x10) != 0) {
|
||||
return 0x17;
|
||||
}
|
||||
if ((open_mode & 1) != 0) {
|
||||
if (entry.start_cluster >= 2 && entry.start_cluster != 0xFFFFFFFF &&
|
||||
entry.file_size != 0) {
|
||||
PFFAT_FreeChain(&iter.ffd, entry.start_cluster, 0xFFFFFFFF,
|
||||
entry.file_size);
|
||||
}
|
||||
entry.start_cluster = 0;
|
||||
entry.file_size = 0;
|
||||
PFENT_getcurrentDateTimeForEnt(&entry.modify_date, &entry.modify_time);
|
||||
entry.access_date = entry.modify_date;
|
||||
} else {
|
||||
PFENT_getcurrentDateTimeForEnt(&entry.access_date, &access_time);
|
||||
}
|
||||
} else if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
volume = entry.p_vol;
|
||||
sfd = PFFILE_GetSFD(volume, &entry);
|
||||
sfd = PFFILE_GetSFD((PFFILE_VOLUME_DIRS*)volume, &entry);
|
||||
if (sfd == PF_NULL) {
|
||||
return 0x15;
|
||||
}
|
||||
@@ -982,18 +969,17 @@ pf_s32 PFFILE_p_fopen(PF_VOLUME* volume, PF_STR* path, pf_u32 open_mode,
|
||||
file->p_sfd = sfd;
|
||||
file->stat = 1;
|
||||
file->open_mode = open_mode;
|
||||
file->last_access_data.state.last_access_chain_index = 0;
|
||||
file->last_access_data.state.last_error = 0;
|
||||
file->lock_count = 0;
|
||||
PFFAT_InitHint(&file->hint);
|
||||
file->cursor.position = 0;
|
||||
file->cursor.sector = 0xFFFFFFFF;
|
||||
file->cursor.position = 0;
|
||||
PFFILE_Cursor_Recalc(file);
|
||||
if ((open_mode & 1) != 0) {
|
||||
sfd->stat |= 4;
|
||||
file->p_sfd->stat |= 4;
|
||||
}
|
||||
if ((open_mode & 4) != 0) {
|
||||
file->cursor.position = entry.file_size;
|
||||
if ((file->open_mode & 4) != 0) {
|
||||
file->cursor.position = file->p_sfd->dir_entry.file_size;
|
||||
PFFILE_Cursor_Recalc(file);
|
||||
}
|
||||
sfd->handler_count++;
|
||||
@@ -1001,8 +987,29 @@ pf_s32 PFFILE_p_fopen(PF_VOLUME* volume, PF_STR* path, pf_u32 open_mode,
|
||||
return 0;
|
||||
}
|
||||
|
||||
#pragma dont_inline on
|
||||
pf_s32 PFFILE_p_fread(PF_VOLUME* volume, pf_u8* buffer, pf_u32 size, pf_u32 count,
|
||||
PFFILE_FILE* file, pf_u32* count_read);
|
||||
PFFILE_FILE* file, pf_u32* count_read) {
|
||||
pf_u32 bytes_read = 0;
|
||||
pf_s32 error;
|
||||
|
||||
*count_read = 0;
|
||||
if ((file->open_mode & 8) == 0 &&
|
||||
((file->open_mode & 1) != 0 || (file->open_mode & 4) != 0)) {
|
||||
return 0xA;
|
||||
}
|
||||
if ((file->p_sfd->lock.mode & 3) != 0 && file->lock_count == 0) {
|
||||
return 0x19;
|
||||
}
|
||||
if (file->cursor.position >= file->p_sfd->dir_entry.file_size) {
|
||||
return 0x1C;
|
||||
}
|
||||
error = PFFILE_Cursor_Read(file, buffer, size * count, &bytes_read);
|
||||
*count_read = bytes_read / size;
|
||||
error &= (-error | error) >> 31;
|
||||
return error;
|
||||
}
|
||||
#pragma dont_inline reset
|
||||
|
||||
pf_s32 PFFILE_p_fwrite(PF_VOLUME* volume, const pf_u8* buffer, pf_u32 size, pf_u32 count,
|
||||
PFFILE_FILE* file, pf_u32* count_written) {
|
||||
@@ -1028,32 +1035,37 @@ pf_s32 PFFILE_p_fwrite(PF_VOLUME* volume, const pf_u8* buffer, pf_u32 size, pf_u
|
||||
if (file->cursor.position > file->p_sfd->dir_entry.file_size) {
|
||||
remaining = file->cursor.position - file->p_sfd->dir_entry.file_size;
|
||||
file->cursor.position = file->p_sfd->dir_entry.file_size;
|
||||
PFFILE_Cursor_Recalc(file);
|
||||
file->cursor.file_sector_index = file->cursor.position >> volume->bpb.log2_bytes_per_sector;
|
||||
file->cursor.offset_in_sector = file->cursor.position & (volume->bpb.bytes_per_sector - 1);
|
||||
error = PFCACHE_AllocateDataPage(volume, 0xFFFFFFFF, &page, &allocation_option);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
pf_memset(page->p_buf, 0, volume->bpb.bytes_per_sector);
|
||||
while (remaining != 0) {
|
||||
if (remaining <= volume->bpb.bytes_per_sector) {
|
||||
if (remaining > volume->bpb.bytes_per_sector) {
|
||||
error = PFFILE_Cursor_Write(file, page->p_buf, volume->bpb.bytes_per_sector,
|
||||
&bytes_written);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
} else {
|
||||
error = PFFILE_Cursor_Write(file, page->p_buf, remaining, &bytes_written);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
break;
|
||||
}
|
||||
error = PFFILE_Cursor_Write(file, page->p_buf, volume->bpb.bytes_per_sector,
|
||||
&bytes_written);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
remaining -= volume->bpb.bytes_per_sector;
|
||||
}
|
||||
PFCACHE_FreeDataPage(volume, page);
|
||||
}
|
||||
error = PFFILE_Cursor_Write(file, buffer, size * count, &bytes_written);
|
||||
*count_written = bytes_written / size;
|
||||
return error;
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFFILE_p_fappend(PFFILE_FILE* file, pf_u32 size, pf_u32* size_appended) {
|
||||
@@ -1120,14 +1132,14 @@ pf_s32 PFFILE_p_finfo(PFFILE_FILE* file, PF_INFO* info) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFFILE_p_combine(PF_VOLUME* volume, PF_STR* first_path, PF_STR* second_path) {
|
||||
pf_s32 PFFILE_p_combine(PF_VOLUME* volume, PFDIR_STR* first_path, PFDIR_STR* second_path) {
|
||||
PFFILE_ENT_ITER first_iter;
|
||||
PFFILE_ENT_ITER second_iter;
|
||||
PFFILE_ENT_ITER second_iter_copy;
|
||||
PF_DIR_ENT first_entry;
|
||||
PF_DIR_ENT second_entry;
|
||||
PF_FAT_HINT first_hint;
|
||||
PF_FAT_HINT second_hint;
|
||||
PFFILE_FAT_HINT first_hint;
|
||||
PFFILE_FAT_HINT second_hint;
|
||||
pf_u32 index;
|
||||
pf_s32 found;
|
||||
pf_s32 error;
|
||||
@@ -1146,41 +1158,14 @@ pf_s32 PFFILE_p_combine(PF_VOLUME* volume, PF_STR* first_path, PF_STR* second_pa
|
||||
if ((first_entry.attr & 1) != 0 || (second_entry.attr & 1) != 0) {
|
||||
return 0x18;
|
||||
}
|
||||
found = 0;
|
||||
for (index = 0; index < 5; index++) {
|
||||
PFFILE_SFD* sfd = &((PFFILE_VOLUME_DIRS*)first_entry.p_vol)->sfds[index];
|
||||
|
||||
if ((sfd->stat & 1) != 0 && (sfd->stat & 2) != 0 &&
|
||||
first_entry.p_vol == sfd->dir_entry.p_vol &&
|
||||
first_entry.entry_sector == sfd->dir_entry.entry_sector &&
|
||||
first_entry.entry_offset == sfd->dir_entry.entry_offset) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found != 0) {
|
||||
return 0x13;
|
||||
}
|
||||
found = 0;
|
||||
for (index = 0; index < 5; index++) {
|
||||
PFFILE_SFD* sfd = &((PFFILE_VOLUME_DIRS*)second_entry.p_vol)->sfds[index];
|
||||
|
||||
if ((sfd->stat & 1) != 0 && (sfd->stat & 2) != 0 &&
|
||||
second_entry.p_vol == sfd->dir_entry.p_vol &&
|
||||
second_entry.entry_sector == sfd->dir_entry.entry_sector &&
|
||||
second_entry.entry_offset == sfd->dir_entry.entry_offset) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found != 0) {
|
||||
if (PFFILE_IsOpened(&first_entry) || PFFILE_IsOpened(&second_entry)) {
|
||||
return 0x13;
|
||||
}
|
||||
if (first_entry.entry_sector == second_entry.entry_sector &&
|
||||
first_entry.entry_offset == second_entry.entry_offset) {
|
||||
return 0xA;
|
||||
}
|
||||
if (0xFFFFFFFF - second_entry.file_size < first_entry.file_size) {
|
||||
if (0xFFFFFFFF - first_entry.file_size < second_entry.file_size) {
|
||||
return 0x25;
|
||||
}
|
||||
PFFAT_InitHint(&first_hint);
|
||||
@@ -1202,25 +1187,21 @@ pf_s32 PFFILE_p_combine(PF_VOLUME* volume, PF_STR* first_path, PF_STR* second_pa
|
||||
return error & (-error | error) >> 31;
|
||||
}
|
||||
|
||||
pf_s32 PFFILE_p_divide(PF_VOLUME* volume, PF_STR* source_path, PF_STR* destination_path,
|
||||
pf_s32 PFFILE_p_divide(PF_VOLUME* volume, PFDIR_STR* source_path, PFDIR_STR* destination_path,
|
||||
pf_u32 split_size) {
|
||||
PF_STR destination_directory;
|
||||
PF_STR destination_filename;
|
||||
PFDIR_STR destination_filename;
|
||||
PFDIR_STR destination_directory;
|
||||
PF_DIR_ENT source_entry;
|
||||
PF_DIR_ENT source_entry_copy;
|
||||
PF_DIR_ENT destination_entry;
|
||||
PF_DIR_ENT source_entry_copy;
|
||||
PFFILE_ENT_ITER source_iter;
|
||||
PFFILE_ENT_ITER destination_iter;
|
||||
PFFILE_ENT_ITER destination_file_iter;
|
||||
PFFILE_FFD source_ffd;
|
||||
PFFILE_FFD destination_ffd;
|
||||
PF_FAT_HINT source_hint;
|
||||
PF_FAT_HINT destination_hint;
|
||||
PFFILE_FAT_HINT source_hint;
|
||||
PFFILE_FAT_HINT destination_hint;
|
||||
pf_s8 normalized_filename[0x200];
|
||||
pf_u32 original_start_cluster;
|
||||
pf_u32 original_size;
|
||||
pf_u32 index;
|
||||
pf_u16 current_time;
|
||||
pf_u32 original_start_cluster;
|
||||
pf_s32 namelength;
|
||||
pf_s32 error;
|
||||
|
||||
error = PFENT_ITER_GetEntryOfPath(&source_iter, &source_entry, volume, source_path, 0);
|
||||
@@ -1233,16 +1214,8 @@ pf_s32 PFFILE_p_divide(PF_VOLUME* volume, PF_STR* source_path, PF_STR* destinati
|
||||
if ((source_entry.attr & 1) != 0) {
|
||||
return 0x18;
|
||||
}
|
||||
for (index = 0; index < 5; index++) {
|
||||
if ((((PFFILE_VOLUME_DIRS*)source_entry.p_vol)->sfds[index].stat & 3) == 3 &&
|
||||
source_entry.p_vol ==
|
||||
((PFFILE_VOLUME_DIRS*)source_entry.p_vol)->sfds[index].dir_entry.p_vol &&
|
||||
source_entry.entry_sector ==
|
||||
((PFFILE_VOLUME_DIRS*)source_entry.p_vol)->sfds[index].dir_entry.entry_sector &&
|
||||
source_entry.entry_offset ==
|
||||
((PFFILE_VOLUME_DIRS*)source_entry.p_vol)->sfds[index].dir_entry.entry_offset) {
|
||||
return 0x13;
|
||||
}
|
||||
if (PFFILE_IsOpened(&source_entry)) {
|
||||
return 0x13;
|
||||
}
|
||||
if (source_entry.file_size == 0) {
|
||||
return 0xA;
|
||||
@@ -1255,7 +1228,8 @@ pf_s32 PFFILE_p_divide(PF_VOLUME* volume, PF_STR* source_path, PF_STR* destinati
|
||||
return 1;
|
||||
}
|
||||
if (PFSTR_GetCodeMode(&destination_filename) == 2) {
|
||||
if ((PFSTR_StrNumChar(&destination_filename, 1) & 0xFFFF) > 0xFF) {
|
||||
namelength = PFSTR_StrNumChar(&destination_filename, 1);
|
||||
if (namelength > 0xFF) {
|
||||
return 1;
|
||||
}
|
||||
PFPATH_transformFromUnicodeToNormal(
|
||||
@@ -1274,13 +1248,14 @@ pf_s32 PFFILE_p_divide(PF_VOLUME* volume, PF_STR* source_path, PF_STR* destinati
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
PFFAT_InitHint(&destination_hint);
|
||||
PFFAT_InitFFD(&destination_ffd, &destination_hint, volume, &destination_entry.start_cluster);
|
||||
PFFAT_InitHint(&source_hint);
|
||||
PFFAT_InitFFD(&source_ffd, &source_hint, volume, &source_entry.start_cluster);
|
||||
PFFAT_InitFFD(&source_iter.ffd, &source_hint, volume, &source_entry.start_cluster);
|
||||
PFFAT_InitHint(&destination_hint);
|
||||
PFFAT_InitFFD(&destination_iter.ffd, &destination_hint, volume,
|
||||
&destination_entry.start_cluster);
|
||||
pf_memcpy(&source_entry_copy, &source_entry, sizeof(source_entry_copy));
|
||||
original_start_cluster = source_entry.start_cluster;
|
||||
original_size = source_entry.file_size;
|
||||
original_start_cluster = source_entry.start_cluster;
|
||||
PFENT_getcurrentDateTimeForEnt(&source_entry.modify_date, &source_entry.modify_time);
|
||||
source_entry.access_date = source_entry.modify_date;
|
||||
if (split_size == 0) {
|
||||
@@ -1288,35 +1263,36 @@ pf_s32 PFFILE_p_divide(PF_VOLUME* volume, PF_STR* source_path, PF_STR* destinati
|
||||
}
|
||||
source_entry.file_size = split_size;
|
||||
error = PFENT_updateEntry(&source_entry, 1);
|
||||
if (error == 0 &&
|
||||
((((PFFILE_VOLUME_DIRS*)volume)->cache_control & 4) == 0 ||
|
||||
PFCACHE_FlushDataCacheSpecific(volume, 0) == 0)) {
|
||||
error = PFCLUSTER_DivideFile(&source_iter, &destination_iter, &source_entry_copy,
|
||||
&destination_entry, split_size);
|
||||
if (error == 0) {
|
||||
destination_entry.create_time = source_entry.modify_time;
|
||||
destination_entry.create_date = source_entry.modify_date;
|
||||
destination_entry.modify_time = source_entry.modify_time;
|
||||
destination_entry.modify_date = source_entry.modify_date;
|
||||
destination_entry.access_date = source_entry.access_date;
|
||||
destination_entry.attr = source_entry.attr;
|
||||
error = PFENT_updateEntry(&destination_entry, 1);
|
||||
return error & (-error | error) >> 31;
|
||||
}
|
||||
PFCACHE_FlushFATCache(volume);
|
||||
source_entry.start_cluster = original_start_cluster;
|
||||
source_entry.file_size = original_size;
|
||||
PFENT_updateEntry(&source_entry, 1);
|
||||
error = PFENT_ITER_GetEntryOfPath(&destination_file_iter, &destination_entry, volume,
|
||||
destination_path, 0);
|
||||
if (error == 0) {
|
||||
PFENT_RemoveEntry(&destination_entry, &destination_file_iter);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if ((((PFFILE_VOLUME_DIRS*)volume)->cache_control & 4) != 0) {
|
||||
error = PFCACHE_FlushDataCacheSpecific(volume, 0);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
return error;
|
||||
error = PFCLUSTER_DivideFile(&source_iter, &destination_iter, &source_entry_copy,
|
||||
&destination_entry, split_size);
|
||||
if (error != 0) {
|
||||
PFCACHE_FlushFATCache(volume);
|
||||
source_entry.file_size = original_size;
|
||||
source_entry.start_cluster = original_start_cluster;
|
||||
PFENT_updateEntry(&source_entry, 1);
|
||||
PFENT_ITER_GetEntryOfPath(&destination_iter, &destination_entry, volume,
|
||||
destination_path, 0);
|
||||
PFENT_RemoveEntry(&destination_entry, &destination_iter);
|
||||
return error;
|
||||
}
|
||||
destination_entry.modify_date = source_entry.modify_date;
|
||||
destination_entry.modify_time = source_entry.modify_time;
|
||||
destination_entry.access_date = source_entry.access_date;
|
||||
destination_entry.attr = source_entry.attr;
|
||||
error = PFENT_updateEntry(&destination_entry, 1);
|
||||
return error & (-error | error) >> 31;
|
||||
}
|
||||
|
||||
pf_s32 PFFILE_p_cinsert(PF_VOLUME* volume, PF_STR* path, pf_u32 cluster_index,
|
||||
pf_s32 PFFILE_p_cinsert(PF_VOLUME* volume, PFDIR_STR* path, pf_u32 cluster_index,
|
||||
pf_u32 count, pf_u32 mode) {
|
||||
PFFILE_ENT_ITER iter;
|
||||
PF_DIR_ENT entry;
|
||||
@@ -1360,7 +1336,7 @@ pf_s32 PFFILE_p_cinsert(PF_VOLUME* volume, PF_STR* path, pf_u32 cluster_index,
|
||||
return error & (-error | error) >> 31;
|
||||
}
|
||||
|
||||
pf_s32 PFFILE_p_cdelete(PF_VOLUME* volume, PF_STR* path, pf_u32 cluster_index,
|
||||
pf_s32 PFFILE_p_cdelete(PF_VOLUME* volume, PFDIR_STR* path, pf_u32 cluster_index,
|
||||
pf_u32 count, pf_u32 mode) {
|
||||
PFFILE_ENT_ITER iter;
|
||||
PF_DIR_ENT entry;
|
||||
@@ -1403,20 +1379,22 @@ pf_s32 PFFILE_p_cdelete(PF_VOLUME* volume, PF_STR* path, pf_u32 cluster_index,
|
||||
|
||||
pf_s32 PFFILE_p_flock(PFFILE_FILE* file, pf_u32 mode) {
|
||||
if ((mode & 3) != 0) {
|
||||
if ((file->p_sfd->lock.mode & 3) != 0 && (mode & 0x10) != 0) {
|
||||
if ((file->p_sfd->lock.mode & 3) != 0 && (mode & 8) != 0) {
|
||||
if ((mode & 1) != 0) {
|
||||
if ((file->p_sfd->lock.mode & 2) != 0) {
|
||||
return 0x27;
|
||||
goto lock_error;
|
||||
}
|
||||
} else if ((mode & 2) != 0 && (file->p_sfd->lock.mode & 1) != 0) {
|
||||
return 0x27;
|
||||
}
|
||||
if ((mode & 2) != 0 && (file->p_sfd->lock.mode & 1) != 0) {
|
||||
goto lock_error;
|
||||
}
|
||||
if (file->p_sfd->lock.owner != 0 && file->p_sfd->lock.owner != (PF_FILE*)file) {
|
||||
lock_error:
|
||||
return 0x27;
|
||||
}
|
||||
}
|
||||
if ((mode & 1) != 0) {
|
||||
if (file->p_sfd->lock.count == 0 || (file->p_sfd->lock.mode & 2) == 0) {
|
||||
if (file->p_sfd->lock.count == 0 || (file->p_sfd->lock.mode & 2) != 0) {
|
||||
file->p_sfd->lock.wcount++;
|
||||
PF_LockFile((PF_FILE*)file, 0);
|
||||
file->p_sfd->lock.wcount--;
|
||||
@@ -1432,30 +1410,22 @@ pf_s32 PFFILE_p_flock(PFFILE_FILE* file, pf_u32 mode) {
|
||||
}
|
||||
file->p_sfd->lock.count++;
|
||||
file->lock_count++;
|
||||
return 0;
|
||||
}
|
||||
if (file->lock_count == 0 || file->p_sfd->lock.count == 0) {
|
||||
return 0x27;
|
||||
}
|
||||
if ((file->p_sfd->lock.mode & 2) != 0 && file->p_sfd->lock.owner != (PF_FILE*)file) {
|
||||
return 0x27;
|
||||
}
|
||||
if ((file->p_sfd->lock.mode & 1) != 0) {
|
||||
file->p_sfd->lock.count -= file->lock_count;
|
||||
file->lock_count = 0;
|
||||
if (file->p_sfd->lock.count == 0) {
|
||||
PF_UnLockFile((PF_FILE*)file);
|
||||
}
|
||||
file->p_sfd->lock.mode &= ~3;
|
||||
} else {
|
||||
if (file->p_sfd->lock.owner != (PF_FILE*)file) {
|
||||
if (file->lock_count == 0 || file->p_sfd->lock.count == 0) {
|
||||
return 0x27;
|
||||
}
|
||||
file->p_sfd->lock.count = 0;
|
||||
file->lock_count = 0;
|
||||
file->p_sfd->lock.owner = 0;
|
||||
PF_UnLockFile((PF_FILE*)file);
|
||||
file->p_sfd->lock.mode &= ~3;
|
||||
if ((file->p_sfd->lock.mode & 2) != 0 && file->p_sfd->lock.owner != (PF_FILE*)file) {
|
||||
return 0x27;
|
||||
}
|
||||
file->lock_count--;
|
||||
file->p_sfd->lock.count--;
|
||||
if (file->p_sfd->lock.count == 0) {
|
||||
PF_UnLockFile((PF_FILE*)file);
|
||||
if ((file->p_sfd->lock.mode & 2) != 0) {
|
||||
file->p_sfd->lock.owner = 0;
|
||||
}
|
||||
file->p_sfd->lock.mode &= ~3;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1503,7 +1473,7 @@ pf_s32 PFFILE_FsexecOpenFile(PF_DIR_ENT* entry, PFFILE_ENT_ITER* iter,
|
||||
} else {
|
||||
PFENT_getcurrentDateTimeForEnt(&entry->access_date, &access_time);
|
||||
}
|
||||
sfd = PFFILE_GetSFD(volume, entry);
|
||||
sfd = PFFILE_GetSFD((PFFILE_VOLUME_DIRS*)volume, entry);
|
||||
if (sfd == PF_NULL) {
|
||||
return 0x15;
|
||||
}
|
||||
@@ -1563,7 +1533,7 @@ void PFFILE_FinalizeAllFiles(PF_VOLUME* volume) {
|
||||
volume_dirs->num_opened_files = 0;
|
||||
}
|
||||
|
||||
pf_s32 PFFILE_remove(PF_STR* path) {
|
||||
pf_s32 PFFILE_remove(PFDIR_STR* path) {
|
||||
PF_VOLUME* volume;
|
||||
pf_s32 error;
|
||||
|
||||
@@ -1607,7 +1577,7 @@ pf_s32 PFFILE_ferror(PFFILE_FILE* file) {
|
||||
return file->last_access_data.state.last_error;
|
||||
}
|
||||
|
||||
pf_s32 PFFILE_fopen(PF_STR* path, pf_s32 mode, PFFILE_FILE** result) {
|
||||
pf_s32 PFFILE_fopen(PFDIR_STR* path, pf_s32 mode, PFFILE_FILE** result) {
|
||||
PF_VOLUME* volume;
|
||||
pf_s32 error;
|
||||
|
||||
@@ -1708,10 +1678,12 @@ close_file_complete:
|
||||
|
||||
pf_s32 PFFILE_fread(pf_u8* buffer, pf_u32 size, pf_u32 count,
|
||||
PFFILE_FILE* file, pf_u32* count_read) {
|
||||
PF_VOLUME* volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol;
|
||||
PF_VOLUME* volume;
|
||||
pf_u32 bytes_read;
|
||||
pf_s32 error;
|
||||
|
||||
*count_read = 0;
|
||||
volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol;
|
||||
error = PFVOL_CheckForRead(volume);
|
||||
if (error != 0) {
|
||||
pf_vol_set.last_error = error;
|
||||
@@ -1724,7 +1696,8 @@ pf_s32 PFFILE_fread(pf_u8* buffer, pf_u32 size, pf_u32 count,
|
||||
return 0x26;
|
||||
}
|
||||
((PFFILE_VOLUME_DIRS*)volume)->cache_signature = file;
|
||||
error = PFFILE_p_fread(volume, buffer, size, count, file, count_read);
|
||||
error = PFFILE_p_fread(volume, buffer, size, count, file, &bytes_read);
|
||||
*count_read = bytes_read;
|
||||
((PFFILE_VOLUME_DIRS*)volume)->cache_signature = PF_NULL;
|
||||
if (error != 0) {
|
||||
pf_vol_set.last_error = error;
|
||||
@@ -1869,8 +1842,8 @@ pf_s32 PFFILE_fsetclstlink(PFFILE_FILE* file, pf_u32 mode,
|
||||
file->p_sfd->ffd.cluster_link.interval_offset = 0;
|
||||
file->p_sfd->ffd.cluster_link.position = 0;
|
||||
file->p_sfd->ffd.cluster_link.save_index = 0;
|
||||
if (file->p_sfd->dir_entry.file_size != 0 && settings->link_max != 0) {
|
||||
settings->buffer[0] = *file->p_sfd->ffd.p_start_cluster;
|
||||
if (file->p_sfd->dir_entry.file_size != 0 && file->p_sfd->ffd.cluster_link.max_count != 0) {
|
||||
file->p_sfd->ffd.cluster_link.buffer[0] = *file->p_sfd->ffd.p_start_cluster;
|
||||
file->p_sfd->ffd.cluster_link.position++;
|
||||
}
|
||||
if (file->p_sfd->ffd.p_hint != PF_NULL) {
|
||||
@@ -2051,7 +2024,7 @@ pf_s32 PFFILE_finfo(PFFILE_FILE* file, PF_INFO* info) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFFILE_combine(PF_STR* first_path, PF_STR* second_path) {
|
||||
pf_s32 PFFILE_combine(PFDIR_STR* first_path, PFDIR_STR* second_path) {
|
||||
PF_VOLUME* volume = PFPATH_GetVolumeFromPath(first_path);
|
||||
PF_VOLUME* second_volume = PFPATH_GetVolumeFromPath(second_path);
|
||||
pf_s32 error;
|
||||
@@ -2088,7 +2061,7 @@ pf_s32 PFFILE_combine(PF_STR* first_path, PF_STR* second_path) {
|
||||
return error;
|
||||
}
|
||||
|
||||
pf_s32 PFFILE_divide(PF_STR* source_path, PF_STR* destination_path, pf_u32 split_size) {
|
||||
pf_s32 PFFILE_divide(PFDIR_STR* source_path, PFDIR_STR* destination_path, pf_u32 split_size) {
|
||||
PF_VOLUME* volume = PFPATH_GetVolumeFromPath(source_path);
|
||||
PF_VOLUME* destination_volume = PFPATH_GetVolumeFromPath(destination_path);
|
||||
pf_s32 error;
|
||||
@@ -2125,7 +2098,7 @@ pf_s32 PFFILE_divide(PF_STR* source_path, PF_STR* destination_path, pf_u32 split
|
||||
return error;
|
||||
}
|
||||
|
||||
pf_s32 PFFILE_cinsert(PF_STR* path, pf_u32 cluster_index, pf_u32 count,
|
||||
pf_s32 PFFILE_cinsert(PFDIR_STR* path, pf_u32 cluster_index, pf_u32 count,
|
||||
pf_u32* cluster_result) {
|
||||
PF_VOLUME* volume;
|
||||
pf_s32 error;
|
||||
@@ -2160,7 +2133,7 @@ pf_s32 PFFILE_cinsert(PF_STR* path, pf_u32 cluster_index, pf_u32 count,
|
||||
return error;
|
||||
}
|
||||
|
||||
pf_s32 PFFILE_cdelete(PF_STR* path, pf_u32 cluster_index, pf_u32 count,
|
||||
pf_s32 PFFILE_cdelete(PFDIR_STR* path, pf_u32 cluster_index, pf_u32 count,
|
||||
pf_u32* cluster_result) {
|
||||
PF_VOLUME* volume;
|
||||
pf_s32 error;
|
||||
@@ -2218,24 +2191,3 @@ pf_s32 PFFILE_flock(PFFILE_FILE* file, pf_u32 mode) {
|
||||
return error;
|
||||
}
|
||||
|
||||
pf_s32 PFFILE_p_fread(PF_VOLUME* volume, pf_u8* buffer, pf_u32 size, pf_u32 count,
|
||||
PFFILE_FILE* file, pf_u32* count_read) {
|
||||
pf_u32 bytes_read = 0;
|
||||
pf_s32 error;
|
||||
|
||||
*count_read = 0;
|
||||
if ((file->open_mode & 8) == 0 &&
|
||||
((file->open_mode & 1) != 0 || (file->open_mode & 4) != 0)) {
|
||||
return 0xA;
|
||||
}
|
||||
if ((file->p_sfd->lock.mode & 3) != 0 && file->lock_count == 0) {
|
||||
return 0x19;
|
||||
}
|
||||
if (file->cursor.position >= file->p_sfd->dir_entry.file_size) {
|
||||
return 0x1C;
|
||||
}
|
||||
error = PFFILE_Cursor_Read(file, buffer, size * count, &bytes_read);
|
||||
*count_read = bytes_read / size;
|
||||
error &= (-error | error) >> 31;
|
||||
return error;
|
||||
}
|
||||
|
||||
56
libs/RVL_SDK/src/fa/pf_filelock.c
Normal file
56
libs/RVL_SDK/src/fa/pf_filelock.c
Normal file
@@ -0,0 +1,56 @@
|
||||
#include <private/fa/pf_system.h>
|
||||
#include <private/vf/PrFILE2/fatfs/pf_entry.h>
|
||||
|
||||
typedef struct PFFILELOCK_SFD {
|
||||
pf_u8 descriptor[0x3c];
|
||||
PF_DIR_ENT dir_entry;
|
||||
pf_u16 lock_mode;
|
||||
pf_u16 lock_count;
|
||||
pf_u32 writer_count;
|
||||
void* owner;
|
||||
pf_s32 resource;
|
||||
OSSemaphore semaphore;
|
||||
} PFFILELOCK_SFD;
|
||||
typedef struct PFFILELOCK_FILE {
|
||||
pf_u32 stat;
|
||||
pf_u32 open_mode;
|
||||
PFFILELOCK_SFD* p_sfd;
|
||||
} PFFILELOCK_FILE;
|
||||
typedef struct PFFILELOCK_SEMAPHORE_PARAM {
|
||||
pf_u32 initial_count;
|
||||
pf_u32 max_count;
|
||||
OSSemaphore* semaphore;
|
||||
} PFFILELOCK_SEMAPHORE_PARAM;
|
||||
extern pf_s32 pfk_create_semaphore(PFFILELOCK_SEMAPHORE_PARAM*);
|
||||
extern pf_s32 pfk_get_semaphore(pf_s32);
|
||||
extern pf_s32 pfk_release_semaphore(pf_s32);
|
||||
extern pf_s32 pfk_delete_semaphore(pf_s32);
|
||||
|
||||
void PF_InitLockFile(void) {
|
||||
pf_sys_set.flock_count = 0;
|
||||
}
|
||||
pf_s32 PF_LockFile(PFFILELOCK_FILE* p_file) {
|
||||
pf_s32 result = -1;
|
||||
PFFILELOCK_SEMAPHORE_PARAM param;
|
||||
if (p_file->p_sfd->lock_count == 0 && p_file->p_sfd->resource == 0) {
|
||||
if (pf_sys_set.flock_count < -1U) {
|
||||
param.initial_count = 1;
|
||||
param.max_count = 1;
|
||||
param.semaphore = &p_file->p_sfd->semaphore;
|
||||
p_file->p_sfd->resource = pfk_create_semaphore(¶m);
|
||||
result = 0;
|
||||
++pf_sys_set.flock_count;
|
||||
} else result = -1;
|
||||
}
|
||||
pfk_get_semaphore(p_file->p_sfd->resource);
|
||||
return result;
|
||||
}
|
||||
pf_s32 PF_UnLockFile(PFFILELOCK_FILE* p_file) {
|
||||
pfk_release_semaphore(p_file->p_sfd->resource);
|
||||
if (p_file->p_sfd->lock_count == 0 && p_file->p_sfd->writer_count == 0 && pf_sys_set.flock_count != 0) {
|
||||
pfk_delete_semaphore(p_file->p_sfd->resource);
|
||||
p_file->p_sfd->resource = 0;
|
||||
--pf_sys_set.flock_count;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
13
libs/RVL_SDK/src/fa/pf_finfo.c
Normal file
13
libs/RVL_SDK/src/fa/pf_finfo.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#define PF_FA_STR_LAYOUT
|
||||
#define VFiPFAPI_convertReturnValue PFAPI_convertReturnValue
|
||||
#define VFiPFFILE_finfo PFFILE_finfo
|
||||
#include <private/vf/PrFILE2/standard/pf_finfo.h>
|
||||
|
||||
#include <private/vf/PrFILE2/fatfs/pf_volume.h>
|
||||
#include <private/vf/PrFILE2/standard/pf_api_util.h>
|
||||
|
||||
pf_int32 pf2_finfo(PF_FILE* p_file, PF_INFO* p_info) {
|
||||
pf_s32 err = VFiPFFILE_finfo(p_file, p_info);
|
||||
err = VFiPFAPI_convertReturnValue(err);
|
||||
return err;
|
||||
}
|
||||
41
libs/RVL_SDK/src/fa/pf_fopen.c
Normal file
41
libs/RVL_SDK/src/fa/pf_fopen.c
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <revolution/fa.h>
|
||||
|
||||
typedef struct PFF2_STR {
|
||||
const s8* p_head;
|
||||
const s8* p_tail;
|
||||
const s8* p_current;
|
||||
u32 code_mode;
|
||||
} PFF2_STR;
|
||||
|
||||
typedef struct PFF2_VOL_SET {
|
||||
u8 reserved[0x40];
|
||||
s32 last_error;
|
||||
} PFF2_VOL_SET;
|
||||
|
||||
extern PFF2_VOL_SET pf_vol_set;
|
||||
extern s32 PFAPI_ParseOpenModeString(const char* mode_str);
|
||||
extern s32 PFSTR_InitStr(PFF2_STR* path, const s8* text, u32 code_mode);
|
||||
extern s32 PFFILE_fopen(PFF2_STR* path, s32 mode, FAFILE** result);
|
||||
extern FAFILE* PFAPI_convertReturnValue2NULL(s32 err, FAFILE* p_stream);
|
||||
|
||||
FAFILE* pf2_fopen(const char* path, const char* mode) {
|
||||
u32 open_mode;
|
||||
FAFILE* p_file;
|
||||
PFF2_STR path_str;
|
||||
s32 err;
|
||||
|
||||
open_mode = PFAPI_ParseOpenModeString(mode);
|
||||
if (open_mode == 0) {
|
||||
pf_vol_set.last_error = 10;
|
||||
p_file = NULL;
|
||||
} else {
|
||||
err = PFSTR_InitStr(&path_str, (const s8*)path, 1);
|
||||
if (err == 0) {
|
||||
err = PFFILE_fopen(&path_str, open_mode, &p_file);
|
||||
} else {
|
||||
pf_vol_set.last_error = err;
|
||||
}
|
||||
p_file = PFAPI_convertReturnValue2NULL(err, p_file);
|
||||
}
|
||||
return p_file;
|
||||
}
|
||||
13
libs/RVL_SDK/src/fa/pf_format.c
Normal file
13
libs/RVL_SDK/src/fa/pf_format.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#define PF_FA_STR_LAYOUT
|
||||
#define VFiPFAPI_convertReturnValue PFAPI_convertReturnValue
|
||||
#define VFiPFVOL_format PFVOL_format
|
||||
#include <private/vf/PrFILE2/standard/pf_format.h>
|
||||
|
||||
#include <private/vf/PrFILE2/fatfs/pf_volume.h>
|
||||
#include <private/vf/PrFILE2/standard/pf_api_util.h>
|
||||
|
||||
pf_int32 pf2_format(pf_ch8 drive, const pf_ch8* param) {
|
||||
pf_s32 err = VFiPFVOL_format(drive, (pf_u8*)param);
|
||||
err = VFiPFAPI_convertReturnValue(err);
|
||||
return err;
|
||||
}
|
||||
10
libs/RVL_SDK/src/fa/pf_fseek.c
Normal file
10
libs/RVL_SDK/src/fa/pf_fseek.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <revolution/fa.h>
|
||||
|
||||
extern s32 PFFILE_fseek(FAFILE* stream, s32 offset, int origin);
|
||||
extern s32 PFAPI_convertReturnValue(s32 err);
|
||||
|
||||
FAError pf2_fseek(FAFILE* stream, s32 offset, int origin) {
|
||||
s32 err = PFFILE_fseek(stream, offset, origin);
|
||||
err = PFAPI_convertReturnValue(err);
|
||||
return err;
|
||||
}
|
||||
32
libs/RVL_SDK/src/fa/pf_fsfirst.c
Normal file
32
libs/RVL_SDK/src/fa/pf_fsfirst.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <revolution/fa.h>
|
||||
|
||||
typedef struct PFF2_STR {
|
||||
const s8* p_head;
|
||||
const s8* p_tail;
|
||||
const s8* p_current;
|
||||
u32 code_mode;
|
||||
} PFF2_STR;
|
||||
|
||||
typedef struct PFF2_VOL_SET {
|
||||
u8 reserved[0x40];
|
||||
s32 last_error;
|
||||
} PFF2_VOL_SET;
|
||||
|
||||
extern PFF2_VOL_SET pf_vol_set;
|
||||
extern s32 PFSTR_InitStr(PFF2_STR* path, const s8* text, u32 code_mode);
|
||||
extern s32 PFDIR_fsfirst(PFF2_STR* path, u8 attributes, FADta* data);
|
||||
extern s32 PFAPI_convertReturnValue(s32 err);
|
||||
|
||||
FAError pf2_fsfirst(const char* dirName, u8 attr, FADta* dta) {
|
||||
s32 err;
|
||||
PFF2_STR path_str;
|
||||
|
||||
err = PFSTR_InitStr(&path_str, (const s8*)dirName, 1);
|
||||
if (err == 0) {
|
||||
err = PFDIR_fsfirst(&path_str, attr, dta);
|
||||
} else {
|
||||
pf_vol_set.last_error = err;
|
||||
}
|
||||
err = PFAPI_convertReturnValue(err);
|
||||
return err;
|
||||
}
|
||||
10
libs/RVL_SDK/src/fa/pf_fsnext.c
Normal file
10
libs/RVL_SDK/src/fa/pf_fsnext.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <revolution/fa.h>
|
||||
|
||||
extern s32 PFDIR_fsnext(FADta* data);
|
||||
extern s32 PFAPI_convertReturnValue(s32 err);
|
||||
|
||||
FAError pf2_fsnext(FADta* dta) {
|
||||
s32 err = PFDIR_fsnext(dta);
|
||||
err = PFAPI_convertReturnValue(err);
|
||||
return err;
|
||||
}
|
||||
32
libs/RVL_SDK/src/fa/pf_fstat.c
Normal file
32
libs/RVL_SDK/src/fa/pf_fstat.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <revolution/fa.h>
|
||||
|
||||
typedef struct PFF2_STR {
|
||||
const s8* p_head;
|
||||
const s8* p_tail;
|
||||
const s8* p_current;
|
||||
u32 code_mode;
|
||||
} PFF2_STR;
|
||||
|
||||
typedef struct PFF2_VOL_SET {
|
||||
u8 reserved[0x40];
|
||||
s32 last_error;
|
||||
} PFF2_VOL_SET;
|
||||
|
||||
extern PFF2_VOL_SET pf_vol_set;
|
||||
extern s32 PFSTR_InitStr(PFF2_STR* path, const s8* text, u32 code_mode);
|
||||
extern s32 PFDIR_fstat(PFF2_STR* path, FAFileStat* file_stat);
|
||||
extern s32 PFAPI_convertReturnValue(s32 err);
|
||||
|
||||
FAError pf2_fstat(const char* fileName, FAFileStat* stat) {
|
||||
s32 err;
|
||||
PFF2_STR path_str;
|
||||
|
||||
err = PFSTR_InitStr(&path_str, (const s8*)fileName, 1);
|
||||
if (err == 0) {
|
||||
err = PFDIR_fstat(&path_str, stat);
|
||||
} else {
|
||||
pf_vol_set.last_error = err;
|
||||
}
|
||||
err = PFAPI_convertReturnValue(err);
|
||||
return err;
|
||||
}
|
||||
13
libs/RVL_SDK/src/fa/pf_getdev.c
Normal file
13
libs/RVL_SDK/src/fa/pf_getdev.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#define PF_FA_STR_LAYOUT
|
||||
#define VFiPFAPI_convertReturnValue PFAPI_convertReturnValue
|
||||
#define VFiPFVOL_getdev PFVOL_getdev
|
||||
#include <private/vf/PrFILE2/standard/pf_getdev.h>
|
||||
|
||||
#include <private/vf/PrFILE2/fatfs/pf_volume.h>
|
||||
#include <private/vf/PrFILE2/standard/pf_api_util.h>
|
||||
|
||||
pf_int32 pf2_devinf(pf_ch8 drv_char, PF_DEV_INF* dev_inf) {
|
||||
pf_s32 err = VFiPFVOL_getdev(drv_char, dev_inf);
|
||||
err = VFiPFAPI_convertReturnValue(err);
|
||||
return err;
|
||||
}
|
||||
19
libs/RVL_SDK/src/fa/pf_init_prfile2.c
Normal file
19
libs/RVL_SDK/src/fa/pf_init_prfile2.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#define PF_FA_STR_LAYOUT
|
||||
#define VFiPFAPI_convertReturnValue PFAPI_convertReturnValue
|
||||
#define VFiPFFATFS_initializeFATFS PFFATFS_initializeFATFS
|
||||
#define VFiPFSYS_initializeSYS PFSYS_initializeSYS
|
||||
#include <private/vf/PrFILE2/standard/pf_init_prfile2.h>
|
||||
|
||||
#include <private/vf/PrFILE2/fatfs/pf_fatfs.h>
|
||||
#include <private/vf/PrFILE2/standard/pf_api_util.h>
|
||||
#include <private/vf/PrFILE2/system/pf_system.h>
|
||||
|
||||
|
||||
pf_int32 pf2_init_prfile2(pf_s32 config, void* param) {
|
||||
pf_s32 err = VFiPFFATFS_initializeFATFS(config, param);
|
||||
if (err == 0) {
|
||||
VFiPFSYS_initializeSYS();
|
||||
}
|
||||
err = VFiPFAPI_convertReturnValue(err);
|
||||
return err;
|
||||
}
|
||||
31
libs/RVL_SDK/src/fa/pf_mkdir.c
Normal file
31
libs/RVL_SDK/src/fa/pf_mkdir.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#define PF_FA_STR_LAYOUT
|
||||
#define VFiPFAPI_convertReturnValue PFAPI_convertReturnValue
|
||||
#define VFiPFDIR_mkdir PFDIR_mkdir
|
||||
#define VFiPFSTR_InitStr PFSTR_InitStr
|
||||
#include <private/vf/PrFILE2/standard/pf_mkdir.h>
|
||||
|
||||
typedef struct PFAPI_GLOBAL_STATE {
|
||||
pf_u8 volume_state[0x40];
|
||||
pf_s32 last_error;
|
||||
} PFAPI_GLOBAL_STATE;
|
||||
extern PFAPI_GLOBAL_STATE pf_vol_set;
|
||||
|
||||
|
||||
#include <private/vf/PrFILE2/fatfs/pf_dir.h>
|
||||
#include <private/vf/PrFILE2/standard/pf_api_util.h>
|
||||
|
||||
#include <private/vf/PrFILE2/common/pf_str.h>
|
||||
|
||||
pf_int32 pf2_mkdir(const pf_ch8* sPath) {
|
||||
pf_s32 err;
|
||||
PF_STR path_str;
|
||||
|
||||
err = VFiPFSTR_InitStr(&path_str, (pf_s8*)sPath, 1U);
|
||||
if (err == 0) {
|
||||
err = VFiPFDIR_mkdir(&path_str);
|
||||
} else {
|
||||
pf_vol_set.last_error = err;
|
||||
}
|
||||
err = VFiPFAPI_convertReturnValue(err);
|
||||
return err;
|
||||
}
|
||||
31
libs/RVL_SDK/src/fa/pf_remove.c
Normal file
31
libs/RVL_SDK/src/fa/pf_remove.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#define PF_FA_STR_LAYOUT
|
||||
#define VFiPFAPI_convertReturnValue PFAPI_convertReturnValue
|
||||
#define VFiPFFILE_remove PFFILE_remove
|
||||
#define VFiPFSTR_InitStr PFSTR_InitStr
|
||||
#include <private/vf/PrFILE2/standard/pf_remove.h>
|
||||
|
||||
typedef struct PFAPI_GLOBAL_STATE {
|
||||
pf_u8 volume_state[0x40];
|
||||
pf_s32 last_error;
|
||||
} PFAPI_GLOBAL_STATE;
|
||||
extern PFAPI_GLOBAL_STATE pf_vol_set;
|
||||
|
||||
|
||||
#include <private/vf/PrFILE2/fatfs/pf_file.h>
|
||||
#include <private/vf/PrFILE2/standard/pf_api_util.h>
|
||||
|
||||
#include <private/vf/PrFILE2/common/pf_str.h>
|
||||
|
||||
pf_int32 pf2_remove(const pf_ch8* path) {
|
||||
pf_s32 err;
|
||||
PF_STR path_str;
|
||||
|
||||
err = VFiPFSTR_InitStr(&path_str, (pf_s8*)path, 1U);
|
||||
if (err == 0) {
|
||||
err = VFiPFFILE_remove(&path_str);
|
||||
} else {
|
||||
pf_vol_set.last_error = err;
|
||||
}
|
||||
err = VFiPFAPI_convertReturnValue(err);
|
||||
return err;
|
||||
}
|
||||
31
libs/RVL_SDK/src/fa/pf_rmdir.c
Normal file
31
libs/RVL_SDK/src/fa/pf_rmdir.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#define PF_FA_STR_LAYOUT
|
||||
#define VFiPFAPI_convertReturnValue PFAPI_convertReturnValue
|
||||
#define VFiPFDIR_rmdir PFDIR_rmdir
|
||||
#define VFiPFSTR_InitStr PFSTR_InitStr
|
||||
#include <private/vf/PrFILE2/standard/pf_rmdir.h>
|
||||
|
||||
typedef struct PFAPI_GLOBAL_STATE {
|
||||
pf_u8 volume_state[0x40];
|
||||
pf_s32 last_error;
|
||||
} PFAPI_GLOBAL_STATE;
|
||||
extern PFAPI_GLOBAL_STATE pf_vol_set;
|
||||
|
||||
|
||||
#include <private/vf/PrFILE2/fatfs/pf_dir.h>
|
||||
#include <private/vf/PrFILE2/standard/pf_api_util.h>
|
||||
|
||||
#include <private/vf/PrFILE2/common/pf_str.h>
|
||||
|
||||
pf_int32 pf2_rmdir(const pf_ch8* sPath) {
|
||||
pf_s32 err;
|
||||
PF_STR path_str;
|
||||
|
||||
err = VFiPFSTR_InitStr(&path_str, (pf_s8*)sPath, 1U);
|
||||
if (err == 0) {
|
||||
err = VFiPFDIR_rmdir(&path_str);
|
||||
} else {
|
||||
pf_vol_set.last_error = err;
|
||||
}
|
||||
err = VFiPFAPI_convertReturnValue(err);
|
||||
return err;
|
||||
}
|
||||
216
libs/RVL_SDK/src/fa/pf_sector.c
Normal file
216
libs/RVL_SDK/src/fa/pf_sector.c
Normal file
@@ -0,0 +1,216 @@
|
||||
#define PF_FA_STR_LAYOUT
|
||||
#define VFiPFCACHE_AllocateDataPage PFCACHE_AllocateDataPage
|
||||
#define VFiPFCACHE_ReadDataNumSector PFCACHE_ReadDataNumSector
|
||||
#define VFiPFCACHE_ReadDataPage PFCACHE_ReadDataPage
|
||||
#define VFiPFCACHE_ReadDataPageAndFlushIfNeeded PFCACHE_ReadDataPageAndFlushIfNeeded
|
||||
#define VFiPFCACHE_ReadFATPage PFCACHE_ReadFATPage
|
||||
#define VFiPFCACHE_SearchDataCache PFCACHE_SearchDataCache
|
||||
#define VFiPFCACHE_UpdateModifiedSector PFCACHE_UpdateModifiedSector
|
||||
#define VFiPFCACHE_WriteDataNumSectorAndFreeIfNeeded PFCACHE_WriteDataNumSectorAndFreeIfNeeded
|
||||
#define VFiPFCACHE_WriteDataPage PFCACHE_WriteDataPage
|
||||
#define VFiPFCACHE_WriteFATPage PFCACHE_WriteFATPage
|
||||
#define VFiPFDRV_IsInserted PFDRV_IsInserted
|
||||
#define VFiPFDRV_IsWProtected PFDRV_IsWProtected
|
||||
#define VFiPFSEC_ReadData PFSEC_ReadData
|
||||
#define VFiPFSEC_ReadDataSector PFSEC_ReadDataSector
|
||||
#define VFiPFSEC_ReadFAT PFSEC_ReadFAT
|
||||
#define VFiPFSEC_WriteData PFSEC_WriteData
|
||||
#define VFiPFSEC_WriteDataSector PFSEC_WriteDataSector
|
||||
#define VFiPFSEC_WriteFAT PFSEC_WriteFAT
|
||||
#define VFipf_memcpy pf_memcpy
|
||||
#include <private/fa/pf_volume.h>
|
||||
#include <private/vf/PrFILE2/fatfs/pf_cache.h>
|
||||
|
||||
|
||||
#include <private/vf/PrFILE2/common/pf_clib.h>
|
||||
#include <private/vf/PrFILE2/driver/pf_driver.h>
|
||||
#include <private/vf/PrFILE2/fatfs/pf_volume.h>
|
||||
|
||||
pf_s32 VFiPFSEC_ReadFAT(PF_VOLUME* p_vol, pf_u8* p_buf, pf_u32 sector, pf_u16 offset, pf_u16 size) {
|
||||
PF_CACHE_PAGE* p_page;
|
||||
pf_s32 err;
|
||||
|
||||
if ((p_vol->flags & 0x01) == 0 || VFiPFDRV_IsInserted(p_vol) == PF_FALSE) {
|
||||
return 9;
|
||||
}
|
||||
if (sector >= p_vol->bpb.total_sectors || offset >= p_vol->bpb.bytes_per_sector || offset + size > p_vol->bpb.bytes_per_sector) {
|
||||
return 10;
|
||||
}
|
||||
err = VFiPFCACHE_ReadFATPage(p_vol, sector, &p_page);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
VFipf_memcpy(p_buf, &p_page->p_buf[offset], size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 VFiPFSEC_ReadData(PF_VOLUME* p_vol, pf_u8* p_buf, pf_u32 sector, pf_u16 offset, pf_u32 size, pf_u32* p_success_size, pf_u32 set_sig) {
|
||||
PF_CACHE_PAGE* p_page;
|
||||
pf_u32 num_success;
|
||||
pf_u32 num_sector;
|
||||
pf_u32 adjust_sector;
|
||||
pf_u32 rest_sector;
|
||||
pf_s32 err;
|
||||
|
||||
*p_success_size = 0;
|
||||
if ((p_vol->flags & 0x01) == 0 || VFiPFDRV_IsInserted(p_vol) == PF_FALSE) {
|
||||
return 9;
|
||||
}
|
||||
if ((sector >= p_vol->bpb.total_sectors || offset >= p_vol->bpb.bytes_per_sector || offset + size > p_vol->bpb.bytes_per_sector) && offset != 0) {
|
||||
return 10;
|
||||
}
|
||||
if (offset != 0 || size < p_vol->bpb.bytes_per_sector) {
|
||||
err = VFiPFCACHE_ReadDataPage(p_vol, sector, &p_page, set_sig);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
VFipf_memcpy(p_buf, &p_page->p_buf[offset], size);
|
||||
*p_success_size = size;
|
||||
} else if (offset == 0 && (size & (p_vol->bpb.bytes_per_sector - 1)) == 0) {
|
||||
err = VFiPFCACHE_ReadDataNumSector(p_vol, p_buf, sector, size >> p_vol->bpb.log2_bytes_per_sector, &num_success);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
*p_success_size += num_success << p_vol->bpb.log2_bytes_per_sector;
|
||||
if (num_success != (size >> p_vol->bpb.log2_bytes_per_sector)) {
|
||||
return 17;
|
||||
}
|
||||
} else if (offset == 0) {
|
||||
p_page = VFiPFCACHE_SearchDataCache(p_vol, sector);
|
||||
if (p_page != PF_NULL) {
|
||||
num_sector = (p_page->sector + p_page->size) - sector;
|
||||
if (num_sector <= (size >> p_vol->bpb.log2_bytes_per_sector)) {
|
||||
VFipf_memcpy(p_buf, p_page->p_buf, num_sector << p_vol->bpb.log2_bytes_per_sector);
|
||||
*p_success_size += num_sector << p_vol->bpb.log2_bytes_per_sector;
|
||||
size -= num_sector << p_vol->bpb.log2_bytes_per_sector;
|
||||
sector += num_sector;
|
||||
} else if (num_sector > (size >> p_vol->bpb.log2_bytes_per_sector)) {
|
||||
VFipf_memcpy(p_buf, p_page->p_buf, size);
|
||||
*p_success_size += size;
|
||||
size = 0;
|
||||
}
|
||||
}
|
||||
if (size != 0) {
|
||||
adjust_sector = 0;
|
||||
num_sector = size >> p_vol->bpb.log2_bytes_per_sector;
|
||||
rest_sector = (sector + num_sector) % p_vol->cache.data_buff_size;
|
||||
if (num_sector > rest_sector) {
|
||||
adjust_sector = num_sector - rest_sector;
|
||||
err = VFiPFCACHE_ReadDataNumSector(p_vol, &p_buf[*p_success_size], sector, adjust_sector, &num_success);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
*p_success_size += num_success << p_vol->bpb.log2_bytes_per_sector;
|
||||
if (num_success != adjust_sector) {
|
||||
return 17;
|
||||
}
|
||||
sector += adjust_sector;
|
||||
num_sector -= adjust_sector;
|
||||
}
|
||||
if (num_sector != 0) {
|
||||
err = VFiPFCACHE_ReadDataPage(p_vol, sector, &p_page, set_sig);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
VFipf_memcpy(&p_buf[*p_success_size], p_page->p_buf, num_sector << p_vol->bpb.log2_bytes_per_sector);
|
||||
*p_success_size += num_sector << p_vol->bpb.log2_bytes_per_sector;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return 10;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 VFiPFSEC_WriteFAT(PF_VOLUME* p_vol, const pf_u8* p_buf, pf_u32 sector, pf_u16 offset, pf_u16 size) {
|
||||
PF_CACHE_PAGE* p_page;
|
||||
pf_s32 err;
|
||||
|
||||
if ((p_vol->flags & 0x01) == 0 || !VFiPFDRV_IsInserted(p_vol) || (p_vol->flags & 2)) {
|
||||
return 9;
|
||||
}
|
||||
if (sector >= p_vol->bpb.total_sectors || offset >= p_vol->bpb.bytes_per_sector || offset + size > p_vol->bpb.bytes_per_sector) {
|
||||
return 10;
|
||||
}
|
||||
err = VFiPFCACHE_ReadFATPage(p_vol, sector, &p_page);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
VFipf_memcpy(&p_page->p_buf[offset], (pf_u8*)p_buf, size);
|
||||
err = VFiPFCACHE_WriteFATPage(p_vol, p_page);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 VFiPFSEC_WriteData(PF_VOLUME* p_vol, const pf_u8* p_buf, pf_u32 sector, pf_u16 offset, pf_u32 size, pf_u32* p_success_size, pf_bool set_sig) {
|
||||
pf_s32 err;
|
||||
PF_CACHE_PAGE* p_page;
|
||||
pf_u32 num_success;
|
||||
pf_u32 num_sector;
|
||||
pf_u32 adjust_sector;
|
||||
pf_u32 rest_sector;
|
||||
|
||||
*p_success_size = 0;
|
||||
if ((p_vol->flags & 0x01) == 0 || !VFiPFDRV_IsInserted(p_vol) || (p_vol->flags & 2)) {
|
||||
return 9;
|
||||
}
|
||||
if ((sector >= p_vol->bpb.total_sectors || offset >= p_vol->bpb.bytes_per_sector || offset + size > p_vol->bpb.bytes_per_sector) && offset != 0) {
|
||||
return 10;
|
||||
}
|
||||
if (offset != 0 || size < p_vol->bpb.bytes_per_sector) {
|
||||
err = VFiPFCACHE_ReadDataPageAndFlushIfNeeded(p_vol, sector, &p_page, set_sig);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
VFipf_memcpy(&p_page->p_buf[offset], (void*)p_buf, size);
|
||||
err = VFiPFCACHE_WriteDataPage(p_vol, p_page, set_sig);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
*p_success_size = size;
|
||||
} else if (offset == 0 && (size & (p_vol->bpb.bytes_per_sector - 1)) == 0) {
|
||||
err = VFiPFCACHE_WriteDataNumSectorAndFreeIfNeeded(p_vol, p_buf, sector, size >> p_vol->bpb.log2_bytes_per_sector, &num_success);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
*p_success_size = num_success << p_vol->bpb.log2_bytes_per_sector;
|
||||
if (num_success != (size >> p_vol->bpb.log2_bytes_per_sector)) {
|
||||
return 17;
|
||||
}
|
||||
} else if (offset == 0) {
|
||||
adjust_sector = 0;
|
||||
num_sector = size >> p_vol->bpb.log2_bytes_per_sector;
|
||||
rest_sector = (sector + num_sector) % p_vol->cache.data_buff_size;
|
||||
if (num_sector > rest_sector) {
|
||||
adjust_sector = num_sector - rest_sector;
|
||||
err = VFiPFCACHE_WriteDataNumSectorAndFreeIfNeeded(p_vol, p_buf, sector, adjust_sector, &num_success);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
*p_success_size = num_success << p_vol->bpb.log2_bytes_per_sector;
|
||||
if (num_success != adjust_sector) {
|
||||
return 17;
|
||||
}
|
||||
sector += adjust_sector;
|
||||
num_sector -= adjust_sector;
|
||||
}
|
||||
if (num_sector != 0) {
|
||||
err = VFiPFCACHE_ReadDataPageAndFlushIfNeeded(p_vol, sector, &p_page, set_sig);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
VFipf_memcpy(p_page->p_buf, (pf_u8*)&p_buf[*p_success_size], num_sector << p_vol->bpb.log2_bytes_per_sector);
|
||||
err = VFiPFCACHE_WriteDataPage(p_vol, p_page, set_sig);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
*p_success_size += num_sector << p_vol->bpb.log2_bytes_per_sector;
|
||||
}
|
||||
} else {
|
||||
return 10;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
24
libs/RVL_SDK/src/fa/pf_service.c
Normal file
24
libs/RVL_SDK/src/fa/pf_service.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#define VFiPF_GET_LE_U16 PF_GET_LE_U16
|
||||
#define VFiPF_LE16_TO_U16_STR PF_LE16_TO_U16_STR
|
||||
#include <private/vf/PrFILE2/pf_types.h>
|
||||
|
||||
pf_u16 VFiPF_GET_LE_U16(const pf_u8* buf) {
|
||||
return (pf_u16)((pf_u16)buf[1] << 8 | (pf_u16)buf[0]);
|
||||
}
|
||||
|
||||
void VFiPF_LE16_TO_U16_STR(pf_u8* sSrc, pf_u32 num) {
|
||||
pf_u32 cnt;
|
||||
pf_s8 tmp_src;
|
||||
|
||||
for (cnt = 0; cnt < num; cnt += sizeof(pf_u16)) {
|
||||
pf_s8* p = (pf_s8*)sSrc + cnt;
|
||||
tmp_src = *p;
|
||||
#ifdef DEBUG
|
||||
*((pf_u8*)sSrc + cnt) = *((pf_u8*)sSrc + cnt + 1);
|
||||
*((pf_u8*)sSrc + cnt + 1) = tmp_src;
|
||||
#else
|
||||
sSrc[cnt] = sSrc[cnt + 1];
|
||||
sSrc[cnt + 1] = tmp_src;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
229
libs/RVL_SDK/src/fa/pf_str.c
Normal file
229
libs/RVL_SDK/src/fa/pf_str.c
Normal file
@@ -0,0 +1,229 @@
|
||||
#include <private/vf/PrFILE2/pf_types.h>
|
||||
|
||||
typedef struct PF_STR {
|
||||
const pf_s8* p_head;
|
||||
const pf_s8* p_tail;
|
||||
const pf_s8* p_current;
|
||||
pf_u32 code_mode;
|
||||
} PF_STR;
|
||||
|
||||
typedef struct PFSTR_CHARCODE {
|
||||
pf_s32 (*oem2unicode)(const pf_s8*, pf_u16*);
|
||||
pf_s32 (*unicode2oem)(const pf_u16*, pf_s8*);
|
||||
pf_s32 (*oem_char_width)(const pf_s8*);
|
||||
pf_bool (*is_oem_mb_char)(pf_s8, pf_bool);
|
||||
pf_s32 (*unicode_char_width)(const pf_u16*);
|
||||
pf_bool (*is_unicode_mb_char)(pf_u16, pf_bool);
|
||||
} PFSTR_CHARCODE;
|
||||
|
||||
typedef struct PFSTR_VOLUME_SET {
|
||||
pf_u8 state_prefix[0x48];
|
||||
PFSTR_CHARCODE codeset;
|
||||
} PFSTR_VOLUME_SET;
|
||||
|
||||
extern PFSTR_VOLUME_SET pf_vol_set;
|
||||
|
||||
extern pf_s32 pf_toupper(pf_s32 c);
|
||||
extern pf_u32 pf_strlen(const pf_s8* s);
|
||||
extern pf_u32 pf_w_strlen(const pf_u16* s);
|
||||
extern pf_s32 pf_strcmp(const pf_s8* s1, const pf_s8* s2);
|
||||
extern pf_s32 pf_strncmp(const pf_s8* s1, const pf_s8* s2, pf_u32 length);
|
||||
|
||||
void PFSTR_SetCodeMode(PF_STR* p_str, pf_u32 code_mode) {
|
||||
p_str->code_mode = code_mode;
|
||||
}
|
||||
|
||||
pf_u32 PFSTR_GetCodeMode(PF_STR* p_str) {
|
||||
return p_str->code_mode;
|
||||
}
|
||||
|
||||
void PFSTR_SetLocalStr(PF_STR* p_str, const pf_s8* local_str) {
|
||||
if (p_str->code_mode == 1 || local_str == PF_NULL) {
|
||||
p_str->p_current = p_str->p_head;
|
||||
} else {
|
||||
p_str->p_current = local_str;
|
||||
}
|
||||
}
|
||||
|
||||
pf_s8* PFSTR_GetStrPos(PF_STR* p_str, pf_u32 target) {
|
||||
pf_s8* p_pos;
|
||||
if (target == 1) {
|
||||
p_pos = (pf_s8*)p_str->p_head;
|
||||
} else if (target == 2) {
|
||||
p_pos = (pf_s8*)p_str->p_tail;
|
||||
} else {
|
||||
p_pos = (pf_s8*)p_str->p_current;
|
||||
}
|
||||
return p_pos;
|
||||
}
|
||||
|
||||
void PFSTR_MoveStrPos(PF_STR* p_str, pf_s16 num_char) {
|
||||
pf_s16 cnt;
|
||||
pf_s16 offset = 0;
|
||||
pf_s32 width;
|
||||
pf_s8* p;
|
||||
pf_u16* wp;
|
||||
|
||||
if (PFSTR_GetCodeMode(p_str) == 1) {
|
||||
p = (pf_s8*)p_str->p_head;
|
||||
while (num_char != 0) {
|
||||
if (pf_vol_set.codeset.is_oem_mb_char((pf_s8)*p, PF_TRUE)) {
|
||||
offset++;
|
||||
}
|
||||
offset++;
|
||||
num_char--;
|
||||
}
|
||||
} else {
|
||||
wp = (pf_u16*)p_str->p_head;
|
||||
|
||||
for (cnt = 0; cnt < num_char; cnt++) {
|
||||
width = pf_vol_set.codeset.unicode_char_width(wp);
|
||||
wp += width;
|
||||
offset += (pf_s16)width;
|
||||
}
|
||||
}
|
||||
|
||||
p_str->p_head = &p_str->p_head[offset];
|
||||
}
|
||||
|
||||
pf_s32 PFSTR_InitStr(PF_STR* p_str, const pf_s8* s, pf_u32 code_mode) {
|
||||
if (code_mode == 1) {
|
||||
p_str->p_head = s;
|
||||
p_str->p_tail = &s[pf_strlen(s)];
|
||||
} else if (code_mode == 2) {
|
||||
p_str->p_head = s;
|
||||
p_str->p_tail = s + (pf_w_strlen((pf_u16*)s) * sizeof(pf_u16));
|
||||
}
|
||||
|
||||
PFSTR_SetCodeMode(p_str, code_mode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_u16 PFSTR_StrLen(PF_STR* p_str) {
|
||||
return (pf_u16)(p_str->p_tail - p_str->p_head);
|
||||
}
|
||||
|
||||
pf_u16 PFSTR_StrNumChar(PF_STR* p_str, pf_u32 target) {
|
||||
pf_s8* p;
|
||||
pf_u16 cnt;
|
||||
pf_s32 width;
|
||||
|
||||
if (target == 1) {
|
||||
p = (pf_s8*)p_str->p_head;
|
||||
} else {
|
||||
p = (pf_s8*)p_str->p_tail;
|
||||
}
|
||||
|
||||
if (p_str->code_mode == 1) {
|
||||
for (cnt = 0; (pf_s8)*p != 0; cnt++) {
|
||||
if (pf_vol_set.codeset.is_oem_mb_char((pf_s8)*p, PF_TRUE)) {
|
||||
p++;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
} else {
|
||||
for (cnt = 0; (pf_s8)p[0] != 0 || (pf_s8)p[1] != 0; cnt++) {
|
||||
width = pf_vol_set.codeset.unicode_char_width((pf_u16*)p);
|
||||
p += width;
|
||||
}
|
||||
}
|
||||
|
||||
return cnt;
|
||||
}
|
||||
|
||||
pf_s32 PFSTR_StrCmp(const PF_STR* p_str, const pf_s8* s) {
|
||||
pf_u16 wc;
|
||||
const pf_u16* wp;
|
||||
const pf_s8* p1;
|
||||
const pf_s8* p2;
|
||||
pf_s32 ret;
|
||||
|
||||
if (p_str->code_mode == 1) {
|
||||
p1 = p_str->p_head;
|
||||
p2 = s;
|
||||
ret = pf_strcmp(p1, p2);
|
||||
} else {
|
||||
wp = (pf_u16*)p_str->p_head;
|
||||
|
||||
do {
|
||||
pf_vol_set.codeset.oem2unicode((pf_s8*)s, &wc);
|
||||
s++;
|
||||
|
||||
if (*wp++ != wc) {
|
||||
break;
|
||||
}
|
||||
} while (*(wp - 1) != 0 && wc != 0);
|
||||
|
||||
wp--;
|
||||
ret = *wp - wc;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
pf_s32 PFSTR_StrNCmp(PF_STR* p_str, const pf_s8* s, pf_u32 target, pf_s16 offset, pf_u16 num) {
|
||||
pf_u16 wc;
|
||||
const pf_u16* wp;
|
||||
const pf_s8* p1;
|
||||
const pf_s8* p2;
|
||||
pf_s32 ret;
|
||||
|
||||
if (p_str->code_mode == 1 || target == 3) {
|
||||
if (target == 1) {
|
||||
p1 = &p_str->p_head[offset];
|
||||
} else if (target == 2) {
|
||||
p1 = &p_str->p_tail[offset];
|
||||
} else {
|
||||
p1 = &p_str->p_current[offset];
|
||||
}
|
||||
p2 = s;
|
||||
ret = pf_strncmp(p1, p2, num);
|
||||
} else {
|
||||
if (target == 1) {
|
||||
wp = (pf_u16*)p_str->p_head + offset;
|
||||
} else {
|
||||
wp = (pf_u16*)p_str->p_tail + offset;
|
||||
}
|
||||
|
||||
do {
|
||||
pf_vol_set.codeset.oem2unicode((pf_s8*)s, &wc);
|
||||
s++;
|
||||
num--;
|
||||
|
||||
if (*wp++ != wc || num == 0) {
|
||||
break;
|
||||
}
|
||||
} while (*(wp - 1) != 0 && wc != 0);
|
||||
|
||||
wp--;
|
||||
ret = *wp - wc;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void PFSTR_ToUpperNStr(PF_STR* p_str, pf_u16 num, pf_s8* dest) {
|
||||
pf_u16 wc;
|
||||
const pf_u16* wp;
|
||||
const pf_s8* p;
|
||||
|
||||
if (p_str->code_mode == 1) {
|
||||
p = (pf_s8*)p_str->p_head;
|
||||
|
||||
for (; num != 0 && *p != 0; p++, num--) {
|
||||
*dest++ = pf_toupper(*p);
|
||||
}
|
||||
} else {
|
||||
wp = (pf_u16*)p_str->p_head;
|
||||
|
||||
for (; num != 0 && *wp != 0; wp++, num--) {
|
||||
wc = (*wp >= 'a' && *wp <= 'z') ? *wp + ('A' - 'a') : *wp;
|
||||
*(dest) = (pf_u8)wc;
|
||||
*(dest + 1) = (pf_u8)(wc >> 8);
|
||||
dest += sizeof(pf_u16);
|
||||
}
|
||||
*dest = 0;
|
||||
}
|
||||
|
||||
*dest = 0;
|
||||
}
|
||||
13
libs/RVL_SDK/src/fa/pf_sync.c
Normal file
13
libs/RVL_SDK/src/fa/pf_sync.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#define PF_FA_STR_LAYOUT
|
||||
#define VFiPFAPI_convertReturnValue PFAPI_convertReturnValue
|
||||
#define VFiPFVOL_sync PFVOL_sync
|
||||
#include <private/vf/PrFILE2/standard/pf_sync.h>
|
||||
|
||||
#include <private/vf/PrFILE2/fatfs/pf_volume.h>
|
||||
#include <private/vf/PrFILE2/standard/pf_api_util.h>
|
||||
|
||||
pf_int32 pf2_sync(pf_ch8 drv_char, pf_s32 mode) {
|
||||
pf_s32 err = VFiPFVOL_sync(drv_char, mode);
|
||||
err = VFiPFAPI_convertReturnValue(err);
|
||||
return err;
|
||||
}
|
||||
30
libs/RVL_SDK/src/fa/pf_system.c
Normal file
30
libs/RVL_SDK/src/fa/pf_system.c
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <private/fa/pf_system.h>
|
||||
|
||||
typedef struct PFSYS_DATE { u32 sys_year, sys_month, sys_day; } PFSYS_DATE;
|
||||
typedef struct PFSYS_TIME { u32 sys_hour, sys_min, sys_sec, sys_ms; } PFSYS_TIME;
|
||||
typedef struct PFSYS_VOLUME_SET {
|
||||
u8 volume_state[0x64];
|
||||
s32 context_id;
|
||||
} PFSYS_VOLUME_SET;
|
||||
extern PFSYS_VOLUME_SET pf_vol_set;
|
||||
extern void pfstub_init_stub(void);
|
||||
PFSYS_SYSTEM_SET pf_sys_set;
|
||||
|
||||
void PFSYS_initializeSYS(void) {
|
||||
pfstub_init_stub();
|
||||
}
|
||||
s32 PFSYS_GetCurrentContextID(s32* context_id) {
|
||||
*context_id = pf_vol_set.context_id;
|
||||
return 0;
|
||||
}
|
||||
void PFSYS_TimeStamp(PFSYS_DATE* sdate, PFSYS_TIME* stime) {
|
||||
OSCalendarTime calendar;
|
||||
OSTicksToCalendarTime(OSGetTime(), &calendar);
|
||||
sdate->sys_year = calendar.year;
|
||||
sdate->sys_month = calendar.mon + 1;
|
||||
sdate->sys_day = calendar.mday;
|
||||
stime->sys_hour = calendar.hour;
|
||||
stime->sys_min = calendar.min;
|
||||
stime->sys_sec = calendar.sec;
|
||||
stime->sys_ms = 1;
|
||||
}
|
||||
13
libs/RVL_SDK/src/fa/pf_unmount.c
Normal file
13
libs/RVL_SDK/src/fa/pf_unmount.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#define PF_FA_STR_LAYOUT
|
||||
#define VFiPFAPI_convertReturnValue4unmount PFAPI_convertReturnValue4unmount
|
||||
#define VFiPFVOL_unmount PFVOL_unmount
|
||||
#include <private/vf/PrFILE2/standard/pf_unmount.h>
|
||||
|
||||
#include <private/vf/PrFILE2/fatfs/pf_volume.h>
|
||||
#include <private/vf/PrFILE2/standard/pf_api_util.h>
|
||||
|
||||
pf_int32 pf2_unmount(pf_ch8 drive, pf_u32 mode) {
|
||||
pf_s32 err = VFiPFVOL_unmount(drive, mode);
|
||||
err = VFiPFAPI_convertReturnValue4unmount(err);
|
||||
return err;
|
||||
}
|
||||
@@ -21,10 +21,29 @@ typedef struct NWC24MsgObjPrivate {
|
||||
u32 type; // 0x04
|
||||
u32 length; // 0x08
|
||||
u32 appId; // 0x0C
|
||||
#ifdef NWC24_MSG_READ
|
||||
u32 headerSize;
|
||||
#elif defined(NWC24_MBOX_CTRL) || defined(NWC24_MSG_COMMIT)
|
||||
u32 unk_0x10;
|
||||
#else
|
||||
u8 unk_0x10[0x4];
|
||||
#endif
|
||||
u32 tag; // 0x14
|
||||
u32 ledPattern; // 0x18
|
||||
#if defined(NWC24_MBOX_CTRL) || defined(NWC24_MSG_COMMIT)
|
||||
u32 unk_0x1C;
|
||||
#endif
|
||||
#if defined(NWC24_MBOX_CTRL) || defined(NWC24_MSG_COMMIT)
|
||||
union {
|
||||
NWC24UserId fromId;
|
||||
#ifdef NWC24_MSG_COMMIT
|
||||
NWC24Data fromAddr;
|
||||
#endif
|
||||
struct { u32 fromIdHigh, fromIdLow; };
|
||||
};
|
||||
#else
|
||||
NWC24UserId fromId; // 0x20
|
||||
#endif
|
||||
u32 unk_0x28;
|
||||
u32 unk_0x2C;
|
||||
NWC24Data unk_0x30;
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
typedef struct PF_STR {
|
||||
const pf_s8* p_head; // 0x00
|
||||
const pf_s8* p_tail; // 0x04
|
||||
#ifdef PF_FA_STR_LAYOUT
|
||||
const pf_s8* p_current;
|
||||
#endif
|
||||
pf_u32 code_mode; // 0x08
|
||||
} PF_STR;
|
||||
|
||||
|
||||
@@ -128,7 +128,19 @@ static const pf_u16 cp932_to_unicode[45][189] = {
|
||||
0x6A5F, 0x5E30, 0x6BC5, 0x6C17, 0x6C7D, 0x757F, 0x7948, 0x5B63, 0x7A00, 0x7D00, 0x5FBD, 0x898F, 0x8A18, 0x8CB4, 0x8D77, 0x8ECC,
|
||||
0x8F1D, 0x98E2, 0x9A0E, 0x9B3C, 0x4E80, 0x507D, 0x5100, 0x5993, 0x5B9C, 0x622F, 0x6280, 0x64EC, 0x6B3A, 0x72A0, 0x7591, 0x7947,
|
||||
0x7FA9, 0x87FB, 0x8ABC, 0x8B70, 0x63AC, 0x83CA, 0x97A0, 0x5409, 0x5403, 0x55AB, 0x6854, 0x6A58, 0x8A70, 0x7827, 0x6775, 0x9ECD,
|
||||
0x5374, 0x5BA2, 0x811A, 0x8650, 0x9006, 0x4E18, 0x4E45, 0x4EC7, 0x4F11, 0x53CA, 0x5438, 0x5BAE, 0x5F13, 0x6025, 0x6551, 0x0000,
|
||||
0x5374, 0x5BA2,
|
||||
#ifdef PF_FA_CP932_TABLE
|
||||
0x0000
|
||||
#else
|
||||
0x811A
|
||||
#endif
|
||||
,
|
||||
#ifdef PF_FA_CP932_TABLE
|
||||
0x0000
|
||||
#else
|
||||
0x8650
|
||||
#endif
|
||||
, 0x9006, 0x4E18, 0x4E45, 0x4EC7, 0x4F11, 0x53CA, 0x5438, 0x5BAE, 0x5F13, 0x6025, 0x6551, 0x0000,
|
||||
0x673D, 0x6C42, 0x6C72, 0x6CE3, 0x7078, 0x7403, 0x7A76, 0x7AAE, 0x7B08, 0x7D1A, 0x7CFE, 0x7D66, 0x65E7, 0x725B, 0x53BB, 0x5C45,
|
||||
0x5DE8, 0x62D2, 0x62E0, 0x6319, 0x6E20, 0x865A, 0x8A31, 0x8DDD, 0x92F8, 0x6F01, 0x79A6, 0x9B5A, 0x4EA8, 0x4EAB, 0x4EAC, 0x4F9B,
|
||||
0x4FA0, 0x50D1, 0x5147, 0x7AF6, 0x5171, 0x51F6, 0x5354, 0x5321, 0x537F, 0x53EB, 0x55AC, 0x5883, 0x5CE1, 0x5F37, 0x5F4A, 0x602F,
|
||||
@@ -236,8 +248,20 @@ static const pf_u16 cp932_to_unicode[45][189] = {
|
||||
0x6065, 0x667A, 0x6C60, 0x75F4, 0x7A1A, 0x7F6E, 0x81F4, 0x8718, 0x9045, 0x99B3, 0x7BC9, 0x755C, 0x7AF9, 0x7B51, 0x84C4, 0x0000,
|
||||
0x9010, 0x79E9, 0x7A92, 0x8336, 0x5AE1, 0x7740, 0x4E2D, 0x4EF2, 0x5B99, 0x5FE0, 0x62BD, 0x663C, 0x67F1, 0x6CE8, 0x866B, 0x8877,
|
||||
0x8A3B, 0x914E, 0x92F3, 0x99D0, 0x6A17, 0x7026, 0x732A, 0x82E7, 0x8457, 0x8CAF, 0x4E01, 0x5146, 0x51CB, 0x558B, 0x5BF5, 0x5E16,
|
||||
0x5E33, 0x5E81, 0x5F14, 0x5F35, 0x5F6B, 0x5FB4, 0x61F2, 0x6311, 0x66A2, 0x671D, 0x6F6E, 0x7252, 0x753A, 0x773A, 0x8074, 0x8139,
|
||||
0x8178, 0x8776, 0x8ABF, 0x8ADC, 0x8D85, 0x8DF3, 0x929A, 0x9577, 0x9802, 0x9CE5, 0x52C5, 0x6357, 0x76F4, 0x6715, 0x6C88, 0x73CD,
|
||||
0x5E33, 0x5E81, 0x5F14, 0x5F35, 0x5F6B, 0x5FB4, 0x61F2, 0x6311, 0x66A2, 0x671D, 0x6F6E, 0x7252, 0x753A, 0x773A, 0x8074,
|
||||
#ifdef PF_FA_CP932_TABLE
|
||||
0x0000
|
||||
#else
|
||||
0x8139
|
||||
#endif
|
||||
,
|
||||
|
||||
#ifdef PF_FA_CP932_TABLE
|
||||
0x0000
|
||||
#else
|
||||
0x8178
|
||||
#endif
|
||||
, 0x8776, 0x8ABF, 0x8ADC, 0x8D85, 0x8DF3, 0x929A, 0x9577, 0x9802, 0x9CE5, 0x52C5, 0x6357, 0x76F4, 0x6715, 0x6C88, 0x73CD,
|
||||
0x8CC3, 0x93AE, 0x9673, 0x6D25, 0x589C, 0x690E, 0x69CC, 0x8FFD, 0x939A, 0x75DB, 0x901A, 0x585A, 0x6802, 0x63B4, 0x69FB, 0x4F43,
|
||||
0x6F2C, 0x67D8, 0x8FBB, 0x8526, 0x7DB4, 0x9354, 0x693F, 0x6F70, 0x576A, 0x58F7, 0x5B2C, 0x7D2C, 0x722A, 0x540A, 0x91E3, 0x9DB4,
|
||||
0x4EAD, 0x4F4E, 0x505C, 0x5075, 0x5243, 0x8C9E, 0x5448, 0x5824, 0x5B9A, 0x5E1D, 0x5E95, 0x5EAD, 0x5EF7, 0x5F1F, 0x608C, 0x62B5,
|
||||
@@ -500,7 +524,19 @@ static const pf_u16 cp932_to_unicode[45][189] = {
|
||||
},
|
||||
|
||||
{
|
||||
0x968B, 0x8146, 0x813E, 0x8153, 0x8151, 0x80FC, 0x8171, 0x816E, 0x8165, 0x8166, 0x8174, 0x8183, 0x8188, 0x818A, 0x8180, 0x8182,
|
||||
0x968B, 0x8146, 0x813E, 0x8153, 0x8151, 0x80FC, 0x8171, 0x816E, 0x8165,
|
||||
#ifdef PF_FA_CP932_TABLE
|
||||
0x0000
|
||||
#else
|
||||
0x8166
|
||||
#endif
|
||||
,
|
||||
#ifdef PF_FA_CP932_TABLE
|
||||
0x0000
|
||||
#else
|
||||
0x8174
|
||||
#endif
|
||||
, 0x8183, 0x8188, 0x818A, 0x8180, 0x8182,
|
||||
0x81A0, 0x8195, 0x81A4, 0x81A3, 0x815F, 0x8193, 0x81A9, 0x81B0, 0x81B5, 0x81BE, 0x81B8, 0x81BD, 0x81C0, 0x81C2, 0x81BA, 0x81C9,
|
||||
0x81CD, 0x81D1, 0x81D9, 0x81D8, 0x81C8, 0x81DA, 0x81DF, 0x81E0, 0x81E7, 0x81FA, 0x81FB, 0x81FE, 0x8201, 0x8202, 0x8205, 0x8207,
|
||||
0x820A, 0x820D, 0x8210, 0x8216, 0x8229, 0x822B, 0x8238, 0x8233, 0x8240, 0x8259, 0x8258, 0x825D, 0x825A, 0x825F, 0x8264, 0x0000,
|
||||
|
||||
@@ -104,8 +104,12 @@ NWC24Err NWC24ReadMsgMBOptOutFlag(const NWC24MsgObj* msg, BOOL* mbOptOutFlag, u3
|
||||
NWC24Err NWC24ReadMsgFromAddr(const NWC24MsgObj* msg, char* addr, u32 addrLen);
|
||||
NWC24Err NWC24ReadMsgSubject(const NWC24MsgObj* msg, char* subject, u32 subjectLen);
|
||||
NWC24Err NWC24ReadMsgText(const NWC24MsgObj* msg, char* text, u32 textLen, NWC24Charset* charset, NWC24Encoding* encoding);
|
||||
#if defined(NWC24_MSG_SUBJECT) || defined(NWC24_MSG_READ)
|
||||
NWC24Err NWC24ReadMsgTextEx(const NWC24MsgObj* msg, char* text, u32 textLen, char* name, u32 nameLen);
|
||||
#else
|
||||
NWC24Err NWC24ReadMsgTextEx(const NWC24MsgObj* msg, char* text, u32 textLen, const char* name, u32 nameLen, NWC24Charset* charset,
|
||||
NWC24Encoding* encoding);
|
||||
#endif
|
||||
NWC24Err NWC24ReadMsgAttached(const NWC24MsgObj* msg, u32 attachIndex, u8* attachData, u32 attachSize);
|
||||
|
||||
NWC24Err NWC24ReadMsgSubjectPublic(const NWC24MsgObj* msg, u16* subject, u32* subjectLen, NWC24EncodingRegion encRegion, u16 unk, u8* work,
|
||||
|
||||
236
libs/RevoEX/src/nwc24/NWC24DateParser.c
Normal file
236
libs/RevoEX/src/nwc24/NWC24DateParser.c
Normal file
@@ -0,0 +1,236 @@
|
||||
#include <private/nwc24/NWC24Utils.h>
|
||||
|
||||
static const u8 DAYS_OF_MONTH[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||
static const u16 DAYS_OF_YEAR[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
|
||||
|
||||
s32 ConvertDateToDays(u16 year, u8 month, u8 day);
|
||||
void ConvertDaysToDate(u16* year, u8* month, u8* day, s32 days);
|
||||
|
||||
static inline BOOL IsLeapYear(u16 year) {
|
||||
BOOL leap = FALSE;
|
||||
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
|
||||
leap = TRUE;
|
||||
return leap;
|
||||
}
|
||||
|
||||
NWC24Err NWC24iDateToMinutes(s32* minutes, const NWC24Date* date) {
|
||||
s32 days;
|
||||
s32 minutesInDay;
|
||||
NWC24Err result;
|
||||
u8 hour;
|
||||
u8 minute;
|
||||
|
||||
days = ConvertDateToDays(date->year, date->month, date->day);
|
||||
if (days == -1) {
|
||||
result = NWC24_ERR_FAILED;
|
||||
} else {
|
||||
hour = date->hour;
|
||||
minute = date->min;
|
||||
if (hour > 23 || minute > 59) {
|
||||
minutesInDay = -1;
|
||||
} else {
|
||||
minutesInDay = minute + hour * 60;
|
||||
}
|
||||
if (minutesInDay == -1 || date->sec > 60) {
|
||||
result = NWC24_ERR_FAILED;
|
||||
} else {
|
||||
result = NWC24_OK;
|
||||
*minutes = minutesInDay + days * 1440;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24iMinutesToDate(NWC24Date* date, s32 minutes) {
|
||||
s32 days;
|
||||
|
||||
if (minutes < 0) {
|
||||
minutes = 0;
|
||||
}
|
||||
|
||||
days = minutes / 1440;
|
||||
minutes %= 1440;
|
||||
date->hour = minutes / 60;
|
||||
date->min = minutes % 60;
|
||||
ConvertDaysToDate(&date->year, &date->month, &date->day, days);
|
||||
return NWC24_OK;
|
||||
}
|
||||
|
||||
NWC24Err NWC24iEpochSecondsToDate(NWC24Date* date, s64 seconds) {
|
||||
s64 elapsedMinutes;
|
||||
s32 minutes;
|
||||
s32 days;
|
||||
|
||||
if (seconds + 2208988800LL < 0) {
|
||||
seconds = -2208988800LL;
|
||||
}
|
||||
|
||||
date->sec = (seconds + 2208988800LL) % 60;
|
||||
elapsedMinutes = (seconds + 2208988800LL) / 60;
|
||||
if ((s32)elapsedMinutes < 0) {
|
||||
elapsedMinutes = 0;
|
||||
}
|
||||
minutes = elapsedMinutes;
|
||||
|
||||
days = minutes / 1440;
|
||||
minutes %= 1440;
|
||||
date->hour = minutes / 60;
|
||||
date->min = minutes % 60;
|
||||
ConvertDaysToDate(&date->year, &date->month, &date->day, days);
|
||||
return NWC24_OK;
|
||||
}
|
||||
|
||||
NWC24Err NWC24iMinutesToOSCalendarTime(OSCalendarTime* calendar, s32 minutes) {
|
||||
s32 days;
|
||||
NWC24Date date;
|
||||
BOOL isLeapYear;
|
||||
|
||||
if (minutes < 0) {
|
||||
minutes = 0;
|
||||
}
|
||||
|
||||
days = minutes / 1440;
|
||||
minutes %= 1440;
|
||||
|
||||
date.hour = minutes / 60;
|
||||
date.min = minutes % 60;
|
||||
ConvertDaysToDate(&date.year, &date.month, &date.day, days);
|
||||
isLeapYear = 0;
|
||||
|
||||
calendar->year = date.year;
|
||||
calendar->mon = date.month - 1;
|
||||
calendar->mday = date.day;
|
||||
calendar->hour = date.hour;
|
||||
calendar->min = date.min;
|
||||
calendar->sec = 0;
|
||||
calendar->msec = 0;
|
||||
calendar->usec = 0;
|
||||
calendar->yday = date.day + DAYS_OF_YEAR[date.month - 1] - 1;
|
||||
if (((date.year % 4 == 0 && date.year % 100 != 0) || date.year % 400 == 0)) {
|
||||
isLeapYear = 1;
|
||||
}
|
||||
if (isLeapYear && date.month > 2) {
|
||||
calendar->yday++;
|
||||
}
|
||||
calendar->wday = (days + 1) % 7;
|
||||
return NWC24_OK;
|
||||
}
|
||||
|
||||
NWC24Err NWC24iDateToOSCalendarTime(OSCalendarTime* calendar, const NWC24Date* date) {
|
||||
BOOL isLeapYear;
|
||||
s32 days;
|
||||
|
||||
isLeapYear = 0;
|
||||
|
||||
calendar->year = date->year;
|
||||
calendar->mon = date->month - 1;
|
||||
calendar->mday = date->day;
|
||||
calendar->hour = date->hour;
|
||||
calendar->min = date->min;
|
||||
calendar->sec = date->sec;
|
||||
calendar->msec = 0;
|
||||
calendar->usec = 0;
|
||||
calendar->yday = date->day + DAYS_OF_YEAR[date->month - 1] - 1;
|
||||
if (((date->year % 4 == 0 && date->year % 100 != 0) || date->year % 400 == 0)) {
|
||||
isLeapYear = 1;
|
||||
}
|
||||
if (isLeapYear && date->month > 2) {
|
||||
calendar->yday++;
|
||||
}
|
||||
|
||||
days = ConvertDateToDays(date->year, date->month, date->day);
|
||||
calendar->wday = (days + 1) % 7;
|
||||
return NWC24_OK;
|
||||
}
|
||||
|
||||
NWC24Err NWC24iIsValidDate(u16 year, u8 month, u8 day) {
|
||||
return ConvertDateToDays(year, month, day) == -1 ? NWC24_ERR_INVALID_VALUE : NWC24_OK;
|
||||
}
|
||||
|
||||
s32 ConvertDateToDays(u16 year, u8 month, u8 day) {
|
||||
s32 daysOfYear;
|
||||
s32 yearOffset;
|
||||
s32 centuryLeapDays;
|
||||
s32 commonLeapDays;
|
||||
BOOL isLeapYear;
|
||||
|
||||
if (year < 1900 || month < 1 || month > 12) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (month == 2) {
|
||||
isLeapYear = 0;
|
||||
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
|
||||
isLeapYear = 1;
|
||||
}
|
||||
if (isLeapYear) {
|
||||
if (day < 1 || day > 29) {
|
||||
return -1;
|
||||
}
|
||||
goto validDate;
|
||||
}
|
||||
}
|
||||
if (day < 1 || DAYS_OF_MONTH[month - 1] < day) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
validDate:
|
||||
daysOfYear = day - 1 + DAYS_OF_YEAR[month - 1];
|
||||
if (month >= 3) {
|
||||
isLeapYear = 0;
|
||||
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
|
||||
isLeapYear = 1;
|
||||
}
|
||||
if (isLeapYear) {
|
||||
daysOfYear++;
|
||||
}
|
||||
}
|
||||
|
||||
yearOffset = year - 1900;
|
||||
centuryLeapDays = (yearOffset + 299) / 400;
|
||||
daysOfYear += yearOffset * 365;
|
||||
daysOfYear += centuryLeapDays;
|
||||
commonLeapDays = (yearOffset - 1) / 4 - (yearOffset - 1) / 100;
|
||||
return daysOfYear + commonLeapDays;
|
||||
}
|
||||
|
||||
void ConvertDaysToDate(u16* year, u8* month, u8* day, s32 days) {
|
||||
*year = 1900;
|
||||
*month = 1;
|
||||
*day = 1;
|
||||
if (days < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
u16 currentYear = *year;
|
||||
s32 previousDays = days;
|
||||
BOOL leapYear = (currentYear % 4 == 0 && currentYear % 100 != 0) || currentYear % 400 == 0;
|
||||
days -= 365 + (leapYear != FALSE);
|
||||
if (days < 0) {
|
||||
days = previousDays;
|
||||
break;
|
||||
}
|
||||
*year = *year + 1;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
s32 previousDays = days;
|
||||
if (*month == 2) {
|
||||
BOOL leapYear = IsLeapYear(*year);
|
||||
if (leapYear) {
|
||||
days -= 29;
|
||||
} else {
|
||||
days -= DAYS_OF_MONTH[*month - 1];
|
||||
}
|
||||
} else {
|
||||
days -= DAYS_OF_MONTH[*month - 1];
|
||||
}
|
||||
if (days < 0) {
|
||||
*day += previousDays;
|
||||
return;
|
||||
}
|
||||
*month = *month + 1;
|
||||
}
|
||||
}
|
||||
1049
libs/RevoEX/src/nwc24/NWC24MBoxCtrl.c
Normal file
1049
libs/RevoEX/src/nwc24/NWC24MBoxCtrl.c
Normal file
File diff suppressed because it is too large
Load Diff
767
libs/RevoEX/src/nwc24/NWC24Mime.c
Normal file
767
libs/RevoEX/src/nwc24/NWC24Mime.c
Normal file
@@ -0,0 +1,767 @@
|
||||
#include <private/nwc24.h>
|
||||
#include <revolution/nwc24.h>
|
||||
|
||||
static const char* MIMEEncStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
|
||||
static NWC24Err Base64Encode(u8* decoded, int decodedSize, u32* stringSize, u8* encoded, int encodedSize, u32* encodedSizeOut) {
|
||||
NWC24Err result = NWC24_OK;
|
||||
s32 textIdx;
|
||||
s32 dataIdx = 0;
|
||||
BOOL hasThird;
|
||||
BOOL hasSecond;
|
||||
u32 combined;
|
||||
|
||||
for (textIdx = 0; dataIdx < decodedSize; dataIdx += 3) {
|
||||
if (textIdx + 3 >= encodedSize) {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
break;
|
||||
}
|
||||
|
||||
hasThird = FALSE;
|
||||
hasSecond = FALSE;
|
||||
|
||||
combined = (u32)decoded[dataIdx] << 8;
|
||||
|
||||
if (dataIdx + 1 < decodedSize) {
|
||||
hasSecond = TRUE;
|
||||
combined |= (u8)decoded[dataIdx + 1];
|
||||
}
|
||||
|
||||
combined <<= 8;
|
||||
|
||||
if (dataIdx + 2 < decodedSize) {
|
||||
hasThird = TRUE;
|
||||
combined |= (u8)decoded[dataIdx + 2];
|
||||
}
|
||||
|
||||
encoded[textIdx + 0] = MIMEEncStr[combined >> 18 & (64 - 1)];
|
||||
encoded[textIdx + 1] = MIMEEncStr[combined >> 12 & (64 - 1)];
|
||||
encoded[textIdx + 2] = MIMEEncStr[hasSecond ? (combined >> 6 & (64 - 1)) : 64];
|
||||
encoded[textIdx + 3] = MIMEEncStr[hasThird ? (combined & (64 - 1)) : 64];
|
||||
|
||||
textIdx += 4;
|
||||
}
|
||||
|
||||
*encodedSizeOut = textIdx;
|
||||
|
||||
if (stringSize != NULL) {
|
||||
textIdx = decodedSize;
|
||||
|
||||
if (decodedSize < dataIdx) {
|
||||
dataIdx = decodedSize;
|
||||
}
|
||||
|
||||
*stringSize = dataIdx;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24Base64Encode(u8* decoded, int decodedSize, u8* encoded, int encodedSize, u32* stringSize) {
|
||||
return Base64Encode(decoded, decodedSize, NULL, encoded, encodedSize, stringSize);
|
||||
}
|
||||
|
||||
NWC24Err NWC24Base64Decode(u8* encoded, int encodedSize, u8* decoded, int decodedSize, u32* stringSize) {
|
||||
int bitCount = 0;
|
||||
u32 bitBuffer = 0;
|
||||
u32 decodedOffset = 0;
|
||||
s8* table = (s8*)NWC24WorkP->base64Work;
|
||||
BOOL produceOutput;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < encodedSize; i++) {
|
||||
if ((s32)table[encoded[i]] >= 0) {
|
||||
if ((s32)table[encoded[i]] < 0x40) {
|
||||
bitCount += 6;
|
||||
bitBuffer <<= 6;
|
||||
produceOutput = bitCount >= 8;
|
||||
bitBuffer |= (u32)table[encoded[i]];
|
||||
if (produceOutput) {
|
||||
if (decodedOffset >= (u32)decodedSize) {
|
||||
*stringSize = decodedSize;
|
||||
return NWC24_ERR_OVERFLOW;
|
||||
}
|
||||
bitCount -= 8;
|
||||
*decoded++ = (u8)((s32)bitBuffer >> bitCount);
|
||||
decodedOffset++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*stringSize = decodedOffset;
|
||||
return NWC24_OK;
|
||||
}
|
||||
|
||||
void NWC24InitBase64Table(u8* table) {
|
||||
s8* signedTable = (s8*)table;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
signedTable[i] = -1;
|
||||
}
|
||||
for (i = 'A'; i <= 'Z'; i++) {
|
||||
table[i] = i - 'A';
|
||||
}
|
||||
for (i = 0; i < 26; i++) {
|
||||
table['a' + i] = i + 26;
|
||||
}
|
||||
for (i = 0; i < 10; i++) {
|
||||
table['0' + i] = i + 52;
|
||||
}
|
||||
table['+'] = 62;
|
||||
table['/'] = 63;
|
||||
}
|
||||
|
||||
static NWC24Err QEncode(char* encoded, u32 encodedCapacity, u32* encodedSize, u8* decoded, u32 decodedSize, u32* decodedSizeOut, s32 maxLineLength) {
|
||||
char* output;
|
||||
u32 textWritten;
|
||||
u32 dataIdx;
|
||||
NWC24Err result;
|
||||
s32 lineLength;
|
||||
u8 octets[3];
|
||||
BOOL lineBreak;
|
||||
s32 emitCount;
|
||||
s32 bytesRead;
|
||||
s16 currentByte;
|
||||
s32 i;
|
||||
|
||||
result = NWC24_OK;
|
||||
|
||||
if (encoded == NULL) {
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
if (decoded == NULL) {
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
if (decodedSize <= 0) {
|
||||
return NWC24_ERR_OVERFLOW;
|
||||
}
|
||||
|
||||
if (decodedSizeOut != NULL) {
|
||||
*decodedSizeOut = 0;
|
||||
}
|
||||
|
||||
if (encodedSize != NULL) {
|
||||
*encodedSize = 0;
|
||||
}
|
||||
|
||||
output = encoded;
|
||||
lineLength = 0;
|
||||
textWritten = 0;
|
||||
dataIdx = 0;
|
||||
|
||||
while (dataIdx < decodedSize) {
|
||||
currentByte = *decoded;
|
||||
lineBreak = FALSE;
|
||||
|
||||
if ((char)currentByte >= '!' && (char)currentByte <= '~' && (char)currentByte != '=') {
|
||||
bytesRead = 1;
|
||||
emitCount = 1;
|
||||
octets[0] = *decoded;
|
||||
|
||||
} else if (dataIdx + 1 < decodedSize && (char)currentByte == '\r' && (char)decoded[1] == '\n') {
|
||||
bytesRead = 2;
|
||||
emitCount = 1;
|
||||
octets[0] = *decoded;
|
||||
octets[1] = decoded[1];
|
||||
|
||||
} else {
|
||||
octets[0] = '=';
|
||||
|
||||
if ((*decoded >> 4) >= 10) {
|
||||
octets[1] = (*decoded >> 4) % 10 + 'A';
|
||||
} else {
|
||||
octets[1] = (*decoded >> 4) % 10 + '0';
|
||||
}
|
||||
|
||||
if ((*decoded & 0x0F) >= 10) {
|
||||
octets[2] = (*decoded & 0x0F) % 10 + 'A';
|
||||
} else {
|
||||
octets[2] = (*decoded & 0x0F) % 10 + '0';
|
||||
}
|
||||
|
||||
bytesRead = 1;
|
||||
emitCount = 3;
|
||||
}
|
||||
|
||||
if (maxLineLength == 0 && lineLength + emitCount >= 75) {
|
||||
lineBreak = TRUE;
|
||||
emitCount += 3;
|
||||
}
|
||||
|
||||
if (textWritten + emitCount >= encodedCapacity) {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
break;
|
||||
}
|
||||
|
||||
textWritten += emitCount;
|
||||
|
||||
if (lineBreak) {
|
||||
output[0] = '=';
|
||||
output[1] = '\r';
|
||||
output[2] = '\n';
|
||||
|
||||
output += 3;
|
||||
emitCount -= 3;
|
||||
|
||||
lineLength = 0;
|
||||
}
|
||||
|
||||
lineLength += emitCount;
|
||||
|
||||
for (i = 0; i < emitCount; i++) {
|
||||
*(output++) = octets[i];
|
||||
}
|
||||
|
||||
dataIdx += bytesRead;
|
||||
decoded += bytesRead;
|
||||
}
|
||||
|
||||
if (decodedSizeOut != NULL) {
|
||||
*decodedSizeOut = dataIdx;
|
||||
}
|
||||
|
||||
if (encodedSize != NULL) {
|
||||
*encodedSize = textWritten;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static NWC24Err QDecode(char* decoded, u32 decodedCapacity, u32* decodedSize, char* encoded, u32 encodedSize, u32* encodedSizeOut, int flags) {
|
||||
u32 decodedOffset = 0;
|
||||
u32 encodedOffset;
|
||||
char* input;
|
||||
char* output;
|
||||
u32 value = 0;
|
||||
NWC24Err result = NWC24_OK;
|
||||
|
||||
if (decoded == NULL)
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
if (encoded == NULL)
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
if (decodedCapacity == 0) {
|
||||
return NWC24_ERR_OVERFLOW;
|
||||
}
|
||||
if (decodedSize != NULL) {
|
||||
*decodedSize = 0;
|
||||
}
|
||||
if (encodedSizeOut != NULL) {
|
||||
*encodedSizeOut = 0;
|
||||
}
|
||||
|
||||
input = encoded;
|
||||
output = decoded;
|
||||
for (encodedOffset = 0; encodedOffset < encodedSize; encodedOffset++) {
|
||||
if (decodedCapacity <= decodedOffset) {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
break;
|
||||
}
|
||||
if (flags != 0 && *input == '_') {
|
||||
*output++ = ' ';
|
||||
input++;
|
||||
decodedOffset++;
|
||||
} else if (*input == '=' && encodedOffset + 2 < encodedSize) {
|
||||
u32 inputAfterEqual = encodedOffset + 1;
|
||||
char* current = ++input;
|
||||
if (*current == ' ' || *current == '\t') {
|
||||
char* previous = current;
|
||||
u32 scan = 1;
|
||||
while (inputAfterEqual + scan + 1 < encodedSize) {
|
||||
char* next = previous + 1;
|
||||
if (*next == '\r' && previous[2] == '\n') {
|
||||
inputAfterEqual += scan;
|
||||
current = next;
|
||||
break;
|
||||
}
|
||||
if (*next != ' ' && *next != '\t') {
|
||||
break;
|
||||
}
|
||||
previous = next;
|
||||
scan++;
|
||||
}
|
||||
}
|
||||
if (*current == '\r' && current[1] == '\n') {
|
||||
current += 2;
|
||||
encodedOffset = inputAfterEqual + 1;
|
||||
input = current;
|
||||
} else {
|
||||
int high = Util_xtoi(*current);
|
||||
int low;
|
||||
if (high >= 0) {
|
||||
value = (high & 0x0F) << 4;
|
||||
}
|
||||
low = Util_xtoi(current[1]);
|
||||
if (low >= 0) {
|
||||
value |= low & 0x0F;
|
||||
}
|
||||
current += 2;
|
||||
if (high >= 0 && low >= 0) {
|
||||
*output++ = (char)value;
|
||||
decodedOffset++;
|
||||
}
|
||||
encodedOffset = inputAfterEqual + 1;
|
||||
input = current;
|
||||
}
|
||||
} else {
|
||||
*output++ = *input++;
|
||||
decodedOffset++;
|
||||
}
|
||||
}
|
||||
if (decodedSize != NULL) {
|
||||
*decodedSize = decodedOffset;
|
||||
}
|
||||
if (encodedSizeOut != NULL) {
|
||||
*encodedSizeOut = encodedOffset;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24EncodeQuotedPrintable(char* encoded, u32 encodedCapacity, u32* encodedSize, u8* decoded, u32 decodedSize, u32* decodedSizeOut) {
|
||||
return QEncode(encoded, encodedCapacity, encodedSize, decoded, decodedSize, decodedSizeOut, 0);
|
||||
}
|
||||
|
||||
NWC24Err NWC24DecodeQuotedPrintable(char* decoded, u32 decodedCapacity, u32* decodedSize, u8* encoded, u32 encodedSize, u32* encodedSizeOut) {
|
||||
return QDecode(decoded, decodedCapacity, decodedSize, (char*)encoded, encodedSize, encodedSizeOut, 0);
|
||||
}
|
||||
|
||||
static NWC24Err ConcatEncodedText(char* encoded, u32 encodedCapacity, u32* encodedSize, char encoding, u8* decoded, u32 decodedSize,
|
||||
u32* decodedSizeOut);
|
||||
|
||||
static NWC24Err EncodeWord(char* encoded, u32 encodedCapacity, u32* encodedSize, char* charset, u32 charsetSize, char encoding, u8* decoded,
|
||||
u32 decodedSize, u32* decodedSizeOut) {
|
||||
NWC24Err result = NWC24_OK;
|
||||
BOOL encodeOverflow = FALSE;
|
||||
|
||||
if (decodedSizeOut != NULL) {
|
||||
*decodedSizeOut = 0;
|
||||
}
|
||||
if (encodedCapacity == 0) {
|
||||
if (decodedSizeOut != NULL) {
|
||||
*decodedSizeOut = 0;
|
||||
}
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
*encoded = '\0';
|
||||
if (encodedSize != NULL) {
|
||||
*encodedSize = 1;
|
||||
}
|
||||
if (Mail_strlen(encoded) + 2 < encodedCapacity) {
|
||||
Mail_strncat(encoded, "=?", 2);
|
||||
} else {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
}
|
||||
if (result == NWC24_OK) {
|
||||
if (charset == NULL) {
|
||||
result = NWC24_ERR_INVALID_VALUE;
|
||||
} else if (charsetSize + Mail_strlen(encoded) < encodedCapacity) {
|
||||
u32 length = Mail_strlen(charset);
|
||||
Mail_strncat(encoded, charset, length);
|
||||
} else {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
}
|
||||
}
|
||||
if (result == NWC24_OK) {
|
||||
if (Mail_strlen(encoded) + 2 < encodedCapacity) {
|
||||
Mail_strncat(encoded, "?", 1);
|
||||
} else {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
}
|
||||
}
|
||||
if (result == NWC24_OK) {
|
||||
char value[1];
|
||||
value[0] = encoding;
|
||||
if (encoding == 'B' || encoding == 'b' || encoding == 'Q' || encoding == 'q') {
|
||||
u32 length = Mail_strlen(encoded);
|
||||
if (length + 1 < encodedCapacity) {
|
||||
Mail_strncat(encoded, value, 1);
|
||||
} else {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
}
|
||||
} else {
|
||||
result = NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
}
|
||||
if (result == NWC24_OK) {
|
||||
if (Mail_strlen(encoded) + 2 < encodedCapacity) {
|
||||
Mail_strncat(encoded, "?", 1);
|
||||
} else {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
}
|
||||
}
|
||||
if (result == NWC24_OK) {
|
||||
result = ConcatEncodedText(encoded, encodedCapacity, encodedSize, encoding, decoded, decodedSize, decodedSizeOut);
|
||||
if (result == NWC24_OK || result == NWC24_ERR_OVERFLOW) {
|
||||
encodeOverflow = result == NWC24_ERR_OVERFLOW;
|
||||
if (Mail_strlen(encoded) + 2 < encodedCapacity) {
|
||||
Mail_strncat(encoded, "?=", 2);
|
||||
result = NWC24_OK;
|
||||
if (encodedSize != NULL) {
|
||||
*encodedSize = Mail_strlen(encoded) + 1;
|
||||
}
|
||||
if (encodeOverflow) {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
}
|
||||
} else {
|
||||
*encoded = '\0';
|
||||
if (decodedSizeOut != NULL) {
|
||||
*decodedSizeOut = 1;
|
||||
}
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
}
|
||||
} else {
|
||||
*encoded = '\0';
|
||||
if (decodedSizeOut != NULL) {
|
||||
*decodedSizeOut = 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
*encoded = '\0';
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24EncodeWord(u8* encoded, u32 encodedCapacity, u32* encodedSize, char* charset, u32 charsetSize, char encoding, u8* decoded,
|
||||
u32 decodedSize) {
|
||||
NWC24Err result;
|
||||
|
||||
if (encodedSize == NULL) {
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
if (encoded == NULL || encodedCapacity == 0) {
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
if (charset == NULL || charsetSize == 0) {
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
if (encoding == '\0') {
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
if (decoded == NULL) {
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
*encoded = 0;
|
||||
*encodedSize = 1;
|
||||
result = EncodeWord((char*)encoded, encodedCapacity, encodedSize, charset, charsetSize, encoding, decoded, decodedSize, NULL);
|
||||
if (result == NWC24_OK || result == NWC24_ERR_OVERFLOW) {
|
||||
encoded[*encodedSize - 1] = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static NWC24Err ExtractCharset(char* charset, u32 charsetCapacity, u32* charsetSize, char* encoded, u32 encodedSize);
|
||||
static NWC24Err ExtractEncodedText(char* decoded, u32 decodedCapacity, u32* decodedSize, char encoding, char* encoded, u32 encodedSize,
|
||||
u32* encodedSizeOut);
|
||||
|
||||
static BOOL CopyWithoutLinearWhiteSpaces(char* output, int* outputSize, char* input, int inputSize) {
|
||||
BOOL afterNewline = FALSE;
|
||||
u32 outputOffset = 0;
|
||||
s32 capacity;
|
||||
|
||||
if (output == NULL || outputSize == NULL || *outputSize == 0) {
|
||||
return FALSE;
|
||||
}
|
||||
capacity = *outputSize;
|
||||
if (input == NULL) {
|
||||
*output = '\0';
|
||||
*outputSize = 1;
|
||||
return TRUE;
|
||||
}
|
||||
while (outputOffset < capacity - 1U && inputSize != 0 && *input != '\0') {
|
||||
char value = *input;
|
||||
switch (value) {
|
||||
case '\r':
|
||||
case '\n':
|
||||
if (!afterNewline) {
|
||||
*output++ = ' ';
|
||||
outputOffset++;
|
||||
}
|
||||
afterNewline = TRUE;
|
||||
break;
|
||||
case '\t':
|
||||
case ' ':
|
||||
if (!afterNewline) {
|
||||
*output++ = value;
|
||||
outputOffset++;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
*output = value;
|
||||
afterNewline = FALSE;
|
||||
output++;
|
||||
outputOffset++;
|
||||
break;
|
||||
}
|
||||
input++;
|
||||
inputSize--;
|
||||
}
|
||||
*output = '\0';
|
||||
*outputSize = outputOffset + 1;
|
||||
return inputSize == 0 || *input == '\0';
|
||||
}
|
||||
|
||||
static inline char* FindMarker(char* input, u32 size, const char* marker) {
|
||||
u32 markerLength = Mail_strlen(marker);
|
||||
u32 offset;
|
||||
for (offset = 0; offset <= size; offset++) {
|
||||
char* current = input + offset;
|
||||
if (Mail_strncmp(current, marker, markerLength) == 0)
|
||||
return current;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static NWC24Err DecodeWord(char* charsetData, u32 charsetCapacity, char* decoded, u32 decodedCapacity, u32* decodedSize, char* encoded,
|
||||
u32 encodedSize, u32* encodedSizeOut) {
|
||||
int encodedWordPosition = 0;
|
||||
int encodedLength;
|
||||
u32 consumedSize;
|
||||
u32 decodedLength;
|
||||
NWC24Err result = NWC24_OK;
|
||||
|
||||
if (encodedSizeOut != NULL) {
|
||||
*encodedSizeOut = 0;
|
||||
}
|
||||
if (decodedCapacity == 0) {
|
||||
if (encodedSizeOut != NULL)
|
||||
*encodedSizeOut = 0;
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
*decoded = '\0';
|
||||
if (decodedSize != NULL) {
|
||||
*decodedSize = 1;
|
||||
}
|
||||
if (encodedSizeOut != NULL) {
|
||||
*encodedSizeOut = 0;
|
||||
}
|
||||
{
|
||||
u32 markerLength = Mail_strlen("=?");
|
||||
u32 offset;
|
||||
for (offset = 0; offset <= encodedSize; offset++) {
|
||||
encodedWordPosition = (int)(encoded + offset);
|
||||
if (Mail_strncmp((char*)encodedWordPosition, "=?", markerLength) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (offset > encodedSize) {
|
||||
encodedWordPosition = 0;
|
||||
}
|
||||
}
|
||||
if (encodedWordPosition == (int)encoded) {
|
||||
result = ExtractCharset(charsetData, charsetCapacity, &consumedSize, (char*)encoded, encodedSize);
|
||||
if (result != NWC24_OK) {
|
||||
return result;
|
||||
}
|
||||
encodedLength = consumedSize;
|
||||
{
|
||||
u32 markerLength = Mail_strlen("?");
|
||||
u32 offset;
|
||||
char* delimiter = NULL;
|
||||
char* current = (char*)encodedWordPosition + encodedLength;
|
||||
for (offset = 0; offset <= encodedSize - encodedLength; offset++) {
|
||||
if (Mail_strncmp((char*)current, "?", markerLength) == 0) {
|
||||
delimiter = current;
|
||||
break;
|
||||
}
|
||||
current++;
|
||||
}
|
||||
if (delimiter == 0) {
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
{
|
||||
char encoding = delimiter[1];
|
||||
consumedSize = 2;
|
||||
encodedLength += consumedSize;
|
||||
result = ExtractEncodedText(decoded, decodedCapacity, &decodedLength, encoding, encoded + encodedLength, encodedSize - encodedLength,
|
||||
&consumedSize);
|
||||
if (result != NWC24_OK) {
|
||||
return result;
|
||||
}
|
||||
encodedLength += consumedSize;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
u32 localSize = decodedCapacity;
|
||||
if (encodedWordPosition == 0) {
|
||||
encodedLength = STD_strnlen(encoded, encodedSize);
|
||||
} else {
|
||||
encodedLength = encodedWordPosition - (int)encoded;
|
||||
}
|
||||
if (!CopyWithoutLinearWhiteSpaces(decoded, (int*)&localSize, encoded, encodedLength)) {
|
||||
*decodedSize = localSize;
|
||||
if (encodedSizeOut != NULL) {
|
||||
*encodedSizeOut = encodedLength;
|
||||
}
|
||||
return NWC24_ERR_OVERFLOW;
|
||||
}
|
||||
decodedLength = localSize;
|
||||
if (encodedWordPosition != 0) {
|
||||
BOOL whitespaceOnly = TRUE;
|
||||
u32 offset;
|
||||
for (offset = 0; offset < localSize && decoded[offset] != '\0'; offset++) {
|
||||
char value = decoded[offset];
|
||||
if (value != ' ' && value != '\t' && value != '\r' && value != '\n') {
|
||||
whitespaceOnly = FALSE;
|
||||
}
|
||||
}
|
||||
if (whitespaceOnly) {
|
||||
*decoded = '\0';
|
||||
decodedLength = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (decodedSize != NULL) {
|
||||
*decodedSize = decodedLength;
|
||||
}
|
||||
if (encodedSizeOut != NULL) {
|
||||
*encodedSizeOut = encodedLength;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24DecodeMIMEHeaderFieldBody(u8* charsetData, u32 charsetDataSize, u8* decoded, u32 decodedCapacity, u32* decodedSize, u8* encoded,
|
||||
u32 encodedSize) {
|
||||
int result = 0;
|
||||
u8* output;
|
||||
u32 inputSize;
|
||||
|
||||
if (decodedSize == NULL) {
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
if (charsetData == NULL || charsetDataSize == 0) {
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
if (decoded == NULL || decodedCapacity == 0) {
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
if (encoded == NULL)
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
if (encoded == NULL)
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
*decoded = 0;
|
||||
*charsetData = 0;
|
||||
*decodedSize = 1;
|
||||
inputSize = encodedSize;
|
||||
output = decoded;
|
||||
while ((s32)inputSize > 0 && (s32)decodedCapacity > 0 && *encoded != '\0') {
|
||||
u32 copiedSize = 0;
|
||||
u32 consumedSize;
|
||||
result =
|
||||
DecodeWord((char*)charsetData, charsetDataSize, (char*)output, decodedCapacity, &copiedSize, (char*)encoded, inputSize, &consumedSize);
|
||||
if (copiedSize == 0) {
|
||||
break;
|
||||
}
|
||||
copiedSize--;
|
||||
output += copiedSize;
|
||||
decodedCapacity -= copiedSize;
|
||||
*decodedSize += copiedSize;
|
||||
encoded += consumedSize;
|
||||
inputSize -= consumedSize;
|
||||
if (result != NWC24_OK) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (result == NWC24_OK && inputSize > 0 && *encoded != '\0') {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
}
|
||||
decoded[*decodedSize - 1] = '\0';
|
||||
return result;
|
||||
}
|
||||
|
||||
static NWC24Err ConcatEncodedText(char* encoded, u32 encodedCapacity, u32* encodedSize, char encoding, u8* decoded, u32 decodedSize,
|
||||
u32* decodedSizeOut) {
|
||||
u32 prefixSize = Mail_strlen(encoded);
|
||||
int available = encodedCapacity - prefixSize - 2;
|
||||
NWC24Err result;
|
||||
|
||||
if (available > 0) {
|
||||
if (encoding == 'B' || encoding == 'b') {
|
||||
result = Base64Encode(decoded, decodedSize, decodedSizeOut, (u8*)encoded + prefixSize, (u32)(available - 1), encodedSize);
|
||||
} else if (encoding == 'Q' || encoding == 'q') {
|
||||
result = QEncode(encoded + prefixSize, (u32)(available - 1), encodedSize, decoded, decodedSize, decodedSizeOut, 1);
|
||||
} else {
|
||||
result = NWC24_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
if (result == NWC24_OK || result == NWC24_ERR_OVERFLOW) {
|
||||
encoded[prefixSize + *encodedSize] = '\0';
|
||||
*encodedSize += 1;
|
||||
}
|
||||
} else {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static NWC24Err ExtractCharset(char* charset, u32 charsetCapacity, u32* charsetSize, char* encoded, u32 encodedSize) {
|
||||
char* start;
|
||||
char* end;
|
||||
u32 charsetLength;
|
||||
|
||||
if (charset == NULL) {
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
start = FindMarker(encoded, encodedSize, "=?");
|
||||
if (start == NULL) {
|
||||
return NWC24_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
start += 2;
|
||||
end = FindMarker(start, encodedSize - (u32)(start - encoded), "?");
|
||||
if (end == NULL) {
|
||||
return NWC24_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
charsetLength = (u32)(end - start);
|
||||
if (charsetLength >= charsetCapacity) {
|
||||
return NWC24_ERR_OVERFLOW;
|
||||
}
|
||||
Mail_strncpy(charset, start, charsetLength);
|
||||
charset[charsetLength] = '\0';
|
||||
*charsetSize = charsetLength + 2;
|
||||
return NWC24_OK;
|
||||
}
|
||||
|
||||
static NWC24Err ExtractEncodedText(char* decoded, u32 decodedCapacity, u32* decodedSize, char encoding, char* encoded, u32 encodedSize,
|
||||
u32* encodedSizeOut) {
|
||||
char* start;
|
||||
char* end;
|
||||
int length;
|
||||
NWC24Err result;
|
||||
|
||||
if (encoded == NULL || decodedSize == NULL) {
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
*decodedSize = 0;
|
||||
if (encodedSizeOut == NULL) {
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
*encodedSizeOut = 0;
|
||||
start = FindMarker(encoded, encodedSize, "?");
|
||||
if (start == NULL) {
|
||||
return NWC24_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
start++;
|
||||
end = FindMarker(start, encodedSize - (u32)(start - encoded), "?=");
|
||||
if (end == NULL) {
|
||||
return NWC24_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
length = end - start;
|
||||
if (encoding == 'B' || encoding == 'b') {
|
||||
result = NWC24Base64Decode((u8*)start, length, (u8*)decoded, decodedCapacity - 1, decodedSize);
|
||||
if (result == NWC24_OK || result == NWC24_ERR_OVERFLOW) {
|
||||
decoded[*decodedSize] = '\0';
|
||||
*decodedSize += 1;
|
||||
}
|
||||
} else if (encoding == 'Q' || encoding == 'q') {
|
||||
result = QDecode(decoded, decodedCapacity - 1, decodedSize, start, length, NULL, 1);
|
||||
if (result == NWC24_OK || result == NWC24_ERR_OVERFLOW) {
|
||||
decoded[*decodedSize] = '\0';
|
||||
*decodedSize += 1;
|
||||
}
|
||||
} else {
|
||||
return NWC24_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
*encodedSizeOut = (u32)(end - encoded) + 2;
|
||||
return result;
|
||||
}
|
||||
924
libs/RevoEX/src/nwc24/NWC24MsgCommit.c
Normal file
924
libs/RevoEX/src/nwc24/NWC24MsgCommit.c
Normal file
@@ -0,0 +1,924 @@
|
||||
#define NWC24_MSG_COMMIT
|
||||
#include <private/nwc24.h>
|
||||
#include <revolution/net/NETMisc.h>
|
||||
#include <revolution/nwc24.h>
|
||||
|
||||
static char MultiPartDivider[64];
|
||||
BOOL LoopBackEnable = TRUE;
|
||||
static NWC24File* m_pFile;
|
||||
|
||||
static NWC24Err NWC24CommitMsgInternal(NWC24MsgObjPrivate* msg, NWC24MBoxType type);
|
||||
static NWC24Err CheckMsgObject(const NWC24MsgObjPrivate* msg);
|
||||
static NWC24Err CheckMsgBoxSpace(const NWC24MsgObjPrivate* msg, NWC24MBoxType type);
|
||||
static NWC24Err SynthesizeAddrStr(const NWC24Data* address, u32 type, char* dest, s32 capacity, u32* length);
|
||||
static NWC24Err WriteSMTP_MAILFROM(NWC24MsgObjPrivate* msg);
|
||||
static NWC24Err WriteSMTP_RCPTTO(NWC24MsgObjPrivate* msg);
|
||||
static NWC24Err WriteFromField(NWC24MsgObjPrivate* msg);
|
||||
static NWC24Err WriteToField(NWC24MsgObjPrivate* msg);
|
||||
static NWC24Err WriteDateField(NWC24MsgObjPrivate* msg);
|
||||
static NWC24Err WriteXWiiAppIdField(NWC24MsgObjPrivate* msg);
|
||||
static NWC24Err WriteXWiiFaceField(NWC24MsgObjPrivate* msg);
|
||||
static NWC24Err WriteXWiiAltNameField(NWC24MsgObjPrivate* msg);
|
||||
static NWC24Err WriteMIMEAttachHeader(NWC24MsgObjPrivate* msg, u32 index);
|
||||
static NWC24Err WriteContentTypeField(NWC24MsgObjPrivate* msg);
|
||||
static NWC24Err WritePlainText(NWC24MsgObjPrivate* msg);
|
||||
static NWC24Err WriteBase64Data(const u8* data, s32 size, u32* length);
|
||||
static NWC24Err WriteQPData(const u8* data, s32 size, u32* length);
|
||||
NWC24Err NWC24iMBoxOpenNewMsg(NWC24MBoxType type, NWC24File* file, u32* id);
|
||||
NWC24Err NWC24iMBoxCloseMsg(NWC24File* file);
|
||||
NWC24Err NWC24iMBoxAddMsgObj(NWC24MBoxType type, NWC24MsgObjPrivate* msg);
|
||||
NWC24Err NWC24iMBoxCancelMsg(NWC24File* file, NWC24MBoxType type, u32 id);
|
||||
NWC24Err NWC24iMBoxFlushHeader(NWC24MBoxType type);
|
||||
NWC24Err NWC24iMBoxCheck(NWC24MBoxType type, u32 size);
|
||||
NWC24Err NWC24iDateToMinutes(u32* minutes, const NWC24Date* date);
|
||||
NWC24Err NWC24iMinutesToDate(NWC24Date* date, u32 minutes);
|
||||
|
||||
static inline NWC24Err WriteString(NWC24MsgObjPrivate* msg, char* buffer) {
|
||||
NWC24Err err;
|
||||
s32 length;
|
||||
length = Mail_strlen(buffer);
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += length;
|
||||
return err;
|
||||
}
|
||||
|
||||
#define CHECK_WRITE(operation) \
|
||||
do { \
|
||||
err = (operation); \
|
||||
if (err != NWC24_OK) { \
|
||||
NWC24FClose(&file); \
|
||||
result = err; \
|
||||
goto finish; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static inline NWC24Err WriteSubjectField(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
s32 length;
|
||||
NWC24Err err;
|
||||
if (msg->subject.size == 0)
|
||||
return NWC24_ERR_NULL;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_strcpy(buffer, "Subject: ");
|
||||
Mail_strncat(buffer, msg->subject.ptr, 1021);
|
||||
Mail_strncat(buffer, "\r\n", 1024);
|
||||
length = STD_strnlen(buffer, 1024);
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += length;
|
||||
return err;
|
||||
}
|
||||
|
||||
static inline NWC24Err WriteSMTPData(NWC24MsgObjPrivate* msg, const char* text) {
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
s32 length;
|
||||
NWC24Err err;
|
||||
Mail_strcpy(buffer, text);
|
||||
length = Mail_strlen(buffer);
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += 6;
|
||||
return err;
|
||||
}
|
||||
|
||||
static inline NWC24Err WriteCmdField(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer;
|
||||
s32 length;
|
||||
NWC24Err err;
|
||||
if (msg->ledPattern == 0)
|
||||
return NWC24_OK;
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_sprintf(buffer, "X-Wii-Cmd: %08X\r\n", msg->ledPattern);
|
||||
length = Mail_strlen(buffer);
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += length;
|
||||
return err;
|
||||
}
|
||||
|
||||
static inline NWC24Err WriteTagField(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer;
|
||||
s32 length;
|
||||
NWC24Err err;
|
||||
if (msg->tag == 0)
|
||||
return NWC24_OK;
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_sprintf(buffer, "X-Wii-Tag: %08X\r\n", msg->tag);
|
||||
length = Mail_strlen(buffer);
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += length;
|
||||
return err;
|
||||
}
|
||||
|
||||
static inline NWC24Err WriteDWCIdField(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer;
|
||||
s32 length;
|
||||
NWC24Err err;
|
||||
if (!(msg->type & 0x2000))
|
||||
return NWC24_OK;
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_sprintf(buffer, "X-Wii-DWCId: %08X\r\n", msg->dwcId);
|
||||
length = Mail_strlen(buffer);
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += length;
|
||||
return err;
|
||||
}
|
||||
|
||||
static inline NWC24Err WriteIconNewField(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer;
|
||||
s32 length;
|
||||
NWC24Err err;
|
||||
if (msg->iconNew == 0 || msg->iconNew == 0x80000000)
|
||||
return NWC24_OK;
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_sprintf(buffer, "X-Wii-IconNew: %08X\r\n", msg->iconNew);
|
||||
length = Mail_strlen(buffer);
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += length;
|
||||
return err;
|
||||
}
|
||||
|
||||
static inline NWC24Err WriteMessageIdField(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
const char* domain;
|
||||
NWC24UserId myId;
|
||||
char idText[32];
|
||||
NWC24Err err;
|
||||
s32 length;
|
||||
domain = NWC24GetAccountDomain();
|
||||
NWC24GetMyUserId(&myId);
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_strcpy(buffer, "Message-Id: <");
|
||||
Mail_memset(idText, 0, 32);
|
||||
Mail_sprintf(idText, "%05X%08X%08X%08X", msg->msgId, (u32)(myId >> 32), (u32)myId, msg->unk_0x28);
|
||||
Mail_strcat(buffer, idText);
|
||||
Mail_strcat(buffer, domain);
|
||||
Mail_strcat(buffer, ">\r\n");
|
||||
length = Mail_strlen(buffer);
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += length;
|
||||
return err;
|
||||
}
|
||||
|
||||
NWC24Err NWC24CommitMsg(NWC24MsgObj* object) {
|
||||
BOOL loopback = FALSE;
|
||||
NWC24MsgObjPrivate* msg = (NWC24MsgObjPrivate*)object;
|
||||
NWC24UserId myId;
|
||||
if (!NWC24IsMsgLibOpened() && !NWC24IsMsgLibOpenedByTool())
|
||||
return NWC24_ERR_LIB_NOT_OPENED;
|
||||
if (!(msg->type & 0x100) || (msg->type & 0x200))
|
||||
return NWC24_ERR_PROTECTED;
|
||||
if (LoopBackEnable && (msg->type & 1)) {
|
||||
NWC24GetMyUserId(&myId);
|
||||
if (msg->numTo == 1 && msg->toIds[0] == myId)
|
||||
loopback = TRUE;
|
||||
}
|
||||
return NWC24CommitMsgInternal(msg, loopback);
|
||||
}
|
||||
|
||||
static inline NWC24Err WriteMBNoReplyField(NWC24MsgObjPrivate* msg) {
|
||||
u32 flags = msg->msgBoardFlags.raw & 0x80000000;
|
||||
char* buffer;
|
||||
s32 length;
|
||||
NWC24Err err;
|
||||
if (!flags)
|
||||
return NWC24_OK;
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_strcpy(buffer, "X-Wii-MB-NoReply: -\r\n");
|
||||
length = 21;
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += length;
|
||||
return err;
|
||||
}
|
||||
|
||||
static inline NWC24Err WriteMBRegDateField(NWC24MsgObjPrivate* msg, u32 flags) {
|
||||
NWC24Err err;
|
||||
s32 length;
|
||||
char* buffer;
|
||||
if (!flags)
|
||||
return NWC24_OK;
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_sprintf(buffer, "X-Wii-MB-RegDate: %04X\r\n", flags);
|
||||
length = STD_strnlen(buffer, 1024);
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += length;
|
||||
return err;
|
||||
}
|
||||
|
||||
static inline NWC24Err WriteMBDelayField(NWC24MsgObjPrivate* msg, u32 flags) {
|
||||
NWC24Err err;
|
||||
s32 length;
|
||||
char* buffer;
|
||||
if (!flags)
|
||||
return NWC24_OK;
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_sprintf(buffer, "X-Wii-MB-Delay: %02X\r\n", flags >> 16);
|
||||
length = STD_strnlen(buffer, 1024);
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += length;
|
||||
return err;
|
||||
}
|
||||
|
||||
static inline NWC24Err WriteExtraFields(NWC24MsgObjPrivate* msg) {
|
||||
NWC24Err err;
|
||||
if (msg->unk_0xD0.size == 0)
|
||||
return NWC24_OK;
|
||||
err = NWC24FWrite(msg->unk_0xD0.ptr, msg->unk_0xD0.size, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += msg->unk_0xD0.size;
|
||||
return err;
|
||||
}
|
||||
|
||||
static NWC24Err NWC24CommitMsgInternal(NWC24MsgObjPrivate* msg, NWC24MBoxType type) {
|
||||
NWC24File file;
|
||||
NWC24Data attached[2];
|
||||
NWC24Data subject;
|
||||
NWC24Data text;
|
||||
u32 id, encodedLength;
|
||||
s32 initIndex;
|
||||
u32 index;
|
||||
char* buffer;
|
||||
NWC24Err result, err;
|
||||
NWC24Data_Init(&subject);
|
||||
NWC24Data_Init(&text);
|
||||
for (initIndex = 0; initIndex < 2; ++initIndex)
|
||||
NWC24Data_Init(&attached[initIndex]);
|
||||
NWC24iSetErrorCode(0);
|
||||
result = CheckMsgObject(msg);
|
||||
if (result != NWC24_OK)
|
||||
goto report;
|
||||
result = CheckMsgBoxSpace(msg, type);
|
||||
if (result != NWC24_OK)
|
||||
goto report;
|
||||
err = NWC24iMBoxOpenNewMsg(type, &file, &id);
|
||||
if (err != NWC24_OK) {
|
||||
result = err;
|
||||
goto finish;
|
||||
}
|
||||
{
|
||||
msg->msgId = id;
|
||||
msg->length = 0;
|
||||
m_pFile = &file;
|
||||
if (type == NWC24_MBOX_TYPE_SEND) {
|
||||
CHECK_WRITE(WriteSMTP_MAILFROM(msg));
|
||||
CHECK_WRITE(WriteSMTP_RCPTTO(msg));
|
||||
CHECK_WRITE(WriteSMTPData(msg, "DATA\r\n"));
|
||||
}
|
||||
CHECK_WRITE(WriteDateField(msg));
|
||||
CHECK_WRITE(WriteFromField(msg));
|
||||
CHECK_WRITE(WriteToField(msg));
|
||||
CHECK_WRITE(WriteMessageIdField(msg));
|
||||
subject.ptr = (const void*)(msg->length + 9);
|
||||
err = WriteSubjectField(msg);
|
||||
if (err == NWC24_OK)
|
||||
subject.size = msg->length - (u32)subject.ptr - 2;
|
||||
else if (err == NWC24_ERR_NULL) {
|
||||
err = NWC24_OK;
|
||||
subject.ptr = NULL;
|
||||
}
|
||||
if (err != NWC24_OK) {
|
||||
NWC24FClose(&file);
|
||||
result = err;
|
||||
goto finish;
|
||||
}
|
||||
if (msg->type & 1) {
|
||||
CHECK_WRITE(WriteXWiiAppIdField(msg));
|
||||
CHECK_WRITE(WriteCmdField(msg));
|
||||
CHECK_WRITE(WriteTagField(msg));
|
||||
CHECK_WRITE(WriteDWCIdField(msg));
|
||||
CHECK_WRITE(WriteXWiiAltNameField(msg));
|
||||
CHECK_WRITE(WriteXWiiFaceField(msg));
|
||||
CHECK_WRITE(WriteIconNewField(msg));
|
||||
if (msg->msgBoardFlags.raw != 0) {
|
||||
CHECK_WRITE(WriteMBNoReplyField(msg));
|
||||
CHECK_WRITE(WriteMBRegDateField(msg, msg->msgBoardFlags.raw & 0xFFFF));
|
||||
CHECK_WRITE(WriteMBDelayField(msg, msg->msgBoardFlags.raw & 0xFF0000));
|
||||
}
|
||||
}
|
||||
CHECK_WRITE(WriteExtraFields(msg));
|
||||
Mail_memset(MultiPartDivider, 0, 40);
|
||||
Mail_sprintf(MultiPartDivider, "Boundary-NWC24-%08X%05X", msg->unk_0x28, msg->msgId);
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_strcpy(buffer, "MIME-Version: 1.0\r\n");
|
||||
if (msg->type & 0x10000) {
|
||||
Mail_strcat(buffer, "Content-Type: multipart/mixed;\r\n boundary=\"");
|
||||
Mail_strcat(buffer, MultiPartDivider);
|
||||
Mail_strcat(buffer, "\"\r\n");
|
||||
}
|
||||
CHECK_WRITE(WriteString(msg, buffer));
|
||||
if (msg->type & 0x10000) {
|
||||
msg->unk_0x10 = msg->length;
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_sprintf(buffer, "\r\n--%s", MultiPartDivider);
|
||||
Mail_strcat(buffer, "\r\n");
|
||||
CHECK_WRITE(WriteString(msg, buffer));
|
||||
}
|
||||
CHECK_WRITE(WriteContentTypeField(msg));
|
||||
if (!(msg->type & 0x10000))
|
||||
msg->unk_0x10 = msg->length;
|
||||
text.ptr = (const void*)msg->length;
|
||||
err = WritePlainText(msg);
|
||||
if (err == NWC24_ERR_NULL)
|
||||
err = NWC24_OK;
|
||||
if (err != NWC24_OK) {
|
||||
NWC24FClose(&file);
|
||||
result = err;
|
||||
goto finish;
|
||||
}
|
||||
text.size = msg->length - (u32)text.ptr;
|
||||
for (index = 0; index < msg->numAttached; ++index) {
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_sprintf(buffer, "\r\n--%s", MultiPartDivider);
|
||||
Mail_strcat(buffer, "\r\n");
|
||||
CHECK_WRITE(WriteString(msg, buffer));
|
||||
CHECK_WRITE(WriteMIMEAttachHeader(msg, index));
|
||||
attached[index].ptr = (const void*)msg->length;
|
||||
err = WriteBase64Data(msg->attached[index].ptr, msg->attached[index].size, &encodedLength);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += encodedLength;
|
||||
if (err != NWC24_OK) {
|
||||
NWC24FClose(&file);
|
||||
result = err;
|
||||
goto finish;
|
||||
}
|
||||
attached[index].size = msg->length - (u32)attached[index].ptr;
|
||||
if ((s32)index == msg->numAttached - 1) {
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_sprintf(buffer, "\r\n--%s", MultiPartDivider);
|
||||
Mail_strcat(buffer, "--\r\n");
|
||||
CHECK_WRITE(WriteString(msg, buffer));
|
||||
}
|
||||
}
|
||||
}
|
||||
finish:
|
||||
if (result == NWC24_OK) {
|
||||
NWC24iMBoxCloseMsg(&file);
|
||||
} else {
|
||||
NWC24iMBoxCancelMsg(&file, type, id);
|
||||
NWC24iMBoxFlushHeader(type);
|
||||
goto report;
|
||||
}
|
||||
{
|
||||
msg->subject = subject;
|
||||
msg->text = text;
|
||||
msg->attached[0] = attached[0];
|
||||
msg->attached[1] = attached[1];
|
||||
msg->type |= 0x200;
|
||||
if (type == NWC24_MBOX_TYPE_RECV)
|
||||
msg->type |= 0x20;
|
||||
else if (type == NWC24_MBOX_TYPE_SEND)
|
||||
msg->type |= 0x10;
|
||||
err = NWC24iMBoxAddMsgObj(type, msg);
|
||||
if (result != NWC24_OK)
|
||||
err = result;
|
||||
result = err;
|
||||
if (type == NWC24_MBOX_TYPE_RECV) {
|
||||
u32 flags = 1;
|
||||
if (msg->type & 8)
|
||||
flags |= 2;
|
||||
NWC24iSetNewMsgArrived(flags);
|
||||
}
|
||||
}
|
||||
report:
|
||||
if (result == NWC24_ERR_FULL || (result <= -16 && result >= -21) || result == -38 || result == -41 || result == -43 || result == -46)
|
||||
NWC24iSetErrorCode(result - 109300);
|
||||
return result;
|
||||
}
|
||||
|
||||
static NWC24Err CheckMsgObject(const NWC24MsgObjPrivate* msg) {
|
||||
const char* subject;
|
||||
if (msg->numTo == 0)
|
||||
return NWC24_ERR_NULL;
|
||||
if (msg->numTo > 8)
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
subject = msg->subject.ptr;
|
||||
if (subject != NULL) {
|
||||
for (; *subject != '\0'; ++subject) {
|
||||
if (*subject == '\r' && subject[1] != '\n')
|
||||
return NWC24_ERR_FORMAT;
|
||||
if (*subject == '\n' && subject[1] != ' ')
|
||||
return NWC24_ERR_FORMAT;
|
||||
}
|
||||
}
|
||||
if (msg->numAttached > 2)
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
return NWC24_OK;
|
||||
}
|
||||
|
||||
static NWC24Err CheckMsgBoxSpace(const NWC24MsgObjPrivate* msg, NWC24MBoxType type) {
|
||||
u32 total = 0;
|
||||
u32 textSize = 0;
|
||||
s32 index;
|
||||
NWC24Err err;
|
||||
for (index = 0; index < msg->numAttached; ++index) {
|
||||
u32 size = msg->attachedSize[index];
|
||||
total += (size * 4 + 2) / 3 + size / 57 * 2 + 4;
|
||||
}
|
||||
switch (msg->encoding) {
|
||||
case NWC24_ENC_7BIT:
|
||||
case NWC24_ENC_8BIT:
|
||||
textSize = msg->text.size;
|
||||
break;
|
||||
case NWC24_ENC_BASE64:
|
||||
textSize = (msg->text.size * 4 + 2) / 3 + msg->text.size / 57 * 2 + 4;
|
||||
break;
|
||||
case NWC24_ENC_QUOTED_PRINTABLE:
|
||||
textSize = msg->text.size * 4 / 3;
|
||||
break;
|
||||
default:
|
||||
textSize = 0;
|
||||
break;
|
||||
}
|
||||
total += textSize;
|
||||
if (total >= 0x31C00)
|
||||
return NWC24_ERR_OVERFLOW;
|
||||
err = NWC24iMBoxCheck(type, total + 1024);
|
||||
if (err != NWC24_OK)
|
||||
return err;
|
||||
return NWC24_OK;
|
||||
}
|
||||
|
||||
static NWC24Err SynthesizeAddrStr(const NWC24Data* address, u32 type, char* dest, s32 capacity, u32* length) {
|
||||
char id[32];
|
||||
NWC24Err err = NWC24_OK;
|
||||
const char* domain;
|
||||
s32 domainLength, written;
|
||||
if (type & 1) {
|
||||
domain = NWC24GetAccountDomain();
|
||||
domainLength = Mail_strlen(domain);
|
||||
if (domainLength <= 0)
|
||||
err = NWC24_ERR_CONFIG;
|
||||
else if (domainLength + 18 >= capacity)
|
||||
err = NWC24_ERR_NOMEM;
|
||||
else {
|
||||
NWC24iConvIdToStr(*(const NWC24UserId*)address, id);
|
||||
written = Mail_sprintf(dest, "%c%s%s", 'w', id, domain);
|
||||
if (written == 0)
|
||||
err = NWC24_ERR_FATAL;
|
||||
else
|
||||
*length = written;
|
||||
}
|
||||
} else if (type & 2) {
|
||||
if (address->size + 3 >= (u32)capacity)
|
||||
err = NWC24_ERR_NOMEM;
|
||||
else {
|
||||
written = Mail_sprintf(dest, "%s", address->ptr);
|
||||
if (written == 0)
|
||||
err = NWC24_ERR_FATAL;
|
||||
else
|
||||
*length = written;
|
||||
}
|
||||
} else
|
||||
err = NWC24_ERR_INVALID_VALUE;
|
||||
return err;
|
||||
}
|
||||
|
||||
static NWC24Err WriteSMTP_MAILFROM(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
char* address;
|
||||
u32 length;
|
||||
s32 total;
|
||||
u32 type;
|
||||
NWC24Err err;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_strncat(buffer, "MAIL FROM: ", 1022);
|
||||
address = buffer + 11;
|
||||
type = 1;
|
||||
if (msg->type & 0x100000)
|
||||
type = 2;
|
||||
err = SynthesizeAddrStr(&msg->fromAddr, type, address, 1009, &length);
|
||||
if (err != NWC24_OK)
|
||||
return err;
|
||||
{
|
||||
address += length;
|
||||
address[0] = '\r';
|
||||
address[1] = '\n';
|
||||
total = length + 13;
|
||||
if ((s32)(1009 - length) <= 0)
|
||||
return NWC24_ERR_NOMEM;
|
||||
}
|
||||
if (err == NWC24_OK) {
|
||||
err = NWC24FWrite(NWC24WorkP->stringWork, total, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += total;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static NWC24Err WriteSMTP_RCPTTO(NWC24MsgObjPrivate* msg) {
|
||||
char* cursor = NWC24WorkP->stringWork;
|
||||
u32 index;
|
||||
s32 total = 0, remaining;
|
||||
u32 length;
|
||||
NWC24Err err = NWC24_OK;
|
||||
Mail_memset(cursor, 0, 1024);
|
||||
remaining = 1022;
|
||||
for (index = 0; index < msg->numTo; ++index) {
|
||||
Mail_strncat(cursor, "RCPT TO: ", remaining);
|
||||
cursor += 9;
|
||||
remaining -= 11;
|
||||
err = SynthesizeAddrStr(&msg->toAddrs[index], msg->type, cursor, remaining, &length);
|
||||
if (err != NWC24_OK)
|
||||
break;
|
||||
cursor += length;
|
||||
cursor[0] = '\r';
|
||||
cursor[1] = '\n';
|
||||
cursor += 2;
|
||||
remaining -= length;
|
||||
total += length + 11;
|
||||
if (remaining <= 0) {
|
||||
err = NWC24_ERR_NOMEM;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (err == NWC24_OK) {
|
||||
err = NWC24FWrite(NWC24WorkP->stringWork, total, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += total;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static NWC24Err WriteFromField(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
char* address;
|
||||
u32 length;
|
||||
s32 total;
|
||||
u32 type;
|
||||
NWC24Err err;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_strncat(buffer, "From: ", 1022);
|
||||
address = buffer + 6;
|
||||
msg->unk_0x30.ptr = (const void*)(msg->length + 6);
|
||||
type = 1;
|
||||
if (msg->type & 0x100000)
|
||||
type = 2;
|
||||
err = SynthesizeAddrStr(&msg->fromAddr, type, address, 1014, &length);
|
||||
if (err != NWC24_OK)
|
||||
return err;
|
||||
{
|
||||
address += length;
|
||||
address[0] = '\r';
|
||||
address[1] = '\n';
|
||||
total = length + 8;
|
||||
if ((s32)(1014 - length) <= 0)
|
||||
return NWC24_ERR_NOMEM;
|
||||
}
|
||||
if (err == NWC24_OK) {
|
||||
err = NWC24FWrite(NWC24WorkP->stringWork, total, m_pFile);
|
||||
if (err == NWC24_OK) {
|
||||
msg->length += total;
|
||||
msg->unk_0x30.size = msg->length - (u32)msg->unk_0x30.ptr - 2;
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static NWC24Err WriteToField(NWC24MsgObjPrivate* msg) {
|
||||
char* cursor = NWC24WorkP->stringWork;
|
||||
s32 index, total, remaining;
|
||||
u32 length;
|
||||
NWC24Err err = NWC24_OK;
|
||||
Mail_memset(cursor, 0, 1024);
|
||||
Mail_strncat(cursor, "To: ", 1022);
|
||||
cursor += 4;
|
||||
index = 0;
|
||||
total = 4;
|
||||
msg->unk_0x38.ptr = (const void*)(msg->length + 4);
|
||||
remaining = 1018;
|
||||
for (; index < msg->numTo; ++index) {
|
||||
err = SynthesizeAddrStr(&msg->toAddrs[index], msg->type, cursor, remaining, &length);
|
||||
if (err != NWC24_OK)
|
||||
break;
|
||||
remaining -= length;
|
||||
cursor += length;
|
||||
total += length;
|
||||
if (remaining <= 4) {
|
||||
err = NWC24_ERR_NOMEM;
|
||||
break;
|
||||
}
|
||||
if (index < msg->numTo - 1) {
|
||||
cursor[0] = ',';
|
||||
cursor[1] = '\r';
|
||||
cursor[2] = '\n';
|
||||
cursor[3] = ' ';
|
||||
total += 4;
|
||||
remaining -= 4;
|
||||
cursor += 4;
|
||||
}
|
||||
}
|
||||
cursor[0] = '\r';
|
||||
cursor[1] = '\n';
|
||||
if (err == NWC24_OK) {
|
||||
err = NWC24FWrite(NWC24WorkP->stringWork, total + 2, m_pFile);
|
||||
if (err == NWC24_OK) {
|
||||
msg->length += total + 2;
|
||||
msg->unk_0x38.size = msg->length - (u32)msg->unk_0x38.ptr - 2;
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static NWC24Err WriteDateField(NWC24MsgObjPrivate* msg) {
|
||||
static const char* months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
NWC24Date date;
|
||||
OSCalendarTime calendar;
|
||||
char* buffer;
|
||||
s32 length;
|
||||
NWC24Err err;
|
||||
NWC24Date_Init(&date);
|
||||
NETGetUniversalCalendar(&calendar);
|
||||
date.year = calendar.year;
|
||||
date.month = calendar.mon + 1;
|
||||
date.day = calendar.mday;
|
||||
date.hour = calendar.hour;
|
||||
date.min = calendar.min;
|
||||
date.sec = calendar.sec;
|
||||
if (date.month > 12)
|
||||
return NWC24_ERR_FORMAT;
|
||||
NWC24iDateToMinutes(&msg->unk_0x28, &date);
|
||||
if (msg->type & 0x1000000)
|
||||
NWC24iMinutesToDate(&date, msg->unk_0x2C);
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_sprintf(buffer, "Date: %02d %s %d %02d:%02d:%02d -0000\r\n", date.day, months[date.month - 1], date.year, date.hour, date.min, date.sec);
|
||||
length = Mail_strlen(buffer);
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += length;
|
||||
return err;
|
||||
}
|
||||
|
||||
static NWC24Err WriteXWiiAppIdField(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
char appIdText[16];
|
||||
u32 type = 0;
|
||||
s32 length;
|
||||
NWC24Err err;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_strcpy(buffer, "X-Wii-AppId: ");
|
||||
if (!NWC24IsMsgLibOpenedByTool() && NWC24GetAppId() != 0x48414541 && msg->appId != 0x48414341)
|
||||
msg->appId = NWC24GetAppId();
|
||||
if (msg->type & 4)
|
||||
type |= 1;
|
||||
if (msg->type & 8)
|
||||
type |= 2;
|
||||
Mail_memset(appIdText, 0, 16);
|
||||
Mail_sprintf(appIdText, "%d-%08X-%04X\r\n", type, msg->appId, msg->groupId);
|
||||
Mail_strcat(buffer, appIdText);
|
||||
length = Mail_strlen(buffer);
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += length;
|
||||
return err;
|
||||
}
|
||||
|
||||
static NWC24Err WriteXWiiFaceField(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer;
|
||||
const u8* data;
|
||||
s32 offset, remaining, chunk;
|
||||
u32 length;
|
||||
NWC24Err err;
|
||||
if (msg->faceData.size == 0)
|
||||
return NWC24_OK;
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_strcpy(buffer, "X-WiiFace:");
|
||||
data = msg->faceData.ptr;
|
||||
offset = 10;
|
||||
for (remaining = msg->faceData.size; remaining > 0; remaining -= chunk) {
|
||||
buffer[offset++] = ' ';
|
||||
chunk = remaining;
|
||||
if (remaining > 42)
|
||||
chunk = 42;
|
||||
NWC24Base64Encode((u8*)data, chunk, (u8*)(buffer + offset), 76, &length);
|
||||
data += chunk;
|
||||
offset += length;
|
||||
buffer[offset++] = '\r';
|
||||
buffer[offset++] = '\n';
|
||||
}
|
||||
err = NWC24FWrite(buffer, offset, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += offset;
|
||||
return err;
|
||||
}
|
||||
|
||||
static NWC24Err WriteXWiiAltNameField(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer;
|
||||
const u8* data;
|
||||
s32 offset, remaining, chunk;
|
||||
u32 length;
|
||||
NWC24Err err;
|
||||
if (msg->altName.size == 0)
|
||||
return NWC24_OK;
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
Mail_strcpy(buffer, "X-Wii-AltName:");
|
||||
data = msg->altName.ptr;
|
||||
offset = 14;
|
||||
for (remaining = msg->altName.size; remaining > 0; remaining -= chunk) {
|
||||
buffer[offset++] = ' ';
|
||||
chunk = remaining;
|
||||
if (remaining > 42)
|
||||
chunk = 42;
|
||||
NWC24Base64Encode((u8*)data, chunk, (u8*)(buffer + offset), 76, &length);
|
||||
data += chunk;
|
||||
offset += length;
|
||||
buffer[offset++] = '\r';
|
||||
buffer[offset++] = '\n';
|
||||
}
|
||||
err = NWC24FWrite(buffer, offset, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += offset;
|
||||
return err;
|
||||
}
|
||||
|
||||
const char* ContentTypeA = "Content-Type: %s;\r\n name=%c%07d.%s\r\n";
|
||||
const char* ContentTxEncA = "Content-Transfer-Encoding: base64\r\n";
|
||||
const char* ContentDispA = "Content-Disposition: attachment;\r\n filename=%c%07d.%s\r\n\r\n";
|
||||
|
||||
static NWC24Err WriteMIMEAttachHeader(NWC24MsgObjPrivate* msg, u32 index) {
|
||||
char* buffer;
|
||||
const char* mime;
|
||||
const char* suffix;
|
||||
s32 typeLength, encodingLength, dispositionLength, mimeLength;
|
||||
s32 first, second, third, total;
|
||||
NWC24Err err;
|
||||
Mail_memset(NWC24WorkP->stringWork, 0, 1024);
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
mime = NWC24GetMIMETypeStr(msg->attachedType[index]);
|
||||
suffix = NWC24iGetMIMETypeSuffix(msg->attachedType[index]);
|
||||
encodingLength = Mail_strlen(ContentTxEncA);
|
||||
typeLength = Mail_strlen(ContentTypeA);
|
||||
dispositionLength = Mail_strlen(ContentDispA);
|
||||
typeLength += encodingLength;
|
||||
mimeLength = Mail_strlen(mime);
|
||||
mimeLength = (dispositionLength + typeLength) + mimeLength + 4;
|
||||
if (mimeLength >= 1024)
|
||||
return NWC24_ERR_NOMEM;
|
||||
first = Mail_sprintf(buffer, (char*)ContentTypeA, mime, (char)('a' + index), msg->msgId, suffix);
|
||||
if (first <= 0)
|
||||
return NWC24_ERR_FAILED;
|
||||
buffer += first;
|
||||
second = Mail_sprintf(buffer, (char*)ContentTxEncA);
|
||||
if (second <= 0)
|
||||
return NWC24_ERR_FAILED;
|
||||
buffer += second;
|
||||
total = first + second;
|
||||
third = Mail_sprintf(buffer, (char*)ContentDispA, (char)('a' + index), msg->msgId, suffix);
|
||||
if (third <= 0)
|
||||
return NWC24_ERR_FAILED;
|
||||
total += third;
|
||||
err = NWC24FWrite(NWC24WorkP->stringWork, total, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += total;
|
||||
return err;
|
||||
}
|
||||
|
||||
const char* ContentTypeTP = "Content-Type: text/plain; charset=%s\r\n";
|
||||
const char* ContentTxEncT = "Content-Transfer-Encoding: %s\r\n\r\n";
|
||||
|
||||
static NWC24Err WriteContentTypeField(NWC24MsgObjPrivate* msg) {
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
const char* name;
|
||||
const char* encoding;
|
||||
s32 total = 0;
|
||||
NWC24Err err;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
name = NWC24GetCharsetStr(msg->charset);
|
||||
if (name != NULL) {
|
||||
Mail_sprintf(buffer, (char*)ContentTypeTP, name);
|
||||
msg->unk_0x50.ptr = (const void*)(msg->length + 34);
|
||||
msg->unk_0x50.size = Mail_strlen(name) + 1;
|
||||
total = Mail_strlen(buffer);
|
||||
buffer += total;
|
||||
}
|
||||
encoding = NWC24GetEncodingStr(msg->encoding);
|
||||
if (encoding != NULL) {
|
||||
Mail_sprintf(buffer, (char*)ContentTxEncT, encoding);
|
||||
msg->unk_0x58.ptr = (const void*)(total + msg->length + 27);
|
||||
msg->unk_0x58.size = Mail_strlen(encoding) + 1;
|
||||
total += Mail_strlen(buffer);
|
||||
}
|
||||
if (total == 0)
|
||||
return NWC24_OK;
|
||||
err = NWC24FWrite(NWC24WorkP->stringWork, total, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
msg->length += total;
|
||||
return err;
|
||||
}
|
||||
|
||||
static NWC24Err WritePlainText(NWC24MsgObjPrivate* msg) {
|
||||
u32 length;
|
||||
NWC24Err err;
|
||||
if (msg->text.size == 0)
|
||||
return NWC24_ERR_NULL;
|
||||
switch (msg->encoding) {
|
||||
case NWC24_ENC_7BIT:
|
||||
case NWC24_ENC_8BIT:
|
||||
err = NWC24FWrite(msg->text.ptr, msg->text.size, m_pFile);
|
||||
length = msg->text.size;
|
||||
break;
|
||||
case NWC24_ENC_BASE64:
|
||||
err = WriteBase64Data(msg->text.ptr, msg->text.size, &length);
|
||||
break;
|
||||
case NWC24_ENC_QUOTED_PRINTABLE:
|
||||
err = WriteQPData(msg->text.ptr, msg->text.size, &length);
|
||||
break;
|
||||
default:
|
||||
err = NWC24_ERR_INVALID_VALUE;
|
||||
break;
|
||||
}
|
||||
if (err == NWC24_OK) {
|
||||
msg->textSize = msg->text.size;
|
||||
msg->length += length;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static NWC24Err WriteBase64Data(const u8* data, s32 size, u32* totalLength) {
|
||||
const u8* cursor = data;
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
u32 length;
|
||||
u32 total = 0;
|
||||
NWC24Err err = NWC24_OK;
|
||||
while (size >= 57) {
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
err = NWC24Base64Encode((u8*)cursor, 57, (u8*)buffer, 76, &length);
|
||||
if (err != NWC24_OK)
|
||||
break;
|
||||
buffer[length++] = '\r';
|
||||
buffer[length++] = '\n';
|
||||
buffer[length] = '\0';
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err != NWC24_OK)
|
||||
break;
|
||||
cursor += 57;
|
||||
size -= 57;
|
||||
total += length;
|
||||
}
|
||||
if (err == NWC24_OK) {
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
err = NWC24Base64Encode((u8*)cursor, size, (u8*)buffer, 76, &length);
|
||||
if (err == NWC24_OK) {
|
||||
buffer[length++] = '\r';
|
||||
buffer[length++] = '\n';
|
||||
buffer[length++] = '\r';
|
||||
buffer[length++] = '\n';
|
||||
buffer[length] = '\0';
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err == NWC24_OK)
|
||||
total += length;
|
||||
}
|
||||
}
|
||||
*totalLength = total;
|
||||
return err;
|
||||
}
|
||||
|
||||
static NWC24Err WriteQPData(const u8* data, s32 size, u32* totalLength) {
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
const u8* cursor = data;
|
||||
s32 remaining = size;
|
||||
s32 total = 0;
|
||||
u32 consumed, length;
|
||||
NWC24Err err = NWC24_OK;
|
||||
for (; remaining > 0; remaining -= consumed) {
|
||||
if (total > 0) {
|
||||
Mail_memcpy(buffer, "=\r\n", 3);
|
||||
err = NWC24FWrite(buffer, 3, m_pFile);
|
||||
if (err != NWC24_OK)
|
||||
break;
|
||||
total += 3;
|
||||
}
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
err = NWC24EncodeQuotedPrintable(buffer, 1024, &length, (u8*)cursor, remaining, &consumed);
|
||||
if (err != NWC24_OK && err != NWC24_ERR_OVERFLOW)
|
||||
break;
|
||||
err = NWC24FWrite(buffer, length, m_pFile);
|
||||
if (err != NWC24_OK)
|
||||
break;
|
||||
cursor += consumed;
|
||||
total += length;
|
||||
}
|
||||
*totalLength = total;
|
||||
return err;
|
||||
}
|
||||
599
libs/RevoEX/src/nwc24/NWC24MsgRead.c
Normal file
599
libs/RevoEX/src/nwc24/NWC24MsgRead.c
Normal file
@@ -0,0 +1,599 @@
|
||||
#define NWC24_MSG_READ
|
||||
#include <private/nwc24.h>
|
||||
|
||||
NWC24Err NWC24iMBoxOpenStoredMsg(NWC24MBoxType type, u32 id, NWC24File* file);
|
||||
NWC24Err NWC24iMBoxCloseMsg(NWC24File* file);
|
||||
BOOL Mail_isdigit(int character);
|
||||
static NWC24Err ReadMsgTextInternal(const NWC24MsgObj* msg, char* text, u32 capacity, char* charset, u32 charsetCapacity, NWC24Encoding* encoding);
|
||||
NWC24Err ReadBase64Data(NWC24File* file, const NWC24Data* data, u8* output, u32 capacity, u32* outputSize);
|
||||
NWC24Err ReadQPText(const NWC24MsgObjPrivate* msg, NWC24File* file, char* output, u32 capacity);
|
||||
|
||||
static inline NWC24Err SelectMBox(const NWC24MsgObjPrivate* msg, NWC24MBoxType* type) {
|
||||
if (msg->type & 0x10)
|
||||
*type = NWC24_MBOX_TYPE_SEND;
|
||||
else if (msg->type & 0x20)
|
||||
*type = NWC24_MBOX_TYPE_RECV;
|
||||
else
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
return NWC24_OK;
|
||||
}
|
||||
|
||||
NWC24Err NWC24ReadMsgField(const NWC24MsgObj* msg, char* fieldName, u8* output, u32 capacity) {
|
||||
const NWC24MsgObjPrivate* privateMsg = (const NWC24MsgObjPrivate*)msg;
|
||||
NWC24File file;
|
||||
NWC24FileStream stream;
|
||||
char* field;
|
||||
u32 offset;
|
||||
u32 length;
|
||||
NWC24MBoxType type;
|
||||
NWC24Err result;
|
||||
NWC24Err closeResult;
|
||||
if (!NWC24IsMsgLibOpened() && !NWC24IsMsgLibOpenedByTool())
|
||||
return NWC24_ERR_LIB_NOT_OPENED;
|
||||
if (!(privateMsg->type & 0x200))
|
||||
return NWC24_ERR_PROTECTED;
|
||||
result = SelectMBox(privateMsg, &type);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
break;
|
||||
default:
|
||||
return result;
|
||||
}
|
||||
result = NWC24iMBoxOpenStoredMsg(type, privateMsg->msgId, &file);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
break;
|
||||
default:
|
||||
return result;
|
||||
}
|
||||
result = NWC24FStreamInit(&stream, &file, 0, privateMsg->length, NWC24WorkP->mainWork, 1024);
|
||||
if (result == NWC24_OK) {
|
||||
result = NWC24iSearchHeaderF(&stream, fieldName, privateMsg->headerSize, &offset, &length);
|
||||
if (result == NWC24_OK) {
|
||||
if (length > capacity)
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
else {
|
||||
result = NWC24FStreamSeek(&stream, offset);
|
||||
if (result == NWC24_OK) {
|
||||
result = NWC24FStreamGetPtr(&stream, &field, length);
|
||||
if (result == NWC24_OK) {
|
||||
Mail_strncpy((char*)output, field, length);
|
||||
output[length - 2] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
closeResult = NWC24iMBoxCloseMsg(&file);
|
||||
if (result == NWC24_OK)
|
||||
result = closeResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24ReadMsgFaceData(const NWC24MsgObj* msg, u8* faceData) {
|
||||
const NWC24MsgObjPrivate* privateMsg = (const NWC24MsgObjPrivate*)msg;
|
||||
char* buffer;
|
||||
u32 length;
|
||||
NWC24Err result;
|
||||
if ((privateMsg->type & 2) && !(privateMsg->type & 0x1000))
|
||||
return NWC24_ERR_NOT_FOUND;
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
result = NWC24ReadMsgField(msg, "x-wiiface", (u8*)buffer, 1024);
|
||||
switch (result) {
|
||||
default:
|
||||
return result;
|
||||
case NWC24_OK:
|
||||
result = NWC24Base64Decode((u8*)buffer, STD_strnlen(buffer, 1024), faceData, 74, &length);
|
||||
switch (result) {
|
||||
default:
|
||||
return result;
|
||||
case NWC24_OK:
|
||||
if (length != 74)
|
||||
return NWC24_ERR_FORMAT;
|
||||
return NWC24_OK;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24ReadMsgAltName(const NWC24MsgObj* msg, u16* name, u32 capacity) {
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
u32 length;
|
||||
NWC24Err result;
|
||||
NWC24Err decodeResult;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
result = NWC24ReadMsgField(msg, "x-wii-altname:", (u8*)buffer, 1024);
|
||||
switch (result) {
|
||||
default:
|
||||
return result;
|
||||
case NWC24_OK:
|
||||
decodeResult = NWC24Base64Decode((u8*)buffer, STD_strnlen(buffer, 1024), (u8*)name, capacity * 2, &length);
|
||||
result = NWC24_OK;
|
||||
if (decodeResult != NWC24_OK)
|
||||
result = decodeResult;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24ReadMsgMBNoReply(const NWC24MsgObj* msg, BOOL* noReply) {
|
||||
char* buffer;
|
||||
NWC24Err result;
|
||||
*noReply = FALSE;
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
result = NWC24ReadMsgField(msg, "x-wii-mb-noreply:", (u8*)buffer, 1024);
|
||||
if (result == NWC24_OK)
|
||||
*noReply = TRUE;
|
||||
else if (result == NWC24_ERR_NOT_FOUND)
|
||||
result = NWC24_OK;
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24ReadMsgMBRegDate(const NWC24MsgObj* msg, u16* year, u8* month, u8* day) {
|
||||
NWC24Err result;
|
||||
u32 offset = 0;
|
||||
u32 digits = 0;
|
||||
u32 value = 0;
|
||||
s32 digit;
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
result = NWC24ReadMsgField(msg, "x-wii-mb-regdate:", (u8*)buffer, 1023);
|
||||
switch (result) {
|
||||
default:
|
||||
return result;
|
||||
case NWC24_OK:
|
||||
break;
|
||||
}
|
||||
while (*buffer == '\t' || *buffer == ' ') {
|
||||
buffer++;
|
||||
offset++;
|
||||
}
|
||||
for (; offset < 1024; offset++, digits++) {
|
||||
digit = Util_xtoi(*buffer);
|
||||
if (digit < 0)
|
||||
break;
|
||||
value = (value << 4) | digit;
|
||||
buffer++;
|
||||
}
|
||||
if (digits != 4)
|
||||
result = NWC24_ERR_FORMAT;
|
||||
*year = ((value >> 9) & 127) + 2000;
|
||||
*month = (value >> 5) & 15;
|
||||
*day = value & 31;
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24ReadMsgMBDelay(const NWC24MsgObj* msg, u8* delay) {
|
||||
NWC24Err result;
|
||||
u32 offset = 0;
|
||||
u32 digits = 0;
|
||||
u32 value = 0;
|
||||
s32 digit;
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
result = NWC24ReadMsgField(msg, "x-wii-mb-delay:", (u8*)buffer, 1023);
|
||||
switch (result) {
|
||||
default:
|
||||
return result;
|
||||
case NWC24_OK:
|
||||
break;
|
||||
}
|
||||
while (*buffer == '\t' || *buffer == ' ') {
|
||||
buffer++;
|
||||
offset++;
|
||||
}
|
||||
for (; offset < 1024; offset++, digits++) {
|
||||
digit = Util_xtoi(*buffer);
|
||||
if (digit < 0)
|
||||
break;
|
||||
value = (value << 4) | digit;
|
||||
buffer++;
|
||||
}
|
||||
if (digits != 2)
|
||||
result = NWC24_ERR_FORMAT;
|
||||
*delay = value;
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24ReadMsgMBUpdateSW(const NWC24MsgObj* msg, u32* update) {
|
||||
NWC24Err result;
|
||||
const NWC24MsgObjPrivate* privateMsg = (const NWC24MsgObjPrivate*)msg;
|
||||
u32 value = 0;
|
||||
char* buffer;
|
||||
if (!(privateMsg->type & 0x1000)) {
|
||||
*update = 0;
|
||||
return NWC24_ERR_NOT_FOUND;
|
||||
}
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
result = NWC24ReadMsgField(msg, "x-wii-mb-updatesw:", (u8*)buffer, 1023);
|
||||
switch (result) {
|
||||
default:
|
||||
return result;
|
||||
case NWC24_OK:
|
||||
while (*buffer == '\t' || *buffer == ' ')
|
||||
buffer++;
|
||||
if (Mail_isdigit(*buffer))
|
||||
value = *buffer - '0';
|
||||
*update = value;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24ReadMsgMBOptOutFlag(const NWC24MsgObj* msg, BOOL* optOut, u32* appId) {
|
||||
NWC24Err result;
|
||||
u32 offset = 0;
|
||||
u32 digits = 0;
|
||||
u32 value = 0;
|
||||
s32 digit;
|
||||
char* buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
*optOut = FALSE;
|
||||
*appId = 0;
|
||||
result = NWC24ReadMsgField(msg, "x-wii-mb-optout:", (u8*)buffer, 1023);
|
||||
if (result == NWC24_ERR_NOT_FOUND)
|
||||
return NWC24_OK;
|
||||
switch (result) {
|
||||
default:
|
||||
return result;
|
||||
case NWC24_OK:
|
||||
while (*buffer == '\t' || *buffer == ' ') {
|
||||
buffer++;
|
||||
offset++;
|
||||
}
|
||||
if (*buffer == '1')
|
||||
*optOut = TRUE;
|
||||
{
|
||||
char separator = buffer[1];
|
||||
buffer += 2;
|
||||
if (separator != '-')
|
||||
return NWC24_OK;
|
||||
{
|
||||
offset += 2;
|
||||
for (; offset < 1024; offset++, digits++) {
|
||||
digit = Util_xtoi(*buffer);
|
||||
if (digit < 0)
|
||||
break;
|
||||
value = (value << 4) | digit;
|
||||
buffer++;
|
||||
}
|
||||
if (digits != 8)
|
||||
result = NWC24_ERR_FORMAT;
|
||||
*appId = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24ReadMsgFromAddr(const NWC24MsgObj* msg, char* address, u32 capacity) {
|
||||
const NWC24MsgObjPrivate* privateMsg = (const NWC24MsgObjPrivate*)msg;
|
||||
NWC24MBoxType type;
|
||||
NWC24File file;
|
||||
NWC24FileStream stream;
|
||||
char* buffer;
|
||||
NWC24Err result, closeResult;
|
||||
if (!NWC24IsMsgLibOpened() && !NWC24IsMsgLibOpenedByTool())
|
||||
return NWC24_ERR_LIB_NOT_OPENED;
|
||||
if (!(privateMsg->type & 0x200))
|
||||
return NWC24_ERR_PROTECTED;
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
Mail_memset(buffer, 0, 1024);
|
||||
if (!(privateMsg->type & 2))
|
||||
return NWC24_ERR_NOT_SUPPORTED;
|
||||
result = SelectMBox(privateMsg, &type);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
break;
|
||||
default:
|
||||
return result;
|
||||
}
|
||||
if (privateMsg->unk_0x30.size == 0)
|
||||
return NWC24_ERR_NULL;
|
||||
result = NWC24iMBoxOpenStoredMsg(type, privateMsg->msgId, &file);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
break;
|
||||
default:
|
||||
return result;
|
||||
}
|
||||
result = NWC24FStreamInit(&stream, &file, 0, privateMsg->length, buffer, 1024);
|
||||
if (result == NWC24_OK) {
|
||||
result = NWC24FStreamSeek(&stream, (u32)privateMsg->unk_0x30.ptr);
|
||||
if (result == NWC24_OK)
|
||||
result = NWC24iExtractAddrSpec(&stream, privateMsg->unk_0x30.size, 0, address, capacity);
|
||||
}
|
||||
closeResult = NWC24iMBoxCloseMsg(&file);
|
||||
if (result != NWC24_OK)
|
||||
closeResult = result;
|
||||
return closeResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24ReadMsgSubject(const NWC24MsgObj* msg, char* subject, u32 capacity) {
|
||||
const NWC24MsgObjPrivate* privateMsg = (const NWC24MsgObjPrivate*)msg;
|
||||
NWC24MBoxType type;
|
||||
NWC24File file;
|
||||
u32 length;
|
||||
NWC24Err result, closeResult;
|
||||
if (!NWC24IsMsgLibOpened() && !NWC24IsMsgLibOpenedByTool())
|
||||
return NWC24_ERR_LIB_NOT_OPENED;
|
||||
if (!(privateMsg->type & 0x200))
|
||||
return NWC24_ERR_PROTECTED;
|
||||
result = SelectMBox(privateMsg, &type);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
break;
|
||||
default:
|
||||
return result;
|
||||
}
|
||||
length = privateMsg->subject.size;
|
||||
if (length == 0)
|
||||
return NWC24_ERR_NULL;
|
||||
result = NWC24iMBoxOpenStoredMsg(type, privateMsg->msgId, &file);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
break;
|
||||
default:
|
||||
return result;
|
||||
}
|
||||
if (length > capacity - 1)
|
||||
length = capacity - 1;
|
||||
NWC24FSeek(&file, (u32)privateMsg->subject.ptr, NWC24_SEEK_BEG);
|
||||
result = NWC24FRead(subject, length, &file);
|
||||
if (result == NWC24_OK) {
|
||||
subject[length] = 0;
|
||||
if (privateMsg->subject.size > capacity - 1)
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
}
|
||||
closeResult = NWC24iMBoxCloseMsg(&file);
|
||||
if (result == NWC24_OK)
|
||||
result = closeResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24ReadMsgText(const NWC24MsgObj* msg, char* text, u32 capacity, NWC24Charset* charset, NWC24Encoding* encoding) {
|
||||
char* name = NWC24WorkP->stringWork + 32;
|
||||
NWC24Err result = ReadMsgTextInternal(msg, text, capacity, name, 64, encoding);
|
||||
if (result == NWC24_OK)
|
||||
result = NWC24ParseCharsetStr(charset, name);
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24ReadMsgTextEx(const NWC24MsgObj* msg, char* text, u32 capacity, char* charset, u32 charsetCapacity) {
|
||||
u32 i;
|
||||
NWC24Encoding encoding;
|
||||
NWC24Err result = ReadMsgTextInternal(msg, text, capacity, charset, charsetCapacity, &encoding);
|
||||
if (result == NWC24_OK) {
|
||||
for (i = 0; i < charsetCapacity; i++) {
|
||||
switch (*charset) {
|
||||
case ' ':
|
||||
case '\t':
|
||||
case '\n':
|
||||
case '\r':
|
||||
case ';':
|
||||
case '"':
|
||||
*charset = 0;
|
||||
break;
|
||||
}
|
||||
if (*charset == 0)
|
||||
break;
|
||||
charset++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static NWC24Err ReadMsgTextInternal(const NWC24MsgObj* msg, char* text, u32 capacity, char* charset, u32 charsetCapacity, NWC24Encoding* encoding) {
|
||||
const NWC24MsgObjPrivate* privateMsg = (const NWC24MsgObjPrivate*)msg;
|
||||
NWC24MBoxType type;
|
||||
NWC24File file;
|
||||
NWC24Err result, closeResult;
|
||||
NWC24Err overflow = NWC24_OK;
|
||||
u32 length;
|
||||
u32 decodedSize;
|
||||
char* buffer;
|
||||
if (!NWC24IsMsgLibOpened() && !NWC24IsMsgLibOpenedByTool())
|
||||
return NWC24_ERR_LIB_NOT_OPENED;
|
||||
if (!(privateMsg->type & 0x200))
|
||||
return NWC24_ERR_PROTECTED;
|
||||
buffer = NWC24WorkP->stringWork;
|
||||
*encoding = 0;
|
||||
result = SelectMBox(privateMsg, &type);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
break;
|
||||
default:
|
||||
return result;
|
||||
}
|
||||
length = privateMsg->textSize;
|
||||
if (length == 0)
|
||||
length = privateMsg->text.size;
|
||||
if (length == 0)
|
||||
return NWC24_ERR_NULL;
|
||||
if (length > capacity - 1) {
|
||||
overflow = NWC24_ERR_OVERFLOW;
|
||||
length = capacity - 1;
|
||||
}
|
||||
result = NWC24iMBoxOpenStoredMsg(type, privateMsg->msgId, &file);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
break;
|
||||
default:
|
||||
return result;
|
||||
}
|
||||
Mail_memset(charset, 0, charsetCapacity);
|
||||
if (privateMsg->unk_0x50.size >= charsetCapacity)
|
||||
result = NWC24_ERR_FORMAT;
|
||||
else {
|
||||
if (privateMsg->unk_0x50.size != 0) {
|
||||
NWC24FSeek(&file, (u32)privateMsg->unk_0x50.ptr, NWC24_SEEK_BEG);
|
||||
result = NWC24FRead(charset, privateMsg->unk_0x50.size, &file);
|
||||
if (result != NWC24_OK)
|
||||
goto close;
|
||||
}
|
||||
if (privateMsg->unk_0x58.size != 0 && privateMsg->unk_0x58.size < 32) {
|
||||
Mail_memset(buffer, 0, 32);
|
||||
NWC24FSeek(&file, (u32)privateMsg->unk_0x58.ptr, NWC24_SEEK_BEG);
|
||||
result = NWC24FRead(buffer, privateMsg->unk_0x58.size, &file);
|
||||
if (result != NWC24_OK)
|
||||
goto close;
|
||||
result = NWC24ParseEncodingStr(encoding, buffer);
|
||||
if (result != NWC24_OK)
|
||||
goto close;
|
||||
}
|
||||
NWC24FSeek(&file, (u32)privateMsg->text.ptr, NWC24_SEEK_BEG);
|
||||
switch (*encoding) {
|
||||
case 0:
|
||||
case 1:
|
||||
result = NWC24FRead(text, length, &file);
|
||||
text[length] = 0;
|
||||
break;
|
||||
case 2:
|
||||
decodedSize = 0;
|
||||
result = ReadBase64Data(&file, &privateMsg->text, (u8*)text, length, &decodedSize);
|
||||
if (result == NWC24_OK && decodedSize != privateMsg->textSize)
|
||||
result = NWC24_ERR_FORMAT;
|
||||
text[length] = 0;
|
||||
break;
|
||||
case 3:
|
||||
result = ReadQPText(privateMsg, &file, text, length);
|
||||
break;
|
||||
default:
|
||||
result = NWC24_ERR_NOT_SUPPORTED;
|
||||
*text = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
close:
|
||||
closeResult = NWC24iMBoxCloseMsg(&file);
|
||||
if (result == NWC24_OK)
|
||||
result = closeResult;
|
||||
if (result == NWC24_OK)
|
||||
result = overflow;
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24ReadMsgAttached(const NWC24MsgObj* msg, u32 index, u8* output, u32 capacity) {
|
||||
const NWC24MsgObjPrivate* privateMsg = (const NWC24MsgObjPrivate*)msg;
|
||||
NWC24File file;
|
||||
NWC24MBoxType type;
|
||||
u32 decodedSize;
|
||||
NWC24Err result, closeResult;
|
||||
if (!NWC24IsMsgLibOpened() && !NWC24IsMsgLibOpenedByTool())
|
||||
return NWC24_ERR_LIB_NOT_OPENED;
|
||||
if (!(privateMsg->type & 0x200))
|
||||
return NWC24_ERR_PROTECTED;
|
||||
if (index >= privateMsg->numAttached)
|
||||
return NWC24_ERR_NOT_FOUND;
|
||||
result = SelectMBox(privateMsg, &type);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
break;
|
||||
default:
|
||||
return result;
|
||||
}
|
||||
if (privateMsg->attached[index].size == 0 || privateMsg->attachedSize[index] == 0)
|
||||
return NWC24_ERR_NULL;
|
||||
result = NWC24iMBoxOpenStoredMsg(type, privateMsg->msgId, &file);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
break;
|
||||
default:
|
||||
return result;
|
||||
}
|
||||
decodedSize = 0;
|
||||
result = ReadBase64Data(&file, &privateMsg->attached[index], output, capacity, &decodedSize);
|
||||
if (result == NWC24_OK && decodedSize != privateMsg->attachedSize[index])
|
||||
result = NWC24_ERR_FORMAT;
|
||||
closeResult = NWC24iMBoxCloseMsg(&file);
|
||||
if (result == NWC24_OK)
|
||||
result = closeResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err ReadBase64Data(NWC24File* file, const NWC24Data* data, u8* output, u32 capacity, u32* outputSize) {
|
||||
int remaining = data->size;
|
||||
int offset = (u32)data->ptr;
|
||||
char* buffer = NWC24WorkP->mainWork;
|
||||
u8* outPtr = output;
|
||||
int total = 0;
|
||||
int readSize;
|
||||
int end;
|
||||
char* cursor;
|
||||
int i;
|
||||
u32 decodedSize;
|
||||
NWC24Err result = NWC24_OK;
|
||||
BOOL finished = FALSE;
|
||||
while (remaining > 0 && !finished) {
|
||||
readSize = remaining > 1024 ? 1024 : remaining;
|
||||
NWC24FSeek(file, offset, NWC24_SEEK_BEG);
|
||||
result = NWC24FRead(buffer, readSize, file);
|
||||
if (result != NWC24_OK)
|
||||
break;
|
||||
end = 0;
|
||||
cursor = buffer;
|
||||
for (i = 0; i < readSize; cursor++, i++) {
|
||||
if (*cursor == '\r')
|
||||
end = i;
|
||||
if (*cursor == '=') {
|
||||
end = i + 1;
|
||||
finished = TRUE;
|
||||
result = NWC24_OK;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (end == 0)
|
||||
break;
|
||||
result = NWC24Base64Decode((u8*)buffer, end, outPtr, capacity - total, &decodedSize);
|
||||
if (result != NWC24_OK)
|
||||
break;
|
||||
offset += end;
|
||||
remaining -= end;
|
||||
total += decodedSize;
|
||||
outPtr += decodedSize;
|
||||
}
|
||||
if (result == NWC24_OK)
|
||||
*outputSize = total;
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err ReadQPText(const NWC24MsgObjPrivate* msg, NWC24File* file, char* output, u32 capacity) {
|
||||
int remaining = msg->text.size;
|
||||
int offset = (u32)msg->text.ptr;
|
||||
char* buffer = NWC24WorkP->mainWork;
|
||||
char* cursor = output;
|
||||
int readSize;
|
||||
u32 total = 0;
|
||||
u32 consumedSize;
|
||||
u32 decodedSize;
|
||||
NWC24Err result = NWC24_OK;
|
||||
while (remaining > 0) {
|
||||
readSize = remaining > 1024 ? 1024 : remaining;
|
||||
NWC24FSeek(file, offset, NWC24_SEEK_BEG);
|
||||
result = NWC24FRead(buffer, readSize, file);
|
||||
if (result != NWC24_OK)
|
||||
break;
|
||||
consumedSize = readSize;
|
||||
if (readSize == 1024) {
|
||||
if (buffer[readSize - 1] == '=')
|
||||
consumedSize = readSize - 1;
|
||||
else if (buffer[readSize - 2] == '=')
|
||||
consumedSize = readSize - 2;
|
||||
}
|
||||
result = NWC24DecodeQuotedPrintable(cursor, capacity - total, &decodedSize, (u8*)buffer, consumedSize, &consumedSize);
|
||||
if (result != NWC24_OK && result != NWC24_ERR_OVERFLOW)
|
||||
break;
|
||||
total += decodedSize;
|
||||
cursor += decodedSize;
|
||||
if (result == NWC24_ERR_OVERFLOW)
|
||||
break;
|
||||
offset += consumedSize;
|
||||
remaining -= consumedSize;
|
||||
}
|
||||
*cursor = 0;
|
||||
if (result == NWC24_OK && total > msg->textSize)
|
||||
result = NWC24_ERR_FORMAT;
|
||||
return result;
|
||||
}
|
||||
877
libs/RevoEX/src/nwc24/NWC24MsgSubject.c
Normal file
877
libs/RevoEX/src/nwc24/NWC24MsgSubject.c
Normal file
@@ -0,0 +1,877 @@
|
||||
#define NWC24_MSG_SUBJECT
|
||||
#include <private/enc.h>
|
||||
#include <private/nwc24.h>
|
||||
#include <revolution/enc.h>
|
||||
#include <revolution/nwc24.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
static char CharsetUsAscii[] = "us-ascii";
|
||||
static char CharsetIso2022Jp[] = "iso-2022-jp";
|
||||
static char CharsetUtf8[] = "utf-8";
|
||||
static char CharsetEucKr[] = "euc-kr";
|
||||
static char CharsetGb2312[] = "gb2312";
|
||||
static const char* JapaneseCharsets[] = {CharsetUsAscii, CharsetIso2022Jp, CharsetUtf8};
|
||||
static const char* ChineseCharsets[] = {CharsetUsAscii, CharsetGb2312};
|
||||
static char CharsetIso88591[] = "iso-8859-1";
|
||||
static char CharsetWindows1252[] = "windows-1252";
|
||||
static char CharsetIso88592[] = "iso-8859-2";
|
||||
static char CharsetIso88597[] = "iso-8859-7";
|
||||
static char CharsetIso885910[] = "iso-8859-10";
|
||||
char CharsetIso88593[] = "iso-8859-3";
|
||||
static const char* WesternCharsets[] = {CharsetUsAscii, CharsetIso88591, CharsetWindows1252, CharsetIso88592,
|
||||
CharsetIso88597, CharsetIso885910, CharsetIso88593, CharsetUtf8};
|
||||
static const char* KoreanCharsets[] = {CharsetUsAscii, CharsetEucKr, CharsetUtf8};
|
||||
static char DefaultCharsetJp[] = "iso-2022-jp";
|
||||
static char DefaultCharsetKr[] = "euc-kr";
|
||||
|
||||
NWC24Err NWC24iGetDefaultCharset(char* charset, u32 charsetSize, NWC24EncodingRegion region);
|
||||
NWC24Err NWC24iConvertToInternalEncoding(u16* dst, u32* dstSize, const u8* src, u32* srcSize, char* charset, u32 charsetSize,
|
||||
NWC24EncodingRegion region, u16 alternative);
|
||||
NWC24Err NWC24iConvertFromInternalEncoding(u8* dst, u32* dstSize, const u16* src, u32* srcSize, char* charset, u32 charsetSize,
|
||||
NWC24EncodingRegion region, u16 alternative);
|
||||
NWC24Err NWC24iDetectEncodingToSend(char* charset, u32 charsetSize, const u16* subject, u32 subjectSize, const u16* text, u32 textSize,
|
||||
NWC24EncodingRegion region);
|
||||
NWC24Err NWC24iDetectBreakPoint(u32* breakPoint, NWC24Charset charset, const u8* text, u32 textSize, u32 maxSize);
|
||||
NWC24Err NWC24iSetMsgSubjectPlain(NWC24MsgObj* msg, const u16* subject, u32 subjectSize, NWC24EncodingRegion region, u16 alternative, u8* work,
|
||||
u32 workSize, NWC24Charset charset, char* charsetName);
|
||||
NWC24Err NWC24iSetMsgSubjectQP(NWC24MsgObj* msg, const u16* subject, u32 subjectSize, NWC24EncodingRegion region, u16 alternative, u8* work,
|
||||
u32 workSize, NWC24Charset charset, char* charsetName);
|
||||
NWC24Err NWC24iSetMsgSubjectBase64(NWC24MsgObj* msg, const u16* subject, u32 subjectSize, NWC24EncodingRegion region, u16 alternative, u8* work,
|
||||
u32 workSize, NWC24Charset charset, char* charsetName);
|
||||
|
||||
NWC24Err NWC24ReadMsgSubjectPublic(const NWC24MsgObj* msg, u16* subject, u32* subjectSize, NWC24EncodingRegion region, u16 alternative, u8* work,
|
||||
u32 workSize) {
|
||||
BOOL truncated;
|
||||
u8* decodedData;
|
||||
u32 decodedCapacity;
|
||||
u32 originalSize;
|
||||
u32 subjectDataSize;
|
||||
u32 workHalf;
|
||||
u32 decodedSize;
|
||||
char* charsetBuffer;
|
||||
NWC24Err result;
|
||||
u32 i;
|
||||
|
||||
if (subjectSize == NULL) {
|
||||
result = NWC24_ERR_INVALID_VALUE;
|
||||
} else {
|
||||
originalSize = *subjectSize;
|
||||
*subjectSize = 0;
|
||||
truncated = FALSE;
|
||||
if (work == NULL) {
|
||||
result = NWC24_ERR_INVALID_VALUE;
|
||||
} else {
|
||||
workHalf = workSize >> 1;
|
||||
decodedData = work + workHalf;
|
||||
decodedCapacity = workSize - workHalf;
|
||||
result = NWC24GetMsgSubjectSize(msg, &subjectDataSize);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
if (subjectDataSize > workHalf) {
|
||||
subjectDataSize = workHalf;
|
||||
truncated = TRUE;
|
||||
}
|
||||
result = NWC24ReadMsgSubject(msg, (char*)work, subjectDataSize);
|
||||
if (result != NWC24_OK) {
|
||||
if (result == NWC24_ERR_OVERFLOW) {
|
||||
truncated = TRUE;
|
||||
} else {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
charsetBuffer = NWC24WorkP->stringWork;
|
||||
result =
|
||||
NWC24DecodeMIMEHeaderFieldBody((u8*)charsetBuffer, 0x40, decodedData, decodedCapacity, &decodedSize, work, subjectDataSize);
|
||||
if (result != NWC24_OK) {
|
||||
if (result == NWC24_ERR_OVERFLOW) {
|
||||
truncated = TRUE;
|
||||
} else {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
*subjectSize = originalSize;
|
||||
result =
|
||||
NWC24iConvertToInternalEncoding(subject, subjectSize, decodedData, &decodedSize, charsetBuffer, 0x40, region, alternative);
|
||||
if ((result == NWC24_OK) || (result == NWC24_ERR_OVERFLOW)) {
|
||||
for (i = 0; (i < *subjectSize) && (subject[i] != 0); i++) {
|
||||
if ((subject[i] == 0x0D) || (subject[i] == 0x0A)) {
|
||||
subject[i] = 0x20;
|
||||
}
|
||||
}
|
||||
if ((result == NWC24_OK) && truncated) {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24ReadMsgTextPublic(const NWC24MsgObj* msg, u16* text, u32* textSize, NWC24EncodingRegion region, u16 alternative, u8* work,
|
||||
u32 workSize) {
|
||||
char* charsetBuffer;
|
||||
BOOL truncated;
|
||||
u32 originalSize;
|
||||
u32 textDataSize;
|
||||
NWC24Err result;
|
||||
|
||||
if (textSize == NULL) {
|
||||
result = NWC24_ERR_INVALID_VALUE;
|
||||
} else {
|
||||
originalSize = *textSize;
|
||||
*textSize = 0;
|
||||
truncated = FALSE;
|
||||
if (work == NULL) {
|
||||
result = NWC24_ERR_INVALID_VALUE;
|
||||
} else {
|
||||
result = NWC24GetMsgTextSize(msg, &textDataSize);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
if (textDataSize > workSize) {
|
||||
textDataSize = workSize;
|
||||
truncated = TRUE;
|
||||
}
|
||||
charsetBuffer = NWC24WorkP->stringWork + 0x20;
|
||||
result = NWC24ReadMsgTextEx(msg, (char*)work, textDataSize, charsetBuffer, 0x40);
|
||||
if (result != NWC24_OK) {
|
||||
if (result != NWC24_ERR_OVERFLOW) {
|
||||
goto done;
|
||||
}
|
||||
truncated = TRUE;
|
||||
}
|
||||
|
||||
*textSize = originalSize;
|
||||
result = NWC24iConvertToInternalEncoding(text, textSize, work, &textDataSize, charsetBuffer, 0x40, region, alternative);
|
||||
if ((result == NWC24_OK) && truncated) {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24SetMsgSubjectPublic(NWC24MsgObj* msg, const u16* subject, u32 subjectSize, NWC24EncodingRegion region, u16 alternative, u8* work,
|
||||
u32 workSize) {
|
||||
NWC24MsgObjPrivate* privateMsg = (NWC24MsgObjPrivate*)msg;
|
||||
NWC24Work* nwcWork;
|
||||
NWC24Charset charset;
|
||||
NWC24Err result;
|
||||
|
||||
if (((privateMsg->type & 0x100) == 0) || ((privateMsg->type & 0x200) != 0)) {
|
||||
result = NWC24_ERR_PROTECTED;
|
||||
goto done;
|
||||
}
|
||||
if ((subject == NULL) || (*subject == 0)) {
|
||||
result = NWC24_ERR_NULL;
|
||||
goto done;
|
||||
}
|
||||
if (subject[subjectSize] != 0) {
|
||||
result = NWC24_ERR_STRING_END;
|
||||
goto done;
|
||||
}
|
||||
if (work == NULL) {
|
||||
result = NWC24_ERR_INVALID_VALUE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
nwcWork = NWC24WorkP;
|
||||
result = NWC24iDetectEncodingToSend(nwcWork->stringWork, 0x40, subject, subjectSize, NULL, 0, region);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
break;
|
||||
default:
|
||||
goto done;
|
||||
}
|
||||
if (NWC24ParseCharsetStr(&charset, nwcWork->stringWork) != NWC24_OK) {
|
||||
charset = 0;
|
||||
}
|
||||
if (charset == 0) {
|
||||
result = NWC24iSetMsgSubjectPlain(msg, subject, subjectSize, region, alternative, work, workSize, charset, nwcWork->stringWork);
|
||||
goto done;
|
||||
}
|
||||
switch (region) {
|
||||
case 0:
|
||||
result = 2;
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
result = 3;
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
result = 2;
|
||||
break;
|
||||
default:
|
||||
result = 2;
|
||||
break;
|
||||
}
|
||||
if (result == 3) {
|
||||
result = NWC24iSetMsgSubjectQP(msg, subject, subjectSize, region, alternative, work, workSize, charset, nwcWork->stringWork);
|
||||
} else {
|
||||
result = NWC24iSetMsgSubjectBase64(msg, subject, subjectSize, region, alternative, work, workSize, charset, nwcWork->stringWork);
|
||||
}
|
||||
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24SetMsgSubjectAndTextPublic(NWC24MsgObj* msg, const u16* subject, u32 subjectSize, const u16* text, u32 textSize,
|
||||
NWC24EncodingRegion region, u16 alternative, u8* work, u32 workSize) {
|
||||
NWC24MsgObjPrivate* privateMsg = (NWC24MsgObjPrivate*)msg;
|
||||
NWC24Work* nwcWork;
|
||||
u32 textSourceSize;
|
||||
u32 textWorkSize;
|
||||
BOOL is7Bit;
|
||||
NWC24Charset charset;
|
||||
u32 subjectWorkSize;
|
||||
u8* subjectWork;
|
||||
NWC24Err result;
|
||||
|
||||
if (((privateMsg->type & 0x100) == 0) || ((privateMsg->type & 0x200) != 0)) {
|
||||
result = NWC24_ERR_PROTECTED;
|
||||
goto done;
|
||||
}
|
||||
if ((subject == NULL) || (*subject == 0)) {
|
||||
result = NWC24_ERR_NULL;
|
||||
goto done;
|
||||
}
|
||||
if ((text == NULL) || (textSize == 0)) {
|
||||
NWC24Data_Init(&privateMsg->text);
|
||||
result = NWC24SetMsgSubjectPublic(msg, subject, subjectSize, region, alternative, work, workSize);
|
||||
goto done;
|
||||
}
|
||||
if ((text[textSize] != 0) || (subject[subjectSize] != 0)) {
|
||||
result = NWC24_ERR_STRING_END;
|
||||
goto done;
|
||||
}
|
||||
if (work == NULL) {
|
||||
result = NWC24_ERR_INVALID_VALUE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
nwcWork = NWC24WorkP;
|
||||
result = NWC24iDetectEncodingToSend(nwcWork->stringWork, 0x40, subject, subjectSize, text, textSize, region);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
break;
|
||||
default:
|
||||
goto done;
|
||||
}
|
||||
if (NWC24ParseCharsetStr(&charset, nwcWork->stringWork) != NWC24_OK) {
|
||||
charset = 0;
|
||||
}
|
||||
textWorkSize = (workSize * textSize) / (textSize + subjectSize * 4);
|
||||
subjectWorkSize = workSize - textWorkSize;
|
||||
subjectWork = work + textWorkSize;
|
||||
textSourceSize = textSize;
|
||||
result = NWC24iConvertFromInternalEncoding(work, &textWorkSize, text, &textSourceSize, nwcWork->stringWork, 0x40, region, alternative);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
break;
|
||||
default:
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = ENCIs7BitEncoding(&is7Bit, nwcWork->stringWork);
|
||||
if (!is7Bit || (result != ENC_OK)) {
|
||||
switch (region) {
|
||||
case 0:
|
||||
result = 2;
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
result = 3;
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
result = 2;
|
||||
break;
|
||||
default:
|
||||
result = 2;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
result = NWC24SetMsgText(msg, (char*)work, textWorkSize - 1, charset, result);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
break;
|
||||
default:
|
||||
goto done;
|
||||
}
|
||||
if (charset == 0) {
|
||||
result = NWC24iSetMsgSubjectPlain(msg, subject, subjectSize, region, alternative, subjectWork, subjectWorkSize, charset, nwcWork->stringWork);
|
||||
goto done;
|
||||
}
|
||||
switch (region) {
|
||||
case 0:
|
||||
result = 2;
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
result = 3;
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
result = 2;
|
||||
break;
|
||||
default:
|
||||
result = 2;
|
||||
break;
|
||||
}
|
||||
if (result == 3) {
|
||||
result = NWC24iSetMsgSubjectQP(msg, subject, subjectSize, region, alternative, subjectWork, subjectWorkSize, charset, nwcWork->stringWork);
|
||||
} else {
|
||||
result =
|
||||
NWC24iSetMsgSubjectBase64(msg, subject, subjectSize, region, alternative, subjectWork, subjectWorkSize, charset, nwcWork->stringWork);
|
||||
}
|
||||
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24iGetDefaultCharset(char* charset, u32 charsetSize, NWC24EncodingRegion region) {
|
||||
NWC24Err result = NWC24_OK;
|
||||
|
||||
switch (region) {
|
||||
case 0:
|
||||
strncpy(charset, DefaultCharsetJp, charsetSize - 1);
|
||||
charset[charsetSize - 1] = 0;
|
||||
goto done;
|
||||
case 1:
|
||||
strncpy(charset, "iso-8859-1", charsetSize - 1);
|
||||
charset[charsetSize - 1] = 0;
|
||||
goto done;
|
||||
case 2:
|
||||
strncpy(charset, "iso-8859-1", charsetSize - 1);
|
||||
charset[charsetSize - 1] = 0;
|
||||
goto done;
|
||||
case 3:
|
||||
strncpy(charset, DefaultCharsetKr, charsetSize - 1);
|
||||
charset[charsetSize - 1] = 0;
|
||||
goto done;
|
||||
case 4:
|
||||
strncpy(charset, "gb2312", charsetSize - 1);
|
||||
charset[charsetSize - 1] = 0;
|
||||
goto done;
|
||||
default:
|
||||
strncpy(charset, "iso-8859-1", charsetSize - 1);
|
||||
charset[charsetSize - 1] = 0;
|
||||
result = NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24iConvertToInternalEncoding(u16* dst, u32* dstSize, const u8* src, u32* srcSize, char* charset, u32 charsetSize,
|
||||
NWC24EncodingRegion region, u16 alternative) {
|
||||
ENCContext context;
|
||||
u32 dstBytes;
|
||||
u32 convertedBytes;
|
||||
NWC24Err result;
|
||||
|
||||
dstBytes = *dstSize * 2;
|
||||
*dstSize = 0;
|
||||
if (dstBytes < 2) {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
goto done;
|
||||
}
|
||||
if (charset[0] == '\0') {
|
||||
result = NWC24iGetDefaultCharset(charset, charsetSize, region);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
break;
|
||||
default:
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
result = ENCInitContext(&context);
|
||||
if ((result == ENC_OK) && ((result = ENCSetExternalEncoding(&context, charset)) == ENC_OK) &&
|
||||
((result = ENCSetBreakType(&context, ENC_BR_LF)) == ENC_OK) &&
|
||||
((alternative == 0) || ((result = ENCSetAlternativeCharacter(&context, alternative, alternative)) == ENC_OK))) {
|
||||
convertedBytes = dstBytes - 2;
|
||||
result = ENCConvertToInternalEncoding(&context, dst, (s32*)&convertedBytes, src, (s32*)srcSize);
|
||||
dst[convertedBytes >> 1] = 0;
|
||||
*dstSize = (convertedBytes >> 1) + 1;
|
||||
}
|
||||
if (result == ENC_ERR_NO_MAP_RULE) {
|
||||
goto invalidCharacter;
|
||||
}
|
||||
if (result < ENC_ERR_NO_MAP_RULE) {
|
||||
if (result == ENC_ERR_INVALID_FORMAT) {
|
||||
goto invalidCharacter;
|
||||
}
|
||||
if (result >= ENC_ERR_INVALID_FORMAT) {
|
||||
goto invalidValue;
|
||||
}
|
||||
if (result >= ENC_ERR_NOT_LOADED) {
|
||||
goto notSupported;
|
||||
}
|
||||
} else {
|
||||
if (result == ENC_OK) {
|
||||
goto success;
|
||||
}
|
||||
if (result >= ENC_OK) {
|
||||
goto fatal;
|
||||
}
|
||||
goto overflow;
|
||||
}
|
||||
goto fatal;
|
||||
|
||||
success:
|
||||
result = ENC_OK;
|
||||
goto done;
|
||||
|
||||
invalidValue:
|
||||
result = NWC24_ERR_INVALID_VALUE;
|
||||
goto done;
|
||||
|
||||
overflow:
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
goto done;
|
||||
|
||||
invalidCharacter:
|
||||
result = NWC24_ERR_INVALID_CHAR;
|
||||
goto done;
|
||||
|
||||
notSupported:
|
||||
result = NWC24_ERR_NOT_SUPPORTED;
|
||||
goto done;
|
||||
|
||||
fatal:
|
||||
result = NWC24_ERR_FATAL;
|
||||
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24iConvertFromInternalEncoding(u8* dst, u32* dstSize, const u16* src, u32* srcSize, char* charset, u32 charsetSize,
|
||||
NWC24EncodingRegion region, u16 alternative) {
|
||||
ENCContext context;
|
||||
u32 outputCapacity;
|
||||
u32 outputBytes;
|
||||
u32 inputBytes;
|
||||
NWC24Err result;
|
||||
|
||||
outputCapacity = *dstSize;
|
||||
*dstSize = 0;
|
||||
if (outputCapacity < 1) {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
goto done;
|
||||
}
|
||||
if (charset[0] == '\0') {
|
||||
result = NWC24iGetDefaultCharset(charset, charsetSize, region);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
break;
|
||||
default:
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
result = ENCInitContext(&context);
|
||||
if ((result == ENC_OK) && ((result = ENCSetExternalEncoding(&context, charset)) == ENC_OK) &&
|
||||
((result = ENCSetBreakType(&context, ENC_BR_CRLF)) == ENC_OK) &&
|
||||
((alternative == 0) || ((result = ENCSetAlternativeCharacter(&context, alternative, alternative)) == ENC_OK))) {
|
||||
outputBytes = outputCapacity - 1;
|
||||
inputBytes = *srcSize << 1;
|
||||
result = ENCConvertFromInternalEncoding(&context, dst, (s32*)&outputBytes, src, (s32*)&inputBytes);
|
||||
dst[outputBytes] = 0;
|
||||
*srcSize = inputBytes >> 1;
|
||||
*dstSize = outputBytes + 1;
|
||||
}
|
||||
if (result == ENC_ERR_NO_MAP_RULE) {
|
||||
goto invalidCharacter;
|
||||
}
|
||||
if (result < ENC_ERR_NO_MAP_RULE) {
|
||||
if (result == ENC_ERR_INVALID_FORMAT) {
|
||||
goto invalidCharacter;
|
||||
}
|
||||
if (result >= ENC_ERR_INVALID_FORMAT) {
|
||||
goto invalidValue;
|
||||
}
|
||||
if (result >= ENC_ERR_NOT_LOADED) {
|
||||
goto notSupported;
|
||||
}
|
||||
goto fatal;
|
||||
}
|
||||
if (result == ENC_OK) {
|
||||
goto success;
|
||||
}
|
||||
if (result >= ENC_OK) {
|
||||
goto fatal;
|
||||
}
|
||||
goto overflow;
|
||||
|
||||
success:
|
||||
result = ENC_OK;
|
||||
goto done;
|
||||
|
||||
invalidValue:
|
||||
result = NWC24_ERR_INVALID_VALUE;
|
||||
goto done;
|
||||
|
||||
overflow:
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
goto done;
|
||||
|
||||
invalidCharacter:
|
||||
result = NWC24_ERR_INVALID_CHAR;
|
||||
goto done;
|
||||
|
||||
notSupported:
|
||||
result = NWC24_ERR_NOT_SUPPORTED;
|
||||
goto done;
|
||||
|
||||
fatal:
|
||||
result = NWC24_ERR_FATAL;
|
||||
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24iDetectEncodingToSend(char* charset, u32 charsetSize, const u16* subject, u32 subjectSize, const u16* text, u32 textSize,
|
||||
NWC24EncodingRegion region) {
|
||||
int endIndex;
|
||||
u32 subjectBytes;
|
||||
u32 textBytes;
|
||||
int startIndex;
|
||||
int lastIndex;
|
||||
int index;
|
||||
const char** names;
|
||||
int numNames;
|
||||
int result;
|
||||
|
||||
index = 0;
|
||||
startIndex = 0;
|
||||
lastIndex = -1;
|
||||
switch (region) {
|
||||
case 0:
|
||||
names = JapaneseCharsets;
|
||||
numNames = 3;
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
names = WesternCharsets;
|
||||
numNames = 8;
|
||||
break;
|
||||
case 3:
|
||||
names = KoreanCharsets;
|
||||
numNames = 3;
|
||||
break;
|
||||
case 4:
|
||||
names = ChineseCharsets;
|
||||
numNames = 2;
|
||||
break;
|
||||
default:
|
||||
names = WesternCharsets;
|
||||
numNames = 8;
|
||||
break;
|
||||
}
|
||||
subjectBytes = subjectSize << 1;
|
||||
textBytes = textSize << 1;
|
||||
endIndex = numNames - 1;
|
||||
while (index < endIndex) {
|
||||
result = ENCCheckEncoding(&index, names + startIndex, endIndex - startIndex, subject, subjectBytes);
|
||||
if (result != ENC_OK) {
|
||||
return NWC24_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
if (index == ENC_CHECK_ENCODING_NOT_FOUND) {
|
||||
index = numNames - 1;
|
||||
break;
|
||||
}
|
||||
startIndex += index;
|
||||
if ((text == NULL) || (lastIndex == startIndex)) {
|
||||
index = startIndex;
|
||||
break;
|
||||
}
|
||||
result = ENCCheckEncoding(&index, names + startIndex, endIndex - startIndex, text, textBytes);
|
||||
if (result != ENC_OK) {
|
||||
return NWC24_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
if (index == ENC_CHECK_ENCODING_NOT_FOUND) {
|
||||
index = numNames - 1;
|
||||
break;
|
||||
}
|
||||
lastIndex = startIndex + index;
|
||||
if (lastIndex == startIndex) {
|
||||
index = lastIndex;
|
||||
break;
|
||||
}
|
||||
startIndex = lastIndex;
|
||||
}
|
||||
strncpy(charset, names[index], charsetSize - 1);
|
||||
charset[charsetSize - 1] = '\0';
|
||||
return NWC24_OK;
|
||||
}
|
||||
|
||||
NWC24Err NWC24iDetectBreakPoint(u32* breakPoint, NWC24Charset charset, const u8* text, u32 textSize, u32 maxSize) {
|
||||
const u8* ptr;
|
||||
BOOL byteEncoding;
|
||||
u32 i;
|
||||
u32 lastBreak;
|
||||
|
||||
i = 0;
|
||||
lastBreak = 0;
|
||||
if ((breakPoint == NULL) || (text == NULL)) {
|
||||
return NWC24_ERR_INVALID_VALUE;
|
||||
}
|
||||
if (charset == 0) {
|
||||
byteEncoding = TRUE;
|
||||
} else if (charset == NWC24_UTF_8) {
|
||||
byteEncoding = FALSE;
|
||||
} else if (((charset & 0xFFFF0000) == 0x00080000) || (charset == NWC24_WINDOWS_1252)) {
|
||||
byteEncoding = TRUE;
|
||||
} else {
|
||||
return NWC24_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
if (textSize <= maxSize) {
|
||||
*breakPoint = textSize;
|
||||
return NWC24_OK;
|
||||
}
|
||||
ptr = text;
|
||||
while ((i < maxSize) && (*text != 0)) {
|
||||
if (*ptr == 0x20) {
|
||||
lastBreak = i;
|
||||
}
|
||||
i++;
|
||||
ptr++;
|
||||
}
|
||||
if (lastBreak != 0) {
|
||||
*breakPoint = lastBreak;
|
||||
return NWC24_OK;
|
||||
}
|
||||
if (byteEncoding) {
|
||||
*breakPoint = maxSize;
|
||||
return NWC24_OK;
|
||||
}
|
||||
{
|
||||
u32 utf8Index = 0;
|
||||
ptr = text;
|
||||
while (utf8Index < maxSize && *text != 0) {
|
||||
if (((u32)*ptr & 0xC0) != 0x80U)
|
||||
lastBreak = utf8Index;
|
||||
utf8Index++;
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
*breakPoint = lastBreak;
|
||||
return NWC24_OK;
|
||||
}
|
||||
|
||||
NWC24Err NWC24iSetMsgSubjectPlain(NWC24MsgObj* msg, const u16* subject, u32 subjectSize, NWC24EncodingRegion region, u16 alternative, u8* work,
|
||||
u32 workSize, NWC24Charset charset, char* charsetName) {
|
||||
u32 workHalf;
|
||||
u32 secondSize;
|
||||
u32 sourceOffset;
|
||||
u8* second;
|
||||
u32 subjectLength;
|
||||
u32 lineLength;
|
||||
s32 copied;
|
||||
u32 i;
|
||||
NWC24Err result;
|
||||
|
||||
secondSize = workSize - (workSize >> 1);
|
||||
second = work + (workSize >> 1);
|
||||
subjectLength = subjectSize;
|
||||
lineLength = 0;
|
||||
workHalf = workSize >> 1;
|
||||
result = NWC24iConvertFromInternalEncoding(work, &workHalf, subject, &subjectLength, charsetName, 0x40, region, alternative);
|
||||
switch (result) {
|
||||
default:
|
||||
goto done;
|
||||
case NWC24_OK:
|
||||
subjectLength = workHalf - 1;
|
||||
for (i = 0; i < workHalf; i++) {
|
||||
if ((work[i] == '\n') || (work[i] == '\r')) {
|
||||
work[i] = ' ';
|
||||
}
|
||||
}
|
||||
NWC24iDetectBreakPoint(&lineLength, charset, work, subjectLength, 0x3F);
|
||||
if (lineLength == subjectLength) {
|
||||
result = NWC24SetMsgSubject(msg, (char*)work, subjectLength);
|
||||
} else {
|
||||
workHalf = secondSize;
|
||||
sourceOffset = lineLength;
|
||||
if (workHalf <= sourceOffset) {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
goto done;
|
||||
}
|
||||
copied = NWC24iStrLCpy((char*)second, (char*)work, lineLength + 1);
|
||||
for (; sourceOffset < subjectLength; sourceOffset += lineLength) {
|
||||
if (workHalf - copied < 3) {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
goto done;
|
||||
}
|
||||
second[copied++] = '\r';
|
||||
second[copied++] = '\n';
|
||||
if (work[sourceOffset] != ' ') {
|
||||
second[copied] = ' ';
|
||||
copied++;
|
||||
}
|
||||
NWC24iDetectBreakPoint(&lineLength, charset, work + sourceOffset, subjectLength - sourceOffset, 0x47);
|
||||
if (workHalf - copied <= lineLength) {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
goto done;
|
||||
}
|
||||
copied += NWC24iStrLCpy((char*)second + copied, (char*)work + sourceOffset, lineLength + 1);
|
||||
}
|
||||
second[copied] = 0;
|
||||
result = NWC24SetMsgSubject(msg, (char*)second, copied);
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24iSetMsgSubjectQP(NWC24MsgObj* msg, const u16* subject, u32 subjectSize, NWC24EncodingRegion region, u16 alternative, u8* work,
|
||||
u32 workSize, NWC24Charset charset, char* charsetName) {
|
||||
u32 workHalf;
|
||||
u32 sourceOffset;
|
||||
u32 secondSize;
|
||||
u8* second;
|
||||
u32 subjectLength;
|
||||
u32 lineLength;
|
||||
u32 outputLength;
|
||||
u32 total;
|
||||
u32 combinedLength;
|
||||
u32 i;
|
||||
u32 charsetLength;
|
||||
NWC24Err result;
|
||||
|
||||
secondSize = workSize - (workSize >> 1);
|
||||
second = work + (workSize >> 1);
|
||||
subjectLength = subjectSize;
|
||||
lineLength = 0;
|
||||
workHalf = workSize >> 1;
|
||||
result = NWC24iConvertFromInternalEncoding(work, &workHalf, subject, &subjectLength, charsetName, 0x40, region, alternative);
|
||||
switch (result) {
|
||||
default:
|
||||
goto done;
|
||||
case NWC24_OK:
|
||||
subjectLength = workHalf - 1;
|
||||
for (i = 0; i < workHalf; i++) {
|
||||
if ((work[i] == '\n') || (work[i] == '\r')) {
|
||||
work[i] = ' ';
|
||||
}
|
||||
}
|
||||
charsetLength = strlen(charsetName);
|
||||
NWC24iDetectBreakPoint(&lineLength, charset, work, subjectLength, (0x38 - charsetLength) / 3);
|
||||
result = NWC24EncodeWord(second, secondSize, &outputLength, charsetName, 0x40, 'Q', work, lineLength);
|
||||
switch (result) {
|
||||
default:
|
||||
goto done;
|
||||
case NWC24_OK:
|
||||
sourceOffset = lineLength;
|
||||
if (lineLength == subjectLength) {
|
||||
result = NWC24SetMsgSubject(msg, (char*)second, outputLength - 1);
|
||||
} else {
|
||||
charsetLength = (0x40 - strlen(charsetName)) / 3;
|
||||
total = outputLength - 1;
|
||||
workHalf = secondSize;
|
||||
for (; sourceOffset < subjectLength;) {
|
||||
if (workHalf - total < 3) {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
goto done;
|
||||
}
|
||||
second[total++] = '\r';
|
||||
second[total++] = '\n';
|
||||
second[total++] = ' ';
|
||||
NWC24iDetectBreakPoint(&lineLength, charset, work + sourceOffset, subjectLength - sourceOffset, charsetLength);
|
||||
result = NWC24EncodeWord(second + total, workHalf - total, &outputLength, charsetName, 0x40, 'Q', work + sourceOffset,
|
||||
lineLength);
|
||||
switch (result) {
|
||||
case NWC24_OK:
|
||||
break;
|
||||
default:
|
||||
goto done;
|
||||
}
|
||||
combinedLength = total + outputLength;
|
||||
sourceOffset += lineLength;
|
||||
total = combinedLength - 1;
|
||||
}
|
||||
result = NWC24SetMsgSubject(msg, (char*)second, total);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
NWC24Err NWC24iSetMsgSubjectBase64(NWC24MsgObj* msg, const u16* subject, u32 subjectSize, NWC24EncodingRegion region, u16 alternative, u8* work,
|
||||
u32 workSize, NWC24Charset charset, char* charsetName) {
|
||||
u32 workHalf;
|
||||
u32 secondSize;
|
||||
u8* second;
|
||||
u32 subjectLength;
|
||||
u32 lineLength;
|
||||
u32 outputLength;
|
||||
u32 sourceOffset;
|
||||
u32 total;
|
||||
u32 charsetLength;
|
||||
NWC24Err result;
|
||||
|
||||
workHalf = workSize >> 1;
|
||||
secondSize = workSize - workHalf;
|
||||
second = work + workHalf;
|
||||
charsetLength = strlen(charsetName);
|
||||
lineLength = ((0x36 - charsetLength) * 3) >> 2;
|
||||
if (workHalf < lineLength) {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
} else {
|
||||
outputLength = lineLength + 1;
|
||||
subjectLength = subjectSize;
|
||||
result = NWC24iConvertFromInternalEncoding(work, &outputLength, subject, &subjectLength, charsetName, 0x40, region, alternative);
|
||||
if (((result == NWC24_OK) || (result == NWC24_ERR_OVERFLOW)) &&
|
||||
((result = NWC24EncodeWord(second, secondSize, &outputLength, charsetName, 0x40, 'B', work, outputLength - 1)) == NWC24_OK)) {
|
||||
sourceOffset = subjectLength;
|
||||
if (sourceOffset == subjectSize) {
|
||||
result = NWC24SetMsgSubject(msg, (char*)second, outputLength - 1);
|
||||
} else {
|
||||
charsetLength = strlen(charsetName);
|
||||
lineLength = (((0x3E - charsetLength) * 3) >> 2) + 1;
|
||||
total = outputLength;
|
||||
for (; sourceOffset < subjectSize; sourceOffset += subjectLength) {
|
||||
subjectLength = subjectSize - sourceOffset;
|
||||
workHalf = lineLength;
|
||||
if (secondSize - (total - 1) < 3) {
|
||||
result = NWC24_ERR_OVERFLOW;
|
||||
goto done;
|
||||
}
|
||||
second[total - 1] = '\r';
|
||||
second[total] = '\n';
|
||||
second[total + 1] = ' ';
|
||||
total += 2;
|
||||
result = NWC24iConvertFromInternalEncoding(work, &workHalf, subject + sourceOffset, &subjectLength, charsetName, 0x40, region,
|
||||
alternative);
|
||||
if (((result != NWC24_OK) && (result != NWC24_ERR_OVERFLOW)) ||
|
||||
((result = NWC24EncodeWord(second + total, secondSize - total, &outputLength, charsetName, 0x40, 'B', work, workHalf - 1)) !=
|
||||
NWC24_OK)) {
|
||||
goto done;
|
||||
}
|
||||
total += outputLength;
|
||||
}
|
||||
result = NWC24SetMsgSubject(msg, (char*)second, total - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
112
libs/RevoEX/src/nwc24/NWC24System.c
Normal file
112
libs/RevoEX/src/nwc24/NWC24System.c
Normal file
@@ -0,0 +1,112 @@
|
||||
#include <private/nwc24.h>
|
||||
#include <private/os/OSStateTM.h>
|
||||
#include <revolution/os.h>
|
||||
#include <revolution/sc.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static s32 nwc24ShtFd = -1;
|
||||
static s32 nwc24ShtRetryRest = 0;
|
||||
static OSShutdownFunctionInfo ShutdownFuncInfo;
|
||||
BOOL NWC24Shutdown(BOOL final, u32 event);
|
||||
NWC24Err NWC24iMBoxSetLastUIDL(NWC24MBoxType type, const char* uidl);
|
||||
|
||||
NWC24Err NWC24EnableLedNotification(BOOL enable) {
|
||||
u8 led = 0;
|
||||
SCIdleModeInfo idleMode;
|
||||
u32 status;
|
||||
if (enable) {
|
||||
do {
|
||||
status = SCCheckStatus();
|
||||
if (status == 2)
|
||||
return NWC24_ERR_FATAL;
|
||||
} while (status == 1);
|
||||
SCGetIdleMode(&idleMode);
|
||||
led = idleMode.led;
|
||||
}
|
||||
__OSSetIdleLEDMode(led);
|
||||
return NWC24_OK;
|
||||
}
|
||||
|
||||
NWC24Err NWC24iPrepareShutdown(void) {
|
||||
NWC24Err result = NWC24_OK;
|
||||
SCIdleModeInfo idleMode;
|
||||
u32 status;
|
||||
NWC24iRegister();
|
||||
ShutdownFuncInfo.func = NWC24Shutdown;
|
||||
ShutdownFuncInfo.priority = 110;
|
||||
OSRegisterShutdownFunction(&ShutdownFuncInfo);
|
||||
if (nwc24ShtFd < 0)
|
||||
result = NWC24OpenResourceManager("/dev/net/kd/request", &nwc24ShtFd, 1);
|
||||
nwc24ShtRetryRest = 5;
|
||||
do {
|
||||
status = SCCheckStatus();
|
||||
if (status == 2)
|
||||
goto ready;
|
||||
} while (status == 1);
|
||||
SCGetIdleMode(&idleMode);
|
||||
__OSSetIdleLEDMode(idleMode.led);
|
||||
ready:
|
||||
if (OSGetAppType() == 0x40)
|
||||
NWC24iSetScriptMode(1);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline NWC24Err NWC24iRequestShutdown(u32 event, NWC24Err* result) {
|
||||
static u32 shtBuffer[8] ALIGN32;
|
||||
static u32 shtResult[8] ALIGN32;
|
||||
shtBuffer[0] = event;
|
||||
return NWC24IoctlResourceManagerAsync(nwc24ShtFd, NWC24_IOCTL_SHUTDOWN, shtBuffer, sizeof(shtBuffer), shtResult, sizeof(shtResult), (s32*)result);
|
||||
}
|
||||
|
||||
BOOL NWC24Shutdown(BOOL final, u32 event) {
|
||||
static BOOL shuttingdown = FALSE;
|
||||
static NWC24Err result = NWC24_OK;
|
||||
if (final)
|
||||
return TRUE;
|
||||
if (shuttingdown) {
|
||||
if (NWC24IsAsyncRequestPending())
|
||||
return FALSE;
|
||||
if (result >= 0)
|
||||
return TRUE;
|
||||
if (nwc24ShtRetryRest > 0) {
|
||||
shuttingdown = FALSE;
|
||||
nwc24ShtRetryRest--;
|
||||
} else
|
||||
return TRUE;
|
||||
} else if (NWC24iRequestShutdown(event, &result) >= 0)
|
||||
shuttingdown = TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
NWC24Err NWC24DoDailyTasks(void* work) {
|
||||
NWC24Err result = NWC24_OK;
|
||||
SCIdleModeInfo idleMode;
|
||||
u32 status;
|
||||
u32 restrictions;
|
||||
u32 tick = OSGetTick();
|
||||
u32 randomValue = rand();
|
||||
if ((randomValue + tick) % 10 != 0)
|
||||
return NWC24_OK;
|
||||
if (NWC24IsMsgLibOpened())
|
||||
return NWC24_ERR_LIB_OPENED;
|
||||
do {
|
||||
status = SCCheckStatus();
|
||||
if (status == 2)
|
||||
return NWC24_ERR_FATAL;
|
||||
OSSleepTicks(OSMillisecondsToTicks((OSTime)100));
|
||||
} while (status != 0);
|
||||
if (!SCGetIdleMode(&idleMode))
|
||||
return NWC24_ERR_NOT_FOUND;
|
||||
restrictions = SCGetNetContentRestrictions() & 2;
|
||||
if (idleMode.standby == 0) {
|
||||
if (restrictions == 0) {
|
||||
result = NWC24OpenLib(work);
|
||||
if (result >= 0) {
|
||||
result = NWC24iMBoxSetLastUIDL(NWC24_MBOX_TYPE_RECV, "");
|
||||
NWC24CloseLib();
|
||||
}
|
||||
} else
|
||||
result = NWC24AdjustUniversalTime();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -23,7 +23,7 @@ static const void* NETGetSHA1Interface(void);
|
||||
static void NETHMACInit(NETHMACContext* ctx, const void* interface, const void* key, u32 keyLen);
|
||||
static void NETHMACUpdate(NETHMACContext* ctx, const void* data, u32 len);
|
||||
static void NETHMACGetDigest(NETHMACContext* ctx, void* digest);
|
||||
extern char lbl_81697583[];
|
||||
extern char VmReportFormat[];
|
||||
|
||||
#define CHANSVmDebugLength 1024
|
||||
#define VM_FRAME_ARENA_SIZE 8192
|
||||
@@ -66,7 +66,7 @@ void CHANSVmDebugPrintf(const vmString format, ...) {
|
||||
|
||||
str[CHANSVmDebugLength - 1] = str[CHANSVmDebugLength - 2] = 0;
|
||||
|
||||
OSReport(lbl_81697583, str);
|
||||
OSReport(VmReportFormat, str);
|
||||
}
|
||||
|
||||
#define CHANS_VM_PRINTF(line, msg, ...) \
|
||||
@@ -92,8 +92,8 @@ vmU16 CHANSVmGetSourceLine(CHANSVm* vm) {
|
||||
}
|
||||
}
|
||||
|
||||
if ((u8*)curEntry + lineOffset + 1 < (u8*)ctx->pDbg + ctx->pDbg->regionSize) {
|
||||
u8* lineData = (u8*)curEntry + lineOffset;
|
||||
if ((u8*)ctx->pDbg->pLineTbl + lineOffset + 1 < (u8*)ctx->pDbg + ctx->pDbg->regionSize) {
|
||||
u8* lineData = (u8*)ctx->pDbg->pLineTbl + lineOffset;
|
||||
return VM_READ_BE_U16(lineData, 0);
|
||||
}
|
||||
}
|
||||
@@ -347,7 +347,7 @@ vmPtr CHANSVmNewObjData(CHANSVm* vm, CHANSVmObjHdr* object, u32 length) {
|
||||
if (chunk == vmNull) {
|
||||
chunk = CHANSVmAlloc(vm, 0x4000);
|
||||
if (chunk == vmNull) {
|
||||
goto error;
|
||||
goto no_entry;
|
||||
}
|
||||
pVm->pChunks[chunkIdx] = chunk;
|
||||
}
|
||||
@@ -365,6 +365,7 @@ vmPtr CHANSVmNewObjData(CHANSVm* vm, CHANSVmObjHdr* object, u32 length) {
|
||||
chunkIdx++;
|
||||
u.off += 4;
|
||||
}
|
||||
no_entry:
|
||||
u.off = 0;
|
||||
goto check_entry;
|
||||
}
|
||||
@@ -397,7 +398,7 @@ error:
|
||||
return vmNull;
|
||||
}
|
||||
|
||||
extern const char CHANSVmConstStringDataEmpty[16];
|
||||
extern const CHANSVmObjHdr CHANSVmConstStringDataEmpty;
|
||||
|
||||
CHANSVmObjHdr* CHANSVmNewObject(CHANSVm* vm, vmBoolInt noAlloc, CHANSVmObjHdr* object, CHANSVmObjType type, vmSize len) {
|
||||
CHANSVmObjHdr* header;
|
||||
@@ -418,7 +419,7 @@ CHANSVmObjHdr* CHANSVmNewObject(CHANSVm* vm, vmBoolInt noAlloc, CHANSVmObjHdr* o
|
||||
}
|
||||
} else {
|
||||
if (type == 3UL) {
|
||||
object->value.ptr_v = (vmPtr)CHANSVmConstStringDataEmpty;
|
||||
object->value.ptr_v = (vmPtr)&CHANSVmConstStringDataEmpty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -509,15 +510,14 @@ CHANSVmErr CHANSVmPopObject(CHANSVm* vm, CHANSVmObjHdr* object) {
|
||||
|
||||
void CHANSVmStrCpyToU16FromU8(vmWString output, vmString input, vmSize length) {
|
||||
u8* src = (u8*)input + length;
|
||||
u32 offset = VM_STR_LENGTH(length);
|
||||
|
||||
while (length > 0) {
|
||||
u8 val;
|
||||
offset -= 2;
|
||||
u32 offset = VM_STR_LENGTH(--length);
|
||||
u8* dest = (u8*)output + offset;
|
||||
val = *--src;
|
||||
((u8*)output)[offset + 1] = val;
|
||||
((u8*)output)[offset] = 0;
|
||||
length--;
|
||||
dest[1] = val;
|
||||
dest[0] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -667,25 +667,25 @@ u8 lbl_81669094[19] = {0x00, '-', 0x00, 'I', 0x00, 'n', 0x00, 'f', 0x00, 'i', 0x
|
||||
|
||||
// clang-format off
|
||||
const CHANSVmObjHdr CHANSVmConstStringObjectUndefined = {{(wchar_t*)lbl_81669070, 18}, {0}, vmNull};
|
||||
const CHANSVmObjHdr lbl_81616C88 = {{L"NaN", 6}, {0}, vmNull};
|
||||
const CHANSVmObjHdr lbl_81616C88 = {{(wchar_t*)"\0N\0a\0N", 6}, {0}, vmNull};
|
||||
const CHANSVmObjHdr lbl_81616C98 = {{(wchar_t*)lbl_81669083, 16}, {0}, vmNull};
|
||||
const CHANSVmObjHdr lbl_81616CA8 = {{(wchar_t*)lbl_81669094, 18}, {0}, vmNull};
|
||||
const CHANSVmObjHdr lbl_81616CB8 = {{L",", 2}, {0}, vmNull};
|
||||
const char CHANSVmConstStringDataEmpty[16] = "";
|
||||
const CHANSVmObjHdr lbl_81616CB8 = {{(wchar_t*)"\0,", 2}, {0}, vmNull};
|
||||
const CHANSVmObjHdr CHANSVmConstStringDataEmpty = {{(wchar_t*)"", 0}, {0}, vmNull};
|
||||
const CHANSVmObjHdr CHANSVmConstStringObjectUndefined_[] = {{{(void*)&CHANSVmConstStringObjectUndefined, 0}, 0x03800100, vmNull},
|
||||
{{(void*)&lbl_81616C88, 0}, 0x03800100, vmNull},
|
||||
{{(void*)&lbl_81616C98, 0}, 0x03800100, vmNull},
|
||||
{{(void*)&lbl_81616CA8, 0}, 0x03800100, vmNull},
|
||||
{{(void*)&lbl_81616CB8, 0}, 0x00800000, vmNull}};
|
||||
char lbl_81697583[] = "%s";
|
||||
char lbl_8169758A[] = "%.16lg";
|
||||
{{vmNull, 0}, 0x00800000, vmNull}};
|
||||
char VmReportFormat[] = "%s";
|
||||
|
||||
const CHANSVmFloatConstantList lbl_81616D28[] = {
|
||||
{ "Infinity", (double*)&VmInf },
|
||||
{ "+Infinity", (double*)&VmInf },
|
||||
{ "-Infinity", (double*)&VmMinusInf },
|
||||
{ "Infinity", (double*)&VmNaN }
|
||||
{ "NaN", (double*)&VmNaN }
|
||||
};
|
||||
char lbl_8169758A[] = "%.16lg";
|
||||
// clang-format on
|
||||
|
||||
CHANSVmObjHdr* CHANSVm_8144B4D4(CHANSVm* vm, CHANSVmObjType type, CHANSVmObjHdr* object) {
|
||||
@@ -764,10 +764,10 @@ s32 CHANSVm_8144B62C(vmWString buf, u32 len, vmFloat val) NO_INLINE {
|
||||
return VM_STR_LENGTH(result);
|
||||
}
|
||||
|
||||
char lbl_81697591[] = "%lld";
|
||||
char VmIntegerFormat[] = "%lld";
|
||||
|
||||
static int VmToStrFromInt(vmWString output, vmSize length, vmInteger integer) {
|
||||
vmS32 len = snprintf((vmString)output, length, lbl_81697591, integer);
|
||||
vmS32 len = snprintf((vmString)output, length, VmIntegerFormat, integer);
|
||||
CHANSVmStrCpyToU16FromU8(output, (vmString)output, len);
|
||||
return len;
|
||||
}
|
||||
@@ -853,7 +853,7 @@ vmBoolInt CHANSVmGetEnumedType(CHANSVmObjType* eType, vmU32 iType) NO_INLINE {
|
||||
type = 4;
|
||||
break;
|
||||
}
|
||||
case CHANS_VM_TYPE_GLOBAL_REF:
|
||||
case CHANS_VM_TYPE_OBJECT:
|
||||
case CHANS_VM_TYPE_CLASS_REF:
|
||||
case CHANS_VM_TYPE_METHOD_REF: {
|
||||
type = 5;
|
||||
@@ -876,12 +876,13 @@ char lbl_81669128[] = "VmGetResultType";
|
||||
|
||||
// clang-format off
|
||||
const VmConvertEntry VmTypeConvertFuncTbl[] = {
|
||||
{CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError},
|
||||
{CHANSVm_8144B30C, CHANSVmConvertToIntFromStr, CHANSVmConvertToIntFromArray, CHANSVmConvertObjectTypeError, CHANSVm_8144B430, CHANSVm_8144B470},
|
||||
{CHANSVm_8144B4D4, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, CHANSVmConvertToStrFromUndefined, CHANSVmConvertToStrFromInt, CHANSVm_8144B734},
|
||||
{CHANSVmConvertToStrFromArray, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError},
|
||||
{CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError},
|
||||
{CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError}};
|
||||
{vmNull, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError},
|
||||
{CHANSVmConvertObjectTypeError, vmNull, CHANSVm_8144B30C, CHANSVmConvertToIntFromStr, CHANSVmConvertToIntFromArray, CHANSVmConvertObjectTypeError},
|
||||
{CHANSVm_8144B430, CHANSVm_8144B470, vmNull, CHANSVm_8144B4D4, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError},
|
||||
{CHANSVmConvertToStrFromUndefined, CHANSVmConvertToStrFromInt, CHANSVm_8144B734, vmNull, CHANSVmConvertToStrFromArray, CHANSVmConvertObjectTypeError},
|
||||
{CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, vmNull, CHANSVmConvertObjectTypeError},
|
||||
{CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, CHANSVmConvertObjectTypeError, vmNull},
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
// Each table is a 6x6 u8 matrix indexed [left_enumed][right_enumed].
|
||||
@@ -1533,8 +1534,8 @@ const char* vmErrorList[] = {
|
||||
"CHANS_VM_ERR_RESERVED_OPCODE", /* -923 */
|
||||
};
|
||||
|
||||
const char* vmNoError = "CHANS_VM_OK";
|
||||
const char* vmUnknownError = "(unknown)";
|
||||
char vmNoError[] = "CHANS_VM_OK";
|
||||
char vmUnknownError[] = "(unknown)";
|
||||
|
||||
CHANSVmNativeClass* CHANSVmFindNativeClass(CHANSVm* vm, const char* clsName) {
|
||||
CHANSVmPrivate* pVm = (CHANSVmPrivate*)vm;
|
||||
@@ -1920,15 +1921,15 @@ static CHANSVmErr VmArrayExpandCommon(CHANSVm* vm, CHANSVmObjHdr* obj, u32 start
|
||||
chunk->pNext = current;
|
||||
}
|
||||
|
||||
for (i = 0, allocSize = 0; i < total; i++, allocSize += sizeof(CHANSVmObjHdr)) {
|
||||
for (i = 0; i < total; i++) {
|
||||
if (fillFromArgs != 0 && i < ((CHANSVmPrivate*)vm)->pActiveCtx->argc && CHANSVmGetArg(vm, i) != vmNull) {
|
||||
CHANSVmObjHdr* arg = CHANSVmGetArg(vm, i);
|
||||
if (CHANSVmCopyObject(vm, (CHANSVmObjHdr*)((u8*)chunk + sizeof(ArrayChunk) + allocSize), arg) == vmNull) {
|
||||
if (CHANSVmCopyObject(vm, &chunk->elements[i], arg) == vmNull) {
|
||||
goto error;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
memset((u8*)chunk + sizeof(ArrayChunk) + allocSize, 0, sizeof(CHANSVmObjHdr));
|
||||
memset(&chunk->elements[i], 0, sizeof(CHANSVmObjHdr));
|
||||
}
|
||||
|
||||
return vmTrue;
|
||||
@@ -2146,7 +2147,7 @@ static u32 VmArrayJoinSub(CHANSVmObjHdr* obj, CHANSVmObjHdr* array, wchar_t* sep
|
||||
goto error;
|
||||
}
|
||||
strBuf = (vmString)(*obj->value.ptr_v) + offset;
|
||||
elemLen = snprintf(strBuf, 0x40, lbl_81697591, chunk->elements[countInChunk].value.int_v);
|
||||
elemLen = snprintf(strBuf, 0x40, VmIntegerFormat, chunk->elements[countInChunk].value.int_v);
|
||||
CHANSVmStrCpyToU16FromU8((vmWString)strBuf, strBuf, elemLen);
|
||||
elemLen = elemLen << 1;
|
||||
break;
|
||||
@@ -2631,10 +2632,8 @@ VmMethodDefine(Date, GetRTC) {
|
||||
u32 bias = SCGetCounterBias();
|
||||
s64 ticks = OSCalendarTimeToTicks(cal);
|
||||
u64 t = ticks / (__OSBusClock / 4 / 1000);
|
||||
u32 val;
|
||||
t = t / 1000;
|
||||
val = (u32)(t - (unsigned int)bias);
|
||||
return CHANSVmSetInteger(VmInst, VmReturnObj, val) == CHANS_VM_OK;
|
||||
t /= 1000;
|
||||
return CHANSVmSetInteger(VmInst, VmReturnObj, (t - bias) & 0xFFFFFFFFULL) == CHANS_VM_OK;
|
||||
}
|
||||
|
||||
const CHANSVmMethodList VmDateMethodTbl[] = {
|
||||
@@ -3167,13 +3166,13 @@ VmMethodDefine(String, Splice) {
|
||||
length = VmParentObj->value.string_v->len;
|
||||
|
||||
if (arg0 != vmNull) {
|
||||
s64 byteOffs0 = arg0->value.int_v * 2;
|
||||
if (byteOffs0 > length) {
|
||||
s64 startByteOffset = arg0->value.int_v * 2;
|
||||
if (startByteOffset > length) {
|
||||
start = length;
|
||||
} else {
|
||||
start = byteOffs0;
|
||||
if (byteOffs0 < 0) {
|
||||
s64 t0 = byteOffs0 + length;
|
||||
start = startByteOffset;
|
||||
if (startByteOffset < 0) {
|
||||
s64 t0 = startByteOffset + length;
|
||||
start = t0;
|
||||
if (t0 < 0) {
|
||||
start = 0;
|
||||
@@ -3200,7 +3199,7 @@ VmMethodDefine(String, Splice) {
|
||||
length = tempLen;
|
||||
}
|
||||
|
||||
newLen = length - start & ~-(s32)(start >= length);
|
||||
newLen = start >= length ? 0 : length - start;
|
||||
|
||||
if (CHANSVmNewObject(VmInst, vmFalse, VmReturnObj, CHANS_VM_OBJ_TYPE_STRING, newLen) != vmNull) {
|
||||
if (newLen != 0) {
|
||||
@@ -4163,23 +4162,21 @@ VmMethodDefine(Blob, CopyRangeFrom) {
|
||||
|
||||
if (CHANSVm_81450D14(destBlob, destOffObj->value.int_v, &destOff) != 0 && CHANSVm_81450D14(srcBlob, srcOffObj->value.int_v, &srcOff) != 0) {
|
||||
count = CHANSVm_81451314(srcBlob, countObj, srcOff);
|
||||
if ((s64)destBlob->size >= (s64)count) {
|
||||
u32 available = destBlob->size - destOff;
|
||||
if ((s64)count >= (s64)available) {
|
||||
{
|
||||
u32 destinationOffset = destOff;
|
||||
if ((s64)count >= 0 && (s64)(destBlob->size - destinationOffset) >= (s64)count) {
|
||||
okFlag = vmTrue;
|
||||
}
|
||||
}
|
||||
|
||||
if (okFlag) {
|
||||
okFlag = vmFalse;
|
||||
if ((s64)count >= 0) {
|
||||
u32 available = srcBlob->size - srcOff;
|
||||
if ((s64)count >= (s64)available) {
|
||||
okFlag = vmTrue;
|
||||
}
|
||||
vmBoolInt sourceValid = vmFalse;
|
||||
u32 sourceOffset = srcOff;
|
||||
if ((s64)count >= 0 && (s64)(srcBlob->size - sourceOffset) >= (s64)count) {
|
||||
sourceValid = vmTrue;
|
||||
}
|
||||
|
||||
if (okFlag) {
|
||||
if (sourceValid) {
|
||||
memmove(destBlob->pData + destOff, srcBlob->pData + srcOff, count);
|
||||
return CHANSVmSetInteger(VmInst, VmReturnObj, (vmInteger)(u64)count) == CHANS_VM_OK;
|
||||
}
|
||||
@@ -4383,14 +4380,14 @@ VmMethodDefine(Blob, CalcMD5Digest) {
|
||||
}
|
||||
|
||||
VmMethodDefine(Blob, CalcRangeMD5Digest) {
|
||||
u8* data;
|
||||
u8* digest;
|
||||
BlobHeader* blob = (BlobHeader*)VmGetStrFromObjHdr(VmParentObj);
|
||||
CHANSVmObjHdr* arg0 = CHANSVmConvertObjectType(VmInst, CHANS_VM_OBJ_TYPE_INTEGER, CHANSVmGetArg(VmInst, 0));
|
||||
CHANSVmObjHdr* arg1 = CHANSVmConvertObjectType(VmInst, CHANS_VM_OBJ_TYPE_INTEGER, CHANSVmGetArg(VmInst, 1));
|
||||
u32 offset = 0;
|
||||
u32 size;
|
||||
u8* data;
|
||||
NETMD5Context ctx;
|
||||
u8* digest;
|
||||
CHANSVmObjHdr* newObj;
|
||||
|
||||
if (blob == vmNull || arg0 == vmNull) {
|
||||
@@ -4531,6 +4528,8 @@ VmMethodDefine(Blob, CalcHMAC) {
|
||||
}
|
||||
|
||||
VmMethodDefine(Blob, CalcRangeHMAC) {
|
||||
u8* blobData;
|
||||
u8* digest;
|
||||
BlobHeader* blob = (BlobHeader*)VmGetStrFromObjHdr(VmParentObj);
|
||||
CHANSVmObjHdr* argKey = CHANSVmGetArg(VmInst, 0);
|
||||
BlobHeader* keyBlob;
|
||||
@@ -4557,9 +4556,7 @@ VmMethodDefine(Blob, CalcRangeHMAC) {
|
||||
off = offset;
|
||||
if (((s64)size >= 0LL && (s64)(blob->size - off) >= (s64)size) != vmFalse) {
|
||||
NETHMACContext ctx;
|
||||
u8* digest;
|
||||
CHANSVmObjHdr* newObj;
|
||||
u8* blobData;
|
||||
|
||||
newObj = VmBlobCreateDirect(VmInst, VmReturnObj, 20);
|
||||
digest = VmBlobGetDataBufferDirect(newObj);
|
||||
@@ -6107,7 +6104,7 @@ static vmBoolInt VmWinEmuWrite(CHANSVm* vm, CHANSVmObjHdr* parent, CHANSVmObjHdr
|
||||
if (result == 0) {
|
||||
buf[outLen] = 0;
|
||||
buf[outLen + 1] = 0;
|
||||
OSReport("%s", buf);
|
||||
OSReport(VmReportFormat, buf);
|
||||
} else {
|
||||
OSReport("document.write(): conversion error (%d)\n", result);
|
||||
break;
|
||||
@@ -6983,7 +6980,7 @@ static CHANSVmErr VmCallMethod(CHANSVm* vm, u32 instructionSize, u32 callType, u
|
||||
CHANSVmNativeClass* target;
|
||||
u32 pushEnd, headerCount;
|
||||
u32 newPc;
|
||||
void* pConstObj;
|
||||
const u8* instruction;
|
||||
CHANSVmObjHdr localBuf;
|
||||
u32 pushDepth;
|
||||
CHANSVmFunction funcPtr;
|
||||
@@ -7047,7 +7044,7 @@ static CHANSVmErr VmCallMethod(CHANSVm* vm, u32 instructionSize, u32 callType, u
|
||||
u32 pc = pVm->pActiveCtx->pc;
|
||||
|
||||
newPc = pc + instructionSize;
|
||||
pConstObj = (void*)(pVm->pActiveCtx->pDbg->pData + pc);
|
||||
instruction = pVm->pActiveCtx->pDbg->pData + pc;
|
||||
|
||||
if (newPc < pc || newPc > pVm->pActiveCtx->pDbg->codeSize) {
|
||||
return CHANS_VM_ERR_CODE_RANGE;
|
||||
@@ -7063,8 +7060,7 @@ static CHANSVmErr VmCallMethod(CHANSVm* vm, u32 instructionSize, u32 callType, u
|
||||
target = vmNull;
|
||||
} else {
|
||||
CHANSVmExecutionCtx* ec = pVm->pActiveCtx;
|
||||
// TODO: what's the actual type of the object here? avoid raw ptr access
|
||||
u32 methodId = *((u16*)pConstObj + 1);
|
||||
u32 methodId = VM_READ_BE_U16(instruction, 1);
|
||||
u32 methodCount;
|
||||
|
||||
if (ec->pDbg->pMethodTbl == vmNull) {
|
||||
@@ -7115,7 +7111,7 @@ static CHANSVmErr VmCallMethod(CHANSVm* vm, u32 instructionSize, u32 callType, u
|
||||
entry = entry->pNext;
|
||||
}
|
||||
} else {
|
||||
pushDepth = *((u8*)pConstObj + instructionSize - 1);
|
||||
pushDepth = instruction[instructionSize - 1];
|
||||
if (retVal != 0) {
|
||||
CHANSVmNativeMethod* node = target->pNativeMethods;
|
||||
|
||||
@@ -7411,7 +7407,7 @@ CHANSVmErr CHANSVmStep(CHANSVm* vm, int stepCount) {
|
||||
break;
|
||||
}
|
||||
case VM_OPKIND_EQ: {
|
||||
convTbl = (u8*)VmResultTypeTbl.arith;
|
||||
convTbl = (u8*)VmResultTypeTbl.eq;
|
||||
break;
|
||||
}
|
||||
case VM_OPKIND_BIT:
|
||||
@@ -7727,7 +7723,8 @@ CHANSVmErr CHANSVmStep(CHANSVm* vm, int stepCount) {
|
||||
return CHANS_VM_ERR_CODE_RANGE;
|
||||
}
|
||||
pAcc = &pVm->accumulator;
|
||||
if (CHANSVmDeleteObject(vm, pAcc) == CHANS_VM_OK) {
|
||||
result = CHANSVmDeleteObject(vm, pAcc);
|
||||
if (result == CHANS_VM_OK) {
|
||||
imm16Val = VM_READ_BE_U16(operandBuf, 0);
|
||||
ctx = pVm->pActiveCtx;
|
||||
dbg = ctx->pDbg;
|
||||
@@ -7741,10 +7738,9 @@ CHANSVmErr CHANSVmStep(CHANSVm* vm, int stepCount) {
|
||||
break;
|
||||
|
||||
load_str_ok:
|
||||
// result is not initialized in this code path?
|
||||
pAcc->type = CHANS_VM_OBJ_TYPE_STRING;
|
||||
pAcc->hasData = vmTrue;
|
||||
pAcc->value.wstring_v = (vmWStringObjVal*)&dbg->pStringTbl[imm16Val];
|
||||
pAcc->value.wstring_v = (vmWStringObjVal*)&ctx->pDbg->pStringTbl[imm16Val];
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -7852,7 +7848,7 @@ CHANSVmErr CHANSVmStep(CHANSVm* vm, int stepCount) {
|
||||
CHANSVmObjHdr* hdr = CHANSVmNewObject(vm, vmFalse, &pVm->accumulator, CHANS_VM_OBJ_TYPE_STRING, VM_STRING_SIZE);
|
||||
if (hdr != vmNull) {
|
||||
char* s = pVm->accumulator.value.string_v->spData;
|
||||
s32 snpLen = snprintf(s, 0x40, "%lld", (u64)arrayIdx);
|
||||
s32 snpLen = snprintf(s, 0x40, VmIntegerFormat, (u64)arrayIdx);
|
||||
CHANSVmStrCpyToU16FromU8((wchar_t*)s, s, snpLen);
|
||||
pVm->accumulator.value.string_v->len = VM_STR_LENGTH(snpLen);
|
||||
} else {
|
||||
@@ -7889,37 +7885,30 @@ CHANSVmErr CHANSVmStep(CHANSVm* vm, int stepCount) {
|
||||
}
|
||||
|
||||
case CHANS_VM_OP_NEW_ARRAY: {
|
||||
CHANSVmObjHdr* accumulator;
|
||||
CHANSVmErr arrayResult;
|
||||
opSize = 3;
|
||||
operandBuf = VmGetOperand(vm, 1, 3);
|
||||
if (operandBuf == vmNull) {
|
||||
return CHANS_VM_ERR_CODE_RANGE;
|
||||
}
|
||||
imm16Val = VM_READ_BE_U16(operandBuf, 0);
|
||||
{
|
||||
CHANSVmObjHdr* pAcc = &pVm->accumulator;
|
||||
if (CHANSVmDeleteObject(vm, pAcc) != CHANS_VM_OK) {
|
||||
// result not initialized in this code path
|
||||
break;
|
||||
}
|
||||
if (VmPushFuncReturnInfo(vm, imm16Val, imm16Val, 0) != CHANS_VM_OK) {
|
||||
// result not initialized in this code path
|
||||
break;
|
||||
}
|
||||
|
||||
pAcc->type = CHANS_VM_TYPE_ARRAY;
|
||||
pAcc->parentCls = pVm->pArrayCls;
|
||||
|
||||
if (CHANSVmNewObjData(vm, pAcc, 0x18) != vmNull) {
|
||||
if (imm16Val != 0) {
|
||||
result = VmArrayExpandCommon(vm, pAcc, imm16Val, 0, vmTrue);
|
||||
accumulator = &pVm->accumulator;
|
||||
arrayResult = CHANSVmDeleteObject(vm, accumulator);
|
||||
if (arrayResult == CHANS_VM_OK) {
|
||||
arrayResult = VmPushFuncReturnInfo(vm, imm16Val, imm16Val, 0);
|
||||
if (arrayResult == CHANS_VM_OK) {
|
||||
accumulator->type = CHANS_VM_TYPE_ARRAY;
|
||||
accumulator->parentCls = pVm->pArrayCls;
|
||||
if (CHANSVmNewObjData(vm, accumulator, sizeof(ArrayChunk)) == vmNull ||
|
||||
(imm16Val != 0 && VmArrayExpandCommon(vm, accumulator, imm16Val, 0, vmTrue) == 0)) {
|
||||
arrayResult = CHANS_VM_ERR_CALL_NEW_ARRAY;
|
||||
} else {
|
||||
arrayResult = VmReturnWithValue(vm, 0);
|
||||
}
|
||||
} else {
|
||||
result = CHANS_VM_ERR_CALL_NEW_ARRAY;
|
||||
break;
|
||||
}
|
||||
|
||||
result = VmReturnWithValue(vm, 0);
|
||||
}
|
||||
result = arrayResult;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -7982,12 +7971,12 @@ CHANSVmErr CHANSVmStep(CHANSVm* vm, int stepCount) {
|
||||
}
|
||||
imm16Val = (opcodeVal << 8 | operandBuf[1]) & 0x1FFF;
|
||||
switch (opcodeVal & CHANS_VM_OP_SYMBOL_STORE) {
|
||||
case CHANS_VM_OP_SYMBOL_STORE: {
|
||||
case 0: {
|
||||
foundObj = CHANSVm_81455654(vm, imm16Val);
|
||||
result = VmStore(vm, &pVm->accumulator, foundObj);
|
||||
break;
|
||||
}
|
||||
case 0: {
|
||||
case CHANS_VM_OP_SYMBOL_STORE: {
|
||||
foundObj = CHANSVm_81455654(vm, imm16Val);
|
||||
result = VmStore(vm, foundObj, &pVm->accumulator);
|
||||
break;
|
||||
@@ -8011,10 +8000,6 @@ CHANSVmErr CHANSVmStep(CHANSVm* vm, int stepCount) {
|
||||
isTypeMatch = 0;
|
||||
if (pVm->accumulator.type == stackTop->type) {
|
||||
switch (stackTop->type) {
|
||||
case CHANS_VM_OBJ_TYPE_BLANK: {
|
||||
isTypeMatch = 1;
|
||||
goto end_branch_check;
|
||||
}
|
||||
case CHANS_VM_OBJ_TYPE_INTEGER: {
|
||||
u32 low1 = *(u32*)stackTop;
|
||||
u32 low2 = *(u32*)&pVm->accumulator;
|
||||
@@ -8034,21 +8019,14 @@ CHANSVmErr CHANSVmStep(CHANSVm* vm, int stepCount) {
|
||||
case CHANS_VM_OBJ_TYPE_STRING: {
|
||||
u32 len1, len2;
|
||||
CHANSVmObjHdr* stackObj = (CHANSVmObjHdr*)pVm->pObjStackTopBuf;
|
||||
s32 cmpResult;
|
||||
u32 strEqual;
|
||||
isTypeMatch = 0;
|
||||
len1 = stackObj->value.wstring_v->len;
|
||||
len2 = pVm->accumulator.value.wstring_v->len;
|
||||
if (len1 == len2) {
|
||||
strEqual = 0;
|
||||
if (len1 == 0) {
|
||||
if (len1 == 0 || memcmp(stackObj->value.wstring_v->spData, pVm->accumulator.value.wstring_v->spData, len1) == 0) {
|
||||
strEqual = 1;
|
||||
goto end_branch_check;
|
||||
} else {
|
||||
cmpResult = 0;
|
||||
cmpResult = memcmp(stackObj->value.wstring_v->spData, pVm->accumulator.value.wstring_v->spData, len1);
|
||||
if (cmpResult == 0) {
|
||||
strEqual = 1;
|
||||
}
|
||||
}
|
||||
if (strEqual) {
|
||||
isTypeMatch = 1;
|
||||
@@ -8056,6 +8034,10 @@ CHANSVmErr CHANSVmStep(CHANSVm* vm, int stepCount) {
|
||||
}
|
||||
goto end_branch_check;
|
||||
}
|
||||
case CHANS_VM_OBJ_TYPE_BLANK: {
|
||||
isTypeMatch = 1;
|
||||
goto end_branch_check;
|
||||
}
|
||||
case CHANS_VM_TYPE_ARRAY:
|
||||
case CHANS_VM_TYPE_CLASS_REF:
|
||||
case CHANS_VM_TYPE_OBJECT:
|
||||
|
||||
310
src/keyboard/MyTiLetterForm.cpp
Normal file
310
src/keyboard/MyTiLetterForm.cpp
Normal file
@@ -0,0 +1,310 @@
|
||||
#define MYTILETTERFORM_IMPLEMENTATION
|
||||
#include "keyboard/MyTiLetterForm.h"
|
||||
#include "keyboard/tiUtil.h"
|
||||
#include <nw4r/lyt/textbox.h>
|
||||
#include <new>
|
||||
|
||||
namespace textinput {
|
||||
namespace inputform {
|
||||
class EventHandler : public nw4rmanager::TiEventHandler {
|
||||
public:
|
||||
EventHandler(textinput::InputForm* form) : mpInputForm(form) {}
|
||||
virtual ~EventHandler() {}
|
||||
virtual void onTiEvent(gui::PaneComponent*, u32, Input*);
|
||||
protected:
|
||||
textinput::InputForm* mpInputForm;
|
||||
};
|
||||
}
|
||||
namespace extend {
|
||||
namespace memo {
|
||||
class EventHandler : public inputform::EventHandler {
|
||||
public:
|
||||
EventHandler(InputForm* form) : inputform::EventHandler(form), mpMemoForm(form) {}
|
||||
virtual ~EventHandler() {}
|
||||
virtual void onTiEvent(gui::PaneComponent*, u32, Input*);
|
||||
protected:
|
||||
InputForm* mpMemoForm;
|
||||
};
|
||||
}
|
||||
namespace letter {
|
||||
class EventHandler : public memo::EventHandler {
|
||||
public:
|
||||
EventHandler(InputForm* form) : memo::EventHandler(form) {}
|
||||
virtual ~EventHandler();
|
||||
virtual void onTiEvent(gui::PaneComponent*, u32, Input*);
|
||||
};
|
||||
class AnmPane : public nw4rmanager::AnmPane {
|
||||
protected:
|
||||
enum KeyType { KT_Whole, KT_Pic };
|
||||
u32 meState;
|
||||
KeyType meKeyType;
|
||||
|
||||
public:
|
||||
AnmPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer)
|
||||
: nw4rmanager::AnmPane(pane, observer), meState(0), meKeyType(KT_Whole) {}
|
||||
virtual ~AnmPane();
|
||||
virtual void init();
|
||||
virtual void changeAnimation(u32 id);
|
||||
virtual KeyType getKeyType() const;
|
||||
virtual u32 getState();
|
||||
};
|
||||
|
||||
class WholePane : public AnmPane {
|
||||
public:
|
||||
WholePane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer)
|
||||
: AnmPane(pane, observer) { meKeyType = KT_Whole; }
|
||||
virtual ~WholePane();
|
||||
virtual void onAnmEvent(AnmPaneEvent paneEvent);
|
||||
};
|
||||
|
||||
class PicPane : public AnmPane {
|
||||
public:
|
||||
PicPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer)
|
||||
: AnmPane(pane, observer) { meKeyType = KT_Pic; }
|
||||
virtual ~PicPane();
|
||||
virtual void onAnmEvent(AnmPaneEvent paneEvent);
|
||||
};
|
||||
|
||||
static const char* paneNames[] = {
|
||||
"N_Header", "N_Body", "B_Body", "N_Footer", "Nigaoe",
|
||||
"T_Nigaoe", "B_Nigaoe", "T_Letter", "T_TouchLetter"
|
||||
};
|
||||
struct AnimationFile { u32 id; char fileName[64]; };
|
||||
static const AnimationFile animationFiles[] = {
|
||||
{0, "my_LetterL_PicFocusIn.brlan"},
|
||||
{1, "my_LetterL_SelectPic.brlan"},
|
||||
{2, "my_LetterL_ExitPic.brlan"},
|
||||
{3, "my_LetterL_PicFocusOut.brlan"},
|
||||
{4, "my_LetterL_ReturnIn.brlan"},
|
||||
{5, "my_LetterL_SendOut.brlan"},
|
||||
{6, "my_LetterL_MailIn.brlan"},
|
||||
{7, "my_LetterL_MailOut.brlan"},
|
||||
};
|
||||
struct PaneToAnimationGroup {
|
||||
s32 type;
|
||||
const char* paneName;
|
||||
u32 count;
|
||||
const AnimationFile* animations[12];
|
||||
};
|
||||
static const PaneToAnimationGroup animationGroups[] = {
|
||||
{0, "N_MemoRoot", 4, {&animationFiles[4], &animationFiles[5], &animationFiles[6], &animationFiles[7]}},
|
||||
{0, "SendPic", 4, {&animationFiles[4], &animationFiles[5], &animationFiles[6], &animationFiles[7]}},
|
||||
{1, "N_Pic", 5, {&animationFiles[0], &animationFiles[1], &animationFiles[2], &animationFiles[3], &animationFiles[4]}},
|
||||
{0, "N_SendMes", 1, {&animationFiles[5]}}
|
||||
};
|
||||
void InputForm::create(MEMAllocator* allocator, textinput::inputform::EditBuffer* editBuffer) {
|
||||
memo::InputForm::create(allocator, editBuffer);
|
||||
MEMFreeToAllocator(allocator, mpInputEventHandler);
|
||||
mpInputEventHandler = new (MEMAllocFromAllocator(allocator, sizeof(EventHandler))) EventHandler(this);
|
||||
mpInputEventHandler->setEventObserver(mpEventObserver);
|
||||
mpPaneManager->changeEventHandler(mpInputEventHandler);
|
||||
|
||||
for (u16 i = 0; i < 4; i++) {
|
||||
const PaneToAnimationGroup* group = &animationGroups[i];
|
||||
AnmPane* pane = NULL;
|
||||
switch (group->type) {
|
||||
case 1:
|
||||
pane = new (MEMAllocFromAllocator(allocator, sizeof(PicPane))) PicPane(
|
||||
getPane(group->paneName), NULL);
|
||||
break;
|
||||
case 0:
|
||||
pane = new (MEMAllocFromAllocator(allocator, sizeof(WholePane))) WholePane(
|
||||
getPane(group->paneName), NULL);
|
||||
break;
|
||||
}
|
||||
nw4r::ut::List_Append(&mAnmPanes, pane);
|
||||
|
||||
for (u16 j = 0; j < group->count; j++) {
|
||||
void* resource = mpMultiArcResourceAccessor->GetResource(0, group->animations[j]->fileName);
|
||||
AnimTransformPane* transform = static_cast<AnimTransformPane*>(
|
||||
getLayout()->CreateAnimTransform(resource, mpMultiArcResourceAccessor));
|
||||
pane->addAnimation(allocator, group->animations[j]->id, transform, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
searchAnmPane("N_Pic")->changeAnimation(3);
|
||||
mpLayout->Animate(0);
|
||||
mpLayout->CalculateMtx(mDrawInfo);
|
||||
mbPhotoScaledUp = 0;
|
||||
mbPhotoDraw = false;
|
||||
mbCloseWithSend = false;
|
||||
}
|
||||
|
||||
AnmPane::~AnmPane() {}
|
||||
|
||||
void InputForm::drawBody() {
|
||||
nw4r::lyt::Pane* bodyPane = getPane(paneNames[1]);
|
||||
f32 y = 0.0f;
|
||||
for (int row = 0; row < (mnLine - 1) / 4 + 1; row++) {
|
||||
bodyPane->SetTranslate(nw4r::math::VEC2(0.0f, y));
|
||||
bodyPane->CalculateMtx(mDrawInfo);
|
||||
bodyPane->Draw(mDrawInfo);
|
||||
y -= bodyPane->GetSize().height;
|
||||
}
|
||||
|
||||
if (!mbEdited) {
|
||||
getPane("T_TouchLetter")->Draw(mDrawInfo);
|
||||
}
|
||||
getPane("SendPic")->Draw(mDrawInfo);
|
||||
getPane("N_SendMes")->Draw(mDrawInfo);
|
||||
|
||||
nw4r::lyt::Pane* scrollPane = getPane("N_txt_scrl");
|
||||
f32 x = scrollPane->GetTranslate().x;
|
||||
getPane("N_txt_scrl")->SetTranslate(nw4r::math::VEC2(x, -6.0f));
|
||||
}
|
||||
|
||||
void InputForm::drawFooter() {
|
||||
nw4r::lyt::Pane* bodyPane = getPane(paneNames[1]);
|
||||
int row = (mnLine - 1) / 4;
|
||||
f32 y = static_cast<f32>(row) * (bodyPane->GetSize().height * -1.0f);
|
||||
nw4r::lyt::Pane* footerPane = getPane(paneNames[3]);
|
||||
footerPane->SetTranslate(nw4r::math::VEC2(0.0f, y));
|
||||
footerPane->CalculateMtx(mDrawInfo);
|
||||
footerPane->Draw(mDrawInfo);
|
||||
|
||||
if (mbPhotoDraw) {
|
||||
getPane("N_Pic")->Draw(mDrawInfo);
|
||||
}
|
||||
}
|
||||
|
||||
nw4r::lyt::Material* InputForm::getPhotoPaneMaterial() {
|
||||
return getPane("Pic")->FindMaterialByName("Pic", true);
|
||||
}
|
||||
|
||||
void InputForm::onPhotoTrig() {
|
||||
if (getEditMode() != memo::InputForm::EM_Disp || !mbPhotoDraw) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void InputForm::onPhotoPoint() {
|
||||
if (getEditMode() != memo::InputForm::EM_Disp || mbPhotoScaledUp || !mbPhotoDraw) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void InputForm::onPhotoLeft() {
|
||||
if (getEditMode() != memo::InputForm::EM_Disp || mbPhotoScaledUp || !mbPhotoDraw) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void InputForm::open() {
|
||||
memo::InputForm::open();
|
||||
switch (meType) {
|
||||
case T_MailAddressSel:
|
||||
searchAnmPane("N_MemoRoot")->changeAnimation(6);
|
||||
break;
|
||||
case T_Address:
|
||||
case T_Picture:
|
||||
case T_Reply:
|
||||
default:
|
||||
searchAnmPane("N_MemoRoot")->changeAnimation(4);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void InputForm::close() {
|
||||
memo::InputForm::close();
|
||||
if (mbCloseWithSend) {
|
||||
searchAnmPane("N_MemoRoot")->changeAnimation(5);
|
||||
searchAnmPane("SendPic")->changeAnimation(5);
|
||||
searchAnmPane("N_SendMes")->changeAnimation(5);
|
||||
} else {
|
||||
searchAnmPane("N_MemoRoot")->changeAnimation(7);
|
||||
searchAnmPane("SendPic")->changeAnimation(7);
|
||||
}
|
||||
}
|
||||
|
||||
bool InputForm::isWholePaneInAnimation() {
|
||||
return searchAnmPane("N_MemoRoot")->isInAnimation();
|
||||
}
|
||||
|
||||
void InputForm::resizePhotoPane(f32 width, f32 height) {
|
||||
nw4r::lyt::Pane* pane = getPane("Pic");
|
||||
pane->SetSize(nw4r::lyt::Size(412.0f, 309.0f));
|
||||
nw4r::lyt::Size bounds(pane->GetSize());
|
||||
nw4r::lyt::Size result(bounds);
|
||||
if (0.0f == width) {
|
||||
return;
|
||||
}
|
||||
if (0.0f == height) {
|
||||
return;
|
||||
}
|
||||
if (width > height) {
|
||||
result.height = bounds.width * height / width;
|
||||
if (result.height > bounds.height) {
|
||||
result.width = bounds.width * (bounds.height / result.height);
|
||||
result.height = bounds.height;
|
||||
}
|
||||
} else {
|
||||
result.width = bounds.height * width / height;
|
||||
if (result.width > bounds.width) {
|
||||
result.height = bounds.height * (bounds.width / result.width);
|
||||
result.width = bounds.width;
|
||||
}
|
||||
}
|
||||
pane->SetSize(result);
|
||||
}
|
||||
|
||||
void InputForm::setSendOutMessage(const wchar_t* sendOutMessage) {
|
||||
nw4r::ut::DynamicCast<nw4r::lyt::TextBox*>(
|
||||
mpLayout->GetRootPane()->FindPaneByName("T_SendMes", true))->SetString(sendOutMessage);
|
||||
}
|
||||
|
||||
void EventHandler::onTiEvent(gui::PaneComponent* paneComponent, u32 event, Input* input) {
|
||||
if (!static_cast<InputForm*>(mpMemoForm)->isPhotoScaledUp()) {
|
||||
memo::EventHandler::onTiEvent(paneComponent, event, input);
|
||||
}
|
||||
nw4r::lyt::Pane* pane = paneComponent->getPane();
|
||||
const char* paneName = pane->GetName();
|
||||
if (paneName[0] == 'B') {
|
||||
if (event == gui::GUIComponent::EVENT_TRIG && (input->trigger & 0x800) &&
|
||||
util::strcmp("B_Pic", paneName)) {
|
||||
static_cast<InputForm*>(mpMemoForm)->onPhotoTrig();
|
||||
}
|
||||
if (event == 0 && util::strcmp("B_Pic", paneName)) {
|
||||
static_cast<InputForm*>(mpMemoForm)->onPhotoPoint();
|
||||
}
|
||||
if (event == 1 && util::strcmp("B_Pic", paneName)) {
|
||||
static_cast<InputForm*>(mpMemoForm)->onPhotoLeft();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool InputForm::isPhotoScaledUp() {
|
||||
return mbPhotoScaledUp;
|
||||
}
|
||||
|
||||
u32 AnmPane::getState() {
|
||||
return meState;
|
||||
}
|
||||
|
||||
void AnmPane::changeAnimation(u32 id) {
|
||||
meState = id;
|
||||
nw4rmanager::AnmPane::changeAnimation(id);
|
||||
}
|
||||
|
||||
AnmPane::KeyType AnmPane::getKeyType() const {
|
||||
return meKeyType;
|
||||
}
|
||||
|
||||
void AnmPane::init() {
|
||||
meState = 0;
|
||||
}
|
||||
|
||||
PicPane::~PicPane() {}
|
||||
|
||||
void PicPane::onAnmEvent(AnmPaneEvent paneEvent) {}
|
||||
|
||||
WholePane::~WholePane() {}
|
||||
|
||||
void WholePane::onAnmEvent(AnmPaneEvent paneEvent) {}
|
||||
|
||||
InputForm::~InputForm() {}
|
||||
|
||||
EventHandler::~EventHandler() {}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
534
src/keyboard/tiHKBManager.cpp
Normal file
534
src/keyboard/tiHKBManager.cpp
Normal file
@@ -0,0 +1,534 @@
|
||||
#define TIHKBMANAGER_IMPLEMENTATION
|
||||
#include "keyboard/tiHKBManager.h"
|
||||
#include <revolution/os.h>
|
||||
|
||||
extern "C" {
|
||||
_KBDEc KBDSetLedsAsync(u8, u8, void (*)(_KBDEc, void*), void*);
|
||||
void KBDSetLockProcessing(u8, int);
|
||||
int KBDSetCountry(u8, u32);
|
||||
int KBDSetModState(u8, u32);
|
||||
_KBDEc KBDSetLeds(u8, u8);
|
||||
u16 KBDTranslateHidCode(u8, u32, u32);
|
||||
void KBDInitRegionUS();
|
||||
void KBDInit();
|
||||
void KBDSetAttachCallback(void (*)(KBDDevEvent*));
|
||||
void KBDSetDetachCallback(void (*)(KBDDevEvent*));
|
||||
void KBDSetKeyCallback(void (*)(KBDKeyEvent*));
|
||||
}
|
||||
|
||||
namespace textinput {
|
||||
namespace input {
|
||||
|
||||
HKBManager HKBManager::sInstance;
|
||||
|
||||
// KBD callbacks encode the device in the first byte of the opaque pointer value.
|
||||
struct LedCallbackData {
|
||||
union {
|
||||
void* pointer;
|
||||
u8 device;
|
||||
};
|
||||
u32 leds;
|
||||
};
|
||||
|
||||
void HKBManager::SetLedCB(_KBDEc result, void* userData) {
|
||||
if (result == KBD_EC_BUSY) {
|
||||
LedCallbackData received;
|
||||
received.pointer = userData;
|
||||
LedCallbackData callback;
|
||||
callback.device = received.device;
|
||||
const u8 leds = callback.leds = 0;
|
||||
u32 interrupts = OSDisableInterrupts();
|
||||
u32 mask = 1 << received.device;
|
||||
sInstance.retryDevices &= ~mask;
|
||||
OSRestoreInterrupts(interrupts);
|
||||
if (KBDSetLedsAsync(received.device, leds, SetLedCB, callback.pointer) == KBD_EC_BUSY) {
|
||||
interrupts = OSDisableInterrupts();
|
||||
sInstance.retryDevices |= mask;
|
||||
OSRestoreInterrupts(interrupts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HKBManager::KBDListenerOwn::OnAttach(KBDDevEvent* event) {
|
||||
HKBManager* owner;
|
||||
u8 device;
|
||||
if (event->device >= 2) {
|
||||
KBDSetLockProcessing(event->device, 0);
|
||||
device = event->device;
|
||||
owner = manager;
|
||||
LedCallbackData callback;
|
||||
callback.device = device;
|
||||
const u8 leds = callback.leds = 0;
|
||||
u32 interrupts = OSDisableInterrupts();
|
||||
u32 mask = 1 << device;
|
||||
owner->retryDevices &= ~mask;
|
||||
OSRestoreInterrupts(interrupts);
|
||||
if (KBDSetLedsAsync(device, leds, SetLedCB, callback.pointer) == KBD_EC_BUSY) {
|
||||
interrupts = OSDisableInterrupts();
|
||||
owner->retryDevices |= mask;
|
||||
OSRestoreInterrupts(interrupts);
|
||||
}
|
||||
} else {
|
||||
manager->attached[event->device] = 1;
|
||||
KBDSetLockProcessing(event->device, 0);
|
||||
manager->states[event->device].retryLeds = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void HKBManager::KBDListenerOwn::OnDetach(KBDDevEvent* event) {
|
||||
u8 device = event->device;
|
||||
if (device >= 2) return;
|
||||
HKBManager* owner = manager;
|
||||
owner->attached[device] = 0;
|
||||
owner->states[device].Clear();
|
||||
}
|
||||
|
||||
void HKBManager::KBDListenerOwn::OnKeyEvent(KBDKeyEvent* event) {
|
||||
if (event->device >= 2) return;
|
||||
if (event->flags & 2) return;
|
||||
manager->states[event->device].NotifyEvent(event->flags & 1, event->key);
|
||||
}
|
||||
|
||||
void HKBManager::AttachCB(KBDDevEvent* event) {
|
||||
KBDListenerOwn* current = &sInstance.listener;
|
||||
while (current != 0) {
|
||||
current->OnAttach(event);
|
||||
current = current->next;
|
||||
if (current == &sInstance.listener) break;
|
||||
}
|
||||
}
|
||||
|
||||
void HKBManager::DetachCB(KBDDevEvent* event) {
|
||||
KBDListenerOwn* current = &sInstance.listener;
|
||||
while (current != 0) {
|
||||
current->OnDetach(event);
|
||||
current = current->next;
|
||||
if (current == &sInstance.listener) break;
|
||||
}
|
||||
}
|
||||
|
||||
void HKBManager::KeyEventCB(KBDKeyEvent* event) {
|
||||
KBDListenerOwn* current = &sInstance.listener;
|
||||
while (current != 0) {
|
||||
current->OnKeyEvent(event);
|
||||
current = current->next;
|
||||
if (current == &sInstance.listener) break;
|
||||
}
|
||||
}
|
||||
|
||||
HKBManager::HKBManager()
|
||||
: initialized(0), lockState(0), retryDevices(0), allowedCharacters(0),
|
||||
allowedCharacterCount(0), listener(this) {
|
||||
for (u32 device = 0; device < 2; device++) {
|
||||
attached[device] = 0;
|
||||
states[static_cast<u8>(device)].Initialize(static_cast<u8>(device));
|
||||
}
|
||||
}
|
||||
|
||||
HKBManager::KBDListenerOwn::~KBDListenerOwn() {}
|
||||
|
||||
void HKBManager::Initialize() {
|
||||
if (initialized == 0) {
|
||||
initialized = 1;
|
||||
KBDInitRegionUS();
|
||||
KBDInit();
|
||||
if (listener.previous == 0) {
|
||||
KBDSetAttachCallback(AttachCB);
|
||||
KBDSetDetachCallback(DetachCB);
|
||||
KBDSetKeyCallback(KeyEventCB);
|
||||
}
|
||||
u32 device = 0;
|
||||
do {
|
||||
KBDSetCountry(static_cast<u8>(device), states[static_cast<u8>(device)].country);
|
||||
device++;
|
||||
} while (device < 2);
|
||||
}
|
||||
}
|
||||
|
||||
void HKBManager::ClearState() {
|
||||
for (u32 device = 0; device < 2; device++) {
|
||||
states[static_cast<u8>(device)].Clear();
|
||||
}
|
||||
}
|
||||
|
||||
u32 HKBManager::GetModifierState() const {
|
||||
u32 modifiers = states[0].modifiers;
|
||||
u32 mask = states[0].forceMask;
|
||||
modifiers &= ~mask;
|
||||
modifiers |= states[0].forceState & mask;
|
||||
u32 forceMask;
|
||||
u32 force;
|
||||
force = states[1].modifiers;
|
||||
forceMask = states[1].forceMask;
|
||||
force &= ~forceMask;
|
||||
force |= states[1].forceState & forceMask;
|
||||
return modifiers | force;
|
||||
}
|
||||
void HKBManager::SetCountry(u8 country) {
|
||||
KeyState_* state;
|
||||
u32 device = 0;
|
||||
do {
|
||||
state = &states[static_cast<u8>(device)];
|
||||
state->country = country;
|
||||
KBDSetCountry(device & 0xff, country);
|
||||
KBDSetModState(state->device, state->modifiers);
|
||||
u32 modifiers = state->modifiers;
|
||||
u8 leds = 0;
|
||||
if ((modifiers & 0x100) != 0) {
|
||||
leds |= 1;
|
||||
}
|
||||
if ((modifiers & 0x200) != 0) {
|
||||
leds |= 2;
|
||||
}
|
||||
if ((modifiers & 0x400) != 0) {
|
||||
leds |= 4;
|
||||
}
|
||||
if (KBDSetLeds(state->device, leds) == 7) {
|
||||
state->retryLeds = 1;
|
||||
}
|
||||
device++;
|
||||
} while (device < 2);
|
||||
}
|
||||
|
||||
void HKBManager::SetModifierState(u32 state, u32 mask) {
|
||||
lockState = lockState & ~mask | state & mask;
|
||||
KeyState_* slot;
|
||||
u32 modifiers;
|
||||
u32 global;
|
||||
u32 device = 0;
|
||||
do {
|
||||
slot = &states[static_cast<u8>(device)];
|
||||
modifiers = slot->modifiers;
|
||||
global = lockState & 0x700;
|
||||
bool changed = global != (modifiers & 0x700);
|
||||
slot->modifiers &= ~0x700;
|
||||
slot->modifiers |= lockState;
|
||||
if (changed &&
|
||||
attached[static_cast<u8>(device)] != 0) {
|
||||
KBDSetModState(slot->device, slot->modifiers);
|
||||
modifiers = slot->modifiers;
|
||||
u8 leds = 0;
|
||||
if ((modifiers & 0x100) != 0) {
|
||||
leds |= 1;
|
||||
}
|
||||
if ((modifiers & 0x200) != 0) {
|
||||
leds |= 2;
|
||||
}
|
||||
if ((modifiers & 0x400) != 0) {
|
||||
leds |= 4;
|
||||
}
|
||||
if (KBDSetLeds(slot->device, leds) == 7) {
|
||||
slot->retryLeds = 1;
|
||||
}
|
||||
}
|
||||
device++;
|
||||
} while (device < 2);
|
||||
}
|
||||
|
||||
void HKBManager::SetForceModifierState(u32 state, u32 mask) {
|
||||
states[0].forceState = state;
|
||||
states[0].forceMask = mask;
|
||||
states[1].forceState = state;
|
||||
states[1].forceMask = mask;
|
||||
}
|
||||
|
||||
void HKBManager::Update() {
|
||||
if (initialized != 0) {
|
||||
u32 mask;
|
||||
u32 device = 2;
|
||||
do {
|
||||
u8 shiftIndex = static_cast<u8>(device);
|
||||
mask = 1 << shiftIndex;
|
||||
if ((retryDevices & mask) != 0) {
|
||||
LedCallbackData callback;
|
||||
callback.device = static_cast<u8>(device);
|
||||
const u8 leds = callback.leds = 0;
|
||||
u32 interrupts = OSDisableInterrupts();
|
||||
retryDevices &= ~mask;
|
||||
OSRestoreInterrupts(interrupts);
|
||||
if (KBDSetLedsAsync(device & 0xff, leds,
|
||||
SetLedCB,
|
||||
callback.pointer) == 7) {
|
||||
interrupts = OSDisableInterrupts();
|
||||
retryDevices |= mask;
|
||||
OSRestoreInterrupts(interrupts);
|
||||
}
|
||||
}
|
||||
device++;
|
||||
} while (device < 4);
|
||||
u32 updateIndex = 0;
|
||||
do {
|
||||
states[updateIndex & 0xff].Update();
|
||||
updateIndex++;
|
||||
} while (updateIndex < 2);
|
||||
}
|
||||
}
|
||||
|
||||
HKBManager::KeySet HKBManager::GetTriggeredKeySet() const {
|
||||
KeySet keys;
|
||||
keys.manager = this;
|
||||
keys.type = 1;
|
||||
keys.index = -1;
|
||||
keys.device = 0;
|
||||
keys.vcode = 0;
|
||||
return keys.GetNext();
|
||||
}
|
||||
|
||||
HKBManager::KeySet HKBManager::GetReleasedKeySet() const {
|
||||
KeySet keys;
|
||||
keys.manager = this;
|
||||
keys.type = 2;
|
||||
keys.index = -1;
|
||||
keys.device = 0;
|
||||
keys.vcode = 0;
|
||||
return keys.GetNext();
|
||||
}
|
||||
|
||||
HKBManager::KeySet HKBManager::GetRepeatedKeySet() const {
|
||||
KeySet keys;
|
||||
keys.manager = this;
|
||||
keys.type = 3;
|
||||
keys.index = -1;
|
||||
keys.device = 0;
|
||||
keys.vcode = 0;
|
||||
return keys.GetNext();
|
||||
}
|
||||
|
||||
void HKBManager::KeyState_::NotifyEvent(u8 down, u8 code) {
|
||||
u32 index;
|
||||
s32 found = -1;
|
||||
if (down == 1) {
|
||||
for (index = 0; index < 8; index++) {
|
||||
if ((pending & (1 << index)) != 0) {
|
||||
if (code == pendingKeys[index]) { found = index; break; }
|
||||
} else {
|
||||
found = index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found >= 0) {
|
||||
pendingKeys[found] = code;
|
||||
pending |= 1 << found;
|
||||
}
|
||||
} else {
|
||||
for (index = 0; index < 8; index++) {
|
||||
if ((pending & (1 << index)) && code == pendingKeys[index]) {
|
||||
found = index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found >= 0) pending &= ~(1 << found);
|
||||
}
|
||||
}
|
||||
|
||||
void HKBManager::KeyState_::Update() {
|
||||
u32 interrupts = OSDisableInterrupts();
|
||||
previous = current;
|
||||
current = pending;
|
||||
for (u32 slot = 0; slot < 8; slot++) {
|
||||
previousKeys[slot] = currentKeys[slot];
|
||||
currentKeys[slot] = pendingKeys[slot];
|
||||
}
|
||||
OSRestoreInterrupts(interrupts);
|
||||
UpdateModState_();
|
||||
u32 bit;
|
||||
u32 index;
|
||||
u32 heldKeys = current;
|
||||
triggered = 0;
|
||||
held = heldKeys;
|
||||
for (index = 0; index < 8; index++) {
|
||||
bit = 1 << index;
|
||||
if ((current & bit) != 0) {
|
||||
if ((previous & bit) == 0 || previousKeys[index] != currentKeys[index]) {
|
||||
triggered |= bit;
|
||||
}
|
||||
}
|
||||
}
|
||||
released = 0;
|
||||
for (index = 0; index < 8; index++) {
|
||||
bit = 1 << index;
|
||||
if ((previous & bit) != 0) {
|
||||
if ((current & bit) == 0 || previousKeys[index] != currentKeys[index]) {
|
||||
released |= bit;
|
||||
}
|
||||
}
|
||||
}
|
||||
repeated = 0;
|
||||
for (index = 0; index < 8; index++) {
|
||||
bit = 1 << index;
|
||||
if ((current & bit) != 0) {
|
||||
if ((triggered & bit) != 0) {
|
||||
repeatDelay[index] = 30;
|
||||
repeated |= bit;
|
||||
}
|
||||
repeatDelay[index]--;
|
||||
if (repeatDelay[index] == 0) {
|
||||
repeatDelay[index] = 8;
|
||||
repeated |= bit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HKBManager::KeyState_::UpdateModState_() {
|
||||
u32 index;
|
||||
u32 oldModifiers = modifiers;
|
||||
modifiers = oldModifiers & 0xffffffd0;
|
||||
index = 0;
|
||||
for (; index < 8; index++) {
|
||||
u32 keySet;
|
||||
u8 slot;
|
||||
keySet = current;
|
||||
slot = index;
|
||||
if ((keySet & (1 << slot)) != 0) {
|
||||
u8 code = currentKeys[slot];
|
||||
if (code == 0xe5 || code == 0xe1) {
|
||||
modifiers |= 2;
|
||||
} else if (code == 0xe4 || code == 0xe0) {
|
||||
modifiers |= 1;
|
||||
} else if (code == 0xe7 || code == 0xe3) {
|
||||
modifiers |= 8;
|
||||
} else if (code == 0xe2) {
|
||||
modifiers |= 4;
|
||||
} else if (code == 0xe6) {
|
||||
if (static_cast<s32>(country) == 0xf ||
|
||||
static_cast<s32>(country) == 0x21) {
|
||||
modifiers |= 4;
|
||||
} else {
|
||||
modifiers |= 0x20;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((oldModifiers & 0x700) != (modifiers & 0x700) || retryLeds != 0) {
|
||||
retryLeds = 0;
|
||||
KBDSetModState(device, modifiers);
|
||||
u32 modifiers = this->modifiers;
|
||||
u8 leds = 0;
|
||||
if ((modifiers & 0x100) != 0) {
|
||||
leds |= 1;
|
||||
}
|
||||
if ((modifiers & 0x200) != 0) {
|
||||
leds |= 2;
|
||||
}
|
||||
if ((modifiers & 0x400) != 0) {
|
||||
leds |= 4;
|
||||
}
|
||||
if (KBDSetLeds(device, leds) == 7) {
|
||||
retryLeds = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
u8 HKBManager::KeySet::GetKey() const {
|
||||
if (!CheckValidity()) return 0;
|
||||
switch (type) {
|
||||
case 0: return manager->states[device].currentKeys[index];
|
||||
case 1: return manager->states[device].currentKeys[index];
|
||||
case 2: return manager->states[device].previousKeys[index];
|
||||
case 3: return manager->states[device].currentKeys[index];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 HKBManager::KeySet::GetWChar() const {
|
||||
s32 code = GetVCode();
|
||||
if (static_cast<u16>(code) >= 0xf130 && static_cast<u16>(code) <= 0xf139) {
|
||||
code = code - 0xf100 & 0xffff;
|
||||
} else {
|
||||
u32 lowCode = code & 0xffff;
|
||||
if (lowCode == 0xf10d) {
|
||||
code = 0xf1cd;
|
||||
} else if (lowCode >= 0xf100 && lowCode <= 0xf13f) {
|
||||
code = code - 0xf100 & 0xffff;
|
||||
} else if ((static_cast<u32>(code) & 0xffff) >= 0xf140 && (static_cast<u32>(code) & 0xffff) <= 0xf17f) {
|
||||
code = code + 0x40 & 0xffff;
|
||||
}
|
||||
}
|
||||
u16 character = code;
|
||||
if ((character & 0xf000) == 0xf000) {
|
||||
code = 0;
|
||||
} else if ((static_cast<u32>(code) & 0xffff) == 0xeeee) {
|
||||
code = 0;
|
||||
} else if ((static_cast<u32>(code) & 0xffff) < 0x20) {
|
||||
code = 0;
|
||||
}
|
||||
u32 index = 0;
|
||||
const HKBManager* owner = manager;
|
||||
if (owner->allowedCharacters == 0) return code;
|
||||
u32 count = owner->allowedCharacterCount;
|
||||
if (count == 0) return code;
|
||||
for (; index < count; index++) {
|
||||
if ((static_cast<u32>(code) & 0xffff) == owner->allowedCharacters[index]) return code;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 HKBManager::KeySet::GetVCode() const {
|
||||
u32 modifiers;
|
||||
if (!CheckValidity()) return 0;
|
||||
if (vcode) return vcode;
|
||||
u32 first = manager->states[0].modifiers;
|
||||
u32 mask = manager->states[0].forceMask;
|
||||
first &= ~mask;
|
||||
first |= manager->states[0].forceState & mask;
|
||||
u32 secondMask;
|
||||
u32 second;
|
||||
second = manager->states[1].modifiers;
|
||||
secondMask = manager->states[1].forceMask;
|
||||
second &= ~secondMask;
|
||||
second |= manager->states[1].forceState & secondMask;
|
||||
modifiers = first | second;
|
||||
if ((modifiers & 0xd) != 0 && (modifiers & 5) != 5) return 0;
|
||||
switch (type) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 3:
|
||||
if ((manager->states[device].current & (1 << index)) != 0) {
|
||||
vcode = KBDTranslateHidCode(manager->states[device].currentKeys[index], modifiers,
|
||||
manager->states[device].country);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if ((manager->states[device].previous & (1 << index)) != 0) {
|
||||
vcode = KBDTranslateHidCode(manager->states[device].previousKeys[index], modifiers,
|
||||
manager->states[device].country);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return vcode;
|
||||
}
|
||||
|
||||
u32 HKBManager::KeySet::IsValid() const {
|
||||
return CheckValidity();
|
||||
}
|
||||
|
||||
HKBManager::KeySet HKBManager::KeySet::GetNext() const {
|
||||
KeySet next(manager, type);
|
||||
if (manager != 0) {
|
||||
next.device = device;
|
||||
while (next.device < 2) {
|
||||
u32 keyFlags = 0;
|
||||
switch (type) {
|
||||
case 0: keyFlags = manager->states[next.device].held; break;
|
||||
case 1: keyFlags = manager->states[next.device].triggered; break;
|
||||
case 2: keyFlags = manager->states[next.device].released; break;
|
||||
case 3: keyFlags = manager->states[next.device].repeated; break;
|
||||
}
|
||||
next.index = index + 1;
|
||||
while (next.index < 8) {
|
||||
if ((keyFlags & (1 << next.index)) != 0) return next;
|
||||
next.index++;
|
||||
}
|
||||
next.index = -1;
|
||||
next.device++;
|
||||
}
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
|
||||
HKBManager::~HKBManager() {}
|
||||
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
327
src/keyboard/tiManager.cpp
Normal file
327
src/keyboard/tiManager.cpp
Normal file
@@ -0,0 +1,327 @@
|
||||
#define TIMANAGER_IMPLEMENTATION
|
||||
#include "keyboard/tiPcKeyboard.h"
|
||||
#include "keyboard/tiCellPhone.h"
|
||||
#include "keyboard/tiInputForm.h"
|
||||
#include <revolution/sc.h>
|
||||
#include <new>
|
||||
|
||||
namespace textinput {
|
||||
namespace keyboard {
|
||||
namespace pctype {
|
||||
class Sample : public LayoutByNW4R {
|
||||
public:
|
||||
Sample(Manager* manager, nw4r::lyt::MultiArcResourceAccessor* accessor, EventObserver* observer, const char* layoutName)
|
||||
: LayoutByNW4R(manager, accessor, observer, layoutName) {}
|
||||
virtual ~Sample();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace textinput {
|
||||
namespace keyboard {
|
||||
namespace cellphonetype {
|
||||
class Sample : public LayoutByNW4R {
|
||||
public:
|
||||
Sample(Manager* manager, nw4r::lyt::MultiArcResourceAccessor* accessor, EventObserver* observer, const char* layoutName)
|
||||
: LayoutByNW4R(manager, accessor, observer, layoutName) {}
|
||||
virtual ~Sample();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace textinput {
|
||||
namespace candidatebox {
|
||||
class Sample : public LayoutByNW4R {
|
||||
public:
|
||||
Sample(Manager* manager, nw4r::lyt::MultiArcResourceAccessor* accessor, EventObserver* observer, const char* layoutName)
|
||||
: LayoutByNW4R(manager, accessor, observer, layoutName) {}
|
||||
virtual ~Sample();
|
||||
};
|
||||
}
|
||||
}
|
||||
namespace textinput {
|
||||
namespace inputform {
|
||||
class Sample : public LayoutByNW4R {
|
||||
public:
|
||||
Sample(Manager* manager, nw4r::lyt::MultiArcResourceAccessor* accessor, EventObserver* observer, const char* layoutName)
|
||||
: LayoutByNW4R(manager, accessor, layoutName, observer, NULL) {}
|
||||
virtual ~Sample();
|
||||
};
|
||||
}
|
||||
}
|
||||
#include "keyboard/tiToolBar.h"
|
||||
#include "keyboard/tiPredictLang.h"
|
||||
namespace textinput { namespace keyboard {
|
||||
namespace signwindow {
|
||||
class Sample : public LayoutByNW4R {
|
||||
public:
|
||||
Sample(Manager* manager, nw4r::lyt::MultiArcResourceAccessor* accessor, EventObserver* observer, const char* layoutName)
|
||||
: LayoutByNW4R(manager, accessor, observer, layoutName) {}
|
||||
virtual ~Sample();
|
||||
};
|
||||
}
|
||||
}}
|
||||
#include "keyboard/tiManager.h"
|
||||
namespace textinput {
|
||||
static EventObserver defaultEventObserver;
|
||||
|
||||
Manager::Manager(MEMAllocator* allocator, nw4r::lyt::MultiArcResourceAccessor* accessor, EventObserver* observer)
|
||||
: mpAllocator(allocator), mpMultiArcResourceAccessor(accessor), mpEditBuffer(NULL), mpHWKeyboard(NULL), mpPCKeyboard(NULL),
|
||||
mpCellPhoneKeyboard(NULL), mpInputForm(NULL), mpCandidateBox(NULL), mpToolBar(NULL), mpPredictLanguageDialog(NULL),
|
||||
mpSignWindow(NULL), mpEventObserver(observer), meDestination(DST_JP), meLanguage(JP), mbAspectRatio4x3(true) {
|
||||
if (observer == NULL) mpEventObserver = &defaultEventObserver;
|
||||
}
|
||||
|
||||
Manager::~Manager() {
|
||||
if (mpPCKeyboard) { mpPCKeyboard->~LayoutByNW4R(); MEMFreeToAllocator(mpAllocator, mpPCKeyboard); }
|
||||
if (mpCellPhoneKeyboard) { mpCellPhoneKeyboard->~LayoutByNW4R(); MEMFreeToAllocator(mpAllocator, mpCellPhoneKeyboard); }
|
||||
if (mpInputForm) { mpInputForm->~LayoutByNW4R(); MEMFreeToAllocator(mpAllocator, mpInputForm); }
|
||||
if (mpCandidateBox) { mpCandidateBox->~LayoutByNW4R(); MEMFreeToAllocator(mpAllocator, mpCandidateBox); }
|
||||
if (mpToolBar) { mpToolBar->~LayoutByNW4R(); MEMFreeToAllocator(mpAllocator, mpToolBar); }
|
||||
if (mpPredictLanguageDialog) { mpPredictLanguageDialog->~LayoutByNW4R(); MEMFreeToAllocator(mpAllocator, mpPredictLanguageDialog); }
|
||||
if (mpSignWindow) { mpSignWindow->~LayoutByNW4R(); MEMFreeToAllocator(mpAllocator, mpSignWindow); }
|
||||
if (mpHWKeyboard) { mpHWKeyboard->~HWKeyboard(); MEMFreeToAllocator(mpAllocator, mpHWKeyboard); }
|
||||
if (mpEditBuffer) { mpEditBuffer->~EditBuffer(); MEMFreeToAllocator(mpAllocator, mpEditBuffer); }
|
||||
|
||||
}
|
||||
|
||||
keyboard::hwkey::HWKeyboard::~HWKeyboard() {}
|
||||
|
||||
void Manager::create(MEMAllocator*) {
|
||||
mpEditBuffer = createEditBuffer();
|
||||
mpEditBuffer->create(mpAllocator);
|
||||
mpHWKeyboard = createHWKeyboard();
|
||||
mpPCKeyboard = static_cast<keyboard::pctype::LayoutByNW4R*>(createPCTypeKeyboard());
|
||||
mpPCKeyboard->create(mpAllocator);
|
||||
mpCellPhoneKeyboard = static_cast<keyboard::cellphonetype::LayoutByNW4R*>(createCellPhoneTypeKeyboard());
|
||||
mpCellPhoneKeyboard->create(mpAllocator);
|
||||
mpInputForm = createInputForm();
|
||||
mpInputForm->create(mpAllocator, mpEditBuffer);
|
||||
mpCandidateBox = static_cast<candidatebox::LayoutByNW4R*>(createCandidateBox());
|
||||
mpCandidateBox->create(mpAllocator);
|
||||
mpToolBar = static_cast<toolbar::LayoutByNW4R*>(createToolBar());
|
||||
mpToolBar->create(mpAllocator);
|
||||
mpPredictLanguageDialog = static_cast<predictlang::LayoutByNW4R*>(createPredictLanguageDialog());
|
||||
mpPredictLanguageDialog->create(mpAllocator);
|
||||
mpSignWindow = static_cast<keyboard::signwindow::LayoutByNW4R*>(createSignWindow());
|
||||
mpSignWindow->create(mpAllocator);
|
||||
if (SCGetAspectRatio() == 1) { setLayoutScaleFor16x9(); mbAspectRatio4x3 = false; }
|
||||
else { setLayoutScaleFor4x3(); mbAspectRatio4x3 = true; }
|
||||
init();
|
||||
}
|
||||
|
||||
void Manager::initAspect() {
|
||||
if (SCGetAspectRatio() == 1) { setLayoutScaleFor16x9(); mbAspectRatio4x3 = false; }
|
||||
else { setLayoutScaleFor4x3(); mbAspectRatio4x3 = true; }
|
||||
}
|
||||
|
||||
void Manager::init() {
|
||||
input::HKBManager::getInstance().ClearState();
|
||||
mpInputForm->clearSender();
|
||||
mpHWKeyboard->setCommandReceiver(mpInputForm);
|
||||
mpPCKeyboard->setCommandReceiver(mpInputForm);
|
||||
mpCellPhoneKeyboard->setCommandReceiver(mpInputForm);
|
||||
mpCandidateBox->setCommandReceiver(mpInputForm);
|
||||
mpPredictLanguageDialog->setCommandReceiver(mpInputForm);
|
||||
mpSignWindow->setCommandReceiver(mpInputForm);
|
||||
mpInputForm->setCandidateBox(mpCandidateBox);
|
||||
mpPCKeyboard->setPredictLanguageDialog(mpPredictLanguageDialog);
|
||||
mpPCKeyboard->setSignWindow(mpSignWindow);
|
||||
mpCellPhoneKeyboard->setPredictLanguageDialog(mpPredictLanguageDialog);
|
||||
mpCellPhoneKeyboard->setSignWindow(mpSignWindow);
|
||||
if (mbAspectRatio4x3 == true) setLayoutScaleFor4x3();
|
||||
else setLayoutScaleFor16x9();
|
||||
mpPredictLanguageDialog->setDestination(meDestination);
|
||||
mpInputForm->setDestination(meDestination);
|
||||
mpInputForm->setLanguage(meLanguage);
|
||||
mpPCKeyboard->setLanguage(meLanguage);
|
||||
mpCellPhoneKeyboard->setLanguage(meLanguage);
|
||||
mpSignWindow->setLanguage(meLanguage);
|
||||
mpCandidateBox->setLanguage(meLanguage);
|
||||
mpToolBar->setLanguage(meLanguage);
|
||||
mpPredictLanguageDialog->setLanguage(meLanguage);
|
||||
mpHWKeyboard->setLanguage(meDestination, meLanguage);
|
||||
mpHWKeyboard->init();
|
||||
mpPCKeyboard->init();
|
||||
mpCellPhoneKeyboard->init();
|
||||
mpInputForm->init();
|
||||
mpCandidateBox->init();
|
||||
mpToolBar->init();
|
||||
mpPredictLanguageDialog->init();
|
||||
mpSignWindow->init();
|
||||
setFixedPredictionJP(0, NULL);
|
||||
setSecretInputMode(false);
|
||||
}
|
||||
|
||||
void Manager::setFixedPredictionJP(int count, const char** predictions) {
|
||||
static_cast<tistring::WithAtok*>(getInputForm()->getAtokString())->setFixPrediction(count, predictions);
|
||||
}
|
||||
|
||||
void Manager::calc() {
|
||||
if (mpToolBar->isQwerty()) mpPCKeyboard->calc();
|
||||
else mpCellPhoneKeyboard->calc();
|
||||
static_cast<nw4rmanager::Layout&>(*mpToolBar).calc();
|
||||
mpCandidateBox->calc();
|
||||
mpInputForm->calc();
|
||||
if (mpPredictLanguageDialog->isActive()) static_cast<nw4rmanager::Layout&>(*mpPredictLanguageDialog).calc();
|
||||
if (mpSignWindow->isActive()) static_cast<nw4rmanager::Layout&>(*mpSignWindow).calc();
|
||||
}
|
||||
|
||||
void Manager::draw() {
|
||||
GXSetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE);
|
||||
mpToolBar->draw();
|
||||
mpInputForm->draw();
|
||||
if (mpToolBar->isQwerty()) mpPCKeyboard->draw();
|
||||
else mpCellPhoneKeyboard->draw();
|
||||
mpCandidateBox->draw();
|
||||
if (mpPredictLanguageDialog->isActive()) mpPredictLanguageDialog->draw();
|
||||
if (mpSignWindow->isActive()) mpSignWindow->draw();
|
||||
}
|
||||
|
||||
bool Manager::updateInput(int channel, f32 x, f32 y, u32 trigger, u32 hold, u32 release) {
|
||||
bool wasQwerty = mpToolBar->isQwerty();
|
||||
nw4rmanager::TiEventHandler::Input input;
|
||||
input.controller = channel;
|
||||
input.x = x;
|
||||
input.y = y;
|
||||
input.trigger = trigger;
|
||||
input.hold = hold;
|
||||
input.release = release;
|
||||
mpHWKeyboard->updateInput(channel, x, y, trigger, hold, release, &input);
|
||||
bool handled;
|
||||
if (mpPredictLanguageDialog->isActive()) {
|
||||
return static_cast<nw4rmanager::Layout&>(*mpPredictLanguageDialog).updateInput(channel, x, y, trigger, hold, release, &input);
|
||||
}
|
||||
mpInputForm->updateInputCommon(channel, trigger, hold, release, &input);
|
||||
if (mpSignWindow->isActive()) {
|
||||
return mpSignWindow->updateInput(channel, x, y, trigger, hold, release, &input);
|
||||
} else {
|
||||
bool keyboardHandled;
|
||||
if (wasQwerty) keyboardHandled = mpPCKeyboard->updateInput(channel, x, y, trigger, hold, release, &input);
|
||||
else keyboardHandled = mpCellPhoneKeyboard->updateInput(channel, x, y, trigger, hold, release, &input);
|
||||
bool toolbarHandled = static_cast<nw4rmanager::Layout&>(*mpToolBar).updateInput(channel, x, y, trigger, hold, release, &input);
|
||||
bool candidateHandled = static_cast<nw4rmanager::Layout&>(*mpCandidateBox).updateInput(channel, x, y, trigger, hold, release, &input);
|
||||
bool formHandled = mpInputForm->updateInput(channel, x, y, trigger, hold, release, &input);
|
||||
handled = (keyboardHandled | candidateHandled) | (formHandled | toolbarHandled);
|
||||
}
|
||||
if (wasQwerty != mpToolBar->isQwerty()) {
|
||||
getInputForm()->onCommand(static_cast<CommandReceiver::INPUT_COMMAND>(6), NULL);
|
||||
mpCandidateBox->checkValidation();
|
||||
if (mpToolBar->isQwerty()) mpPCKeyboard->onActive();
|
||||
else mpCellPhoneKeyboard->onActive();
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
bool Manager::updateInput(input::HKBManager& keyboard) {
|
||||
bool wasQwerty = mpToolBar->isQwerty();
|
||||
bool handled;
|
||||
if (mpPredictLanguageDialog->isActive()) return static_cast<nw4rmanager::Layout&>(*mpPredictLanguageDialog).updateInput(keyboard);
|
||||
else if (mpSignWindow->isActive()) return mpSignWindow->updateInput(keyboard);
|
||||
else {
|
||||
bool keyboardHandled;
|
||||
if (wasQwerty) keyboardHandled = mpPCKeyboard->updateInput(keyboard);
|
||||
else keyboardHandled = mpCellPhoneKeyboard->updateInput(keyboard);
|
||||
bool toolbarHandled = static_cast<nw4rmanager::Layout&>(*mpToolBar).updateInput(keyboard);
|
||||
bool candidateHandled = static_cast<nw4rmanager::Layout&>(*mpCandidateBox).updateInput(keyboard);
|
||||
bool formHandled = mpInputForm->updateInput(keyboard);
|
||||
handled = (keyboardHandled | candidateHandled) | (formHandled | toolbarHandled);
|
||||
}
|
||||
if (wasQwerty != mpToolBar->isQwerty()) {
|
||||
getInputForm()->onCommand(static_cast<CommandReceiver::INPUT_COMMAND>(6), NULL);
|
||||
mpCandidateBox->checkValidation();
|
||||
if (mpToolBar->isQwerty()) mpPCKeyboard->onActive();
|
||||
else mpCellPhoneKeyboard->onActive();
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
wchar_t* Manager::getWCString() const { return mpInputForm->getWCString(); }
|
||||
void Manager::setWCString(const wchar_t* string) { mpInputForm->inputform::Base::setString(string); }
|
||||
void Manager::setLanguage(Language language) { meLanguage = language; }
|
||||
void Manager::setDestination(Destination destination) { meDestination = destination; }
|
||||
void Manager::limitStringLength(u32 length) { mpInputForm->limitStringLength(length); }
|
||||
void Manager::limitRowNum(u32 rows) { mpInputForm->limitRowNum(rows); }
|
||||
|
||||
void Manager::setAnimationOn(bool enabled) {
|
||||
static_cast<nw4rmanager::Layout&>(*mpPCKeyboard).setAnimOn(enabled);
|
||||
static_cast<nw4rmanager::Layout&>(*mpCellPhoneKeyboard).setAnimOn(enabled);
|
||||
static_cast<nw4rmanager::Layout&>(*mpInputForm).setAnimOn(enabled);
|
||||
static_cast<nw4rmanager::Layout&>(*mpCandidateBox).setAnimOn(enabled);
|
||||
static_cast<nw4rmanager::Layout&>(*mpToolBar).setAnimOn(enabled);
|
||||
static_cast<nw4rmanager::Layout&>(*mpPredictLanguageDialog).setAnimOn(enabled);
|
||||
static_cast<nw4rmanager::Layout&>(*mpSignWindow).setAnimOn(enabled);
|
||||
}
|
||||
void Manager::setAspectRatio(bool standard) {
|
||||
mbAspectRatio4x3 = standard;
|
||||
if (static_cast<u8>(standard) == true) setLayoutScaleFor4x3();
|
||||
else setLayoutScaleFor16x9();
|
||||
}
|
||||
void Manager::setTitleText(wchar_t* title) {
|
||||
nw4r::lyt::TextBox* text = nw4r::ut::DynamicCast<nw4r::lyt::TextBox*>(static_cast<nw4rmanager::Layout&>(*mpInputForm).getPane("T_title_text"));
|
||||
if (text != NULL) text->SetString(title, 0);
|
||||
}
|
||||
void Manager::setLayoutScaleFor16x9() {
|
||||
static_cast<nw4rmanager::Layout&>(*mpPCKeyboard).setRootPaneScaleFor16x9();
|
||||
static_cast<nw4rmanager::Layout&>(*mpCellPhoneKeyboard).setRootPaneScaleFor16x9();
|
||||
mpInputForm->setRootPaneScaleFor16x9();
|
||||
mpCandidateBox->setRootPaneScaleFor16x9();
|
||||
static_cast<nw4rmanager::Layout&>(*mpToolBar).setRootPaneScaleFor16x9();
|
||||
static_cast<nw4rmanager::Layout&>(*mpPredictLanguageDialog).setRootPaneScaleFor16x9();
|
||||
static_cast<nw4rmanager::Layout&>(*mpSignWindow).setRootPaneScaleFor16x9();
|
||||
}
|
||||
void Manager::setLayoutScaleFor4x3() {
|
||||
static_cast<nw4rmanager::Layout&>(*mpPCKeyboard).setRootPaneScaleFor4x3();
|
||||
static_cast<nw4rmanager::Layout&>(*mpCellPhoneKeyboard).setRootPaneScaleFor4x3();
|
||||
mpInputForm->setRootPaneScaleFor4x3();
|
||||
mpCandidateBox->setRootPaneScaleFor4x3();
|
||||
static_cast<nw4rmanager::Layout&>(*mpToolBar).setRootPaneScaleFor4x3();
|
||||
static_cast<nw4rmanager::Layout&>(*mpPredictLanguageDialog).setRootPaneScaleFor4x3();
|
||||
static_cast<nw4rmanager::Layout&>(*mpSignWindow).setRootPaneScaleFor4x3();
|
||||
}
|
||||
inputform::EditBuffer* Manager::createEditBuffer() { return new (MEMAllocFromAllocator(mpAllocator, sizeof(inputform::EditBuffer))) inputform::EditBuffer; }
|
||||
keyboard::hwkey::HWKeyboard* Manager::createHWKeyboard() { return new (MEMAllocFromAllocator(mpAllocator, sizeof(keyboard::hwkey::HWKeyboard))) keyboard::hwkey::HWKeyboard(this); }
|
||||
void* Manager::createPCTypeKeyboard() { return new (MEMAllocFromAllocator(mpAllocator, sizeof(keyboard::pctype::Sample))) keyboard::pctype::Sample(this, mpMultiArcResourceAccessor, mpEventObserver, "fs_VK_ascii_keytop_a.brlyt"); }
|
||||
void* Manager::createCellPhoneTypeKeyboard() { return new (MEMAllocFromAllocator(mpAllocator, sizeof(keyboard::cellphonetype::Sample))) keyboard::cellphonetype::Sample(this, mpMultiArcResourceAccessor, mpEventObserver, "fs_VK_cellPhone_a.brlyt"); }
|
||||
InputForm* Manager::createInputForm() { return new (MEMAllocFromAllocator(mpAllocator, sizeof(inputform::Sample))) inputform::Sample(this, mpMultiArcResourceAccessor, mpEventObserver, "fs_VK_textBox_a.brlyt"); }
|
||||
void* Manager::createCandidateBox() { return new (MEMAllocFromAllocator(mpAllocator, sizeof(candidatebox::Sample))) candidatebox::Sample(this, mpMultiArcResourceAccessor, mpEventObserver, "fs_VK_predictInput_a.brlyt"); }
|
||||
void* Manager::createToolBar() { return new (MEMAllocFromAllocator(mpAllocator, sizeof(toolbar::Sample))) toolbar::Sample(this, mpMultiArcResourceAccessor, mpEventObserver, "fs_VK_toolbar_a.brlyt"); }
|
||||
void* Manager::createPredictLanguageDialog() { return new (MEMAllocFromAllocator(mpAllocator, sizeof(predictlang::Sample))) predictlang::Sample(this, mpMultiArcResourceAccessor, mpEventObserver, "fs_prdicSelWidw_a.brlyt"); }
|
||||
predictlang::Base::~Base() {}
|
||||
void* Manager::createSignWindow() { return new (MEMAllocFromAllocator(mpAllocator, sizeof(keyboard::signwindow::Sample))) keyboard::signwindow::Sample(this, mpMultiArcResourceAccessor, mpEventObserver, "fs_signWindow_a.brlyt"); }
|
||||
void Manager::startPredictTurnOn(bool enabled) {
|
||||
if (getInputForm()->mbPredictOn != enabled) getCandidateBox()->startTurnOn(enabled);
|
||||
}
|
||||
bool Manager::isPredictTurning() const { return getCandidateBox()->getOnOffButton().IsTurning(); }
|
||||
void Manager::enableCompatibleFilter(bool enabled) { inputform::DeadKeyStream::sbCompatibleFilterEnabled = enabled; }
|
||||
void Manager::enableKSXFilter(bool enabled) {
|
||||
static_cast<tistring::Decolated*>(mpEditBuffer->mpString)->EnableKSXFilter(enabled);
|
||||
static_cast<tistring::Decolated*>(mpEditBuffer->mpZiString)->EnableKSXFilter(enabled);
|
||||
}
|
||||
bool Manager::isVacancy() const {
|
||||
if (!getInputForm() || !getToolBar()) return true;
|
||||
if (!getToolBar()->isQwerty() && getCellPhoneKeyboard()->isHoldingButton()) return false;
|
||||
return getInputForm()->inputform::Base::isVacancy();
|
||||
}
|
||||
void Manager::SetFont(nw4r::lyt::FontRefLink* link) {
|
||||
nw4r::ut::Font* font = link->GetFont();
|
||||
if (mpToolBar) static_cast<nw4rmanager::Layout&>(*mpToolBar).SetFontForce(font);
|
||||
if (mpPCKeyboard) static_cast<nw4rmanager::Layout&>(*mpPCKeyboard).SetFontForce(font);
|
||||
if (mpCandidateBox) static_cast<nw4rmanager::Layout&>(*mpCandidateBox).SetFontForce(font);
|
||||
if (mpSignWindow) static_cast<nw4rmanager::Layout&>(*mpSignWindow).SetFontForce(font);
|
||||
if (mpInputForm) mpInputForm->nw4r::ut::CharWriter::SetFont(*font);
|
||||
if (mpCellPhoneKeyboard) static_cast<nw4rmanager::Layout&>(*mpCellPhoneKeyboard).SetFontForce(font);
|
||||
}
|
||||
void Manager::setDefaultPredictionJP(int count, const char** predictions) {
|
||||
static_cast<tistring::WithAtok*>(getInputForm()->getAtokString())->setDefaultPrediction(count, predictions);
|
||||
}
|
||||
void predictlang::Base::init() {}
|
||||
void predictlang::Base::create(MEMAllocator* allocator) { mpAllocator = allocator; }
|
||||
keyboard::pctype::Sample::~Sample() {}
|
||||
keyboard::cellphonetype::Sample::~Sample() {}
|
||||
candidatebox::Sample::~Sample() {}
|
||||
inputform::Sample::~Sample() {}
|
||||
toolbar::Sample::~Sample() {}
|
||||
predictlang::Sample::~Sample() {}
|
||||
keyboard::signwindow::Sample::~Sample() {}
|
||||
}
|
||||
@@ -13,6 +13,12 @@
|
||||
namespace textinput {
|
||||
namespace keyboard {
|
||||
namespace pctype {
|
||||
struct SelectorPosition {
|
||||
f32 coordinates[3];
|
||||
};
|
||||
extern SelectorPosition chinesePosition;
|
||||
extern SelectorPosition koreanPosition;
|
||||
|
||||
static const wchar_t* PREDICT_CAPTIONS[] = {L"", L"", L"Eng", L"Fra", L"Esp", L"EN", L"DE", L"FR", L"ES", L"IT", L"NL", L"CN", L"KR"};
|
||||
|
||||
static const GridKey csGridKeyboard[] = {
|
||||
@@ -1534,8 +1540,8 @@ namespace textinput {
|
||||
u32 count;
|
||||
u32 type;
|
||||
};
|
||||
u32 flags = 0;
|
||||
mState.rejected = false;
|
||||
u32 flags = 0;
|
||||
if (mKeyState.abcFlags & 64)
|
||||
flags |= 2;
|
||||
if (mKeyState.abcFlags & 128)
|
||||
@@ -1557,7 +1563,7 @@ namespace textinput {
|
||||
if (code != util::KBD_ConvertSmall(code))
|
||||
conversions |= 128;
|
||||
if ((mKeyState.aiuFlags & ~15) != conversions) {
|
||||
mKeyState.aiuFlags = (mKeyState.aiuFlags & 15) | conversions;
|
||||
mKeyState.aiuFlags = (mKeyState.aiuFlags & 15) | (conversions & ~15);
|
||||
mKeyState.refresh_();
|
||||
}
|
||||
}
|
||||
@@ -1600,7 +1606,7 @@ namespace textinput {
|
||||
}
|
||||
|
||||
void Base::setTranslateMode(TranslateMode mode) {
|
||||
u32 keyMode;
|
||||
u32 keyMode = mode;
|
||||
switch (mode) {
|
||||
case TM_Direct:
|
||||
keyMode = 0;
|
||||
@@ -1612,7 +1618,7 @@ namespace textinput {
|
||||
keyMode = 2;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
break;
|
||||
}
|
||||
if (keyMode != (mKeyState.abcFlags & 15)) {
|
||||
if (getLanguage() == KR || getLanguage() == CN)
|
||||
@@ -1646,7 +1652,7 @@ namespace textinput {
|
||||
abcFlags &= ~15;
|
||||
refresh_();
|
||||
}
|
||||
if (static_cast<u32>(language - CN) <= 1 && (abcFlags & 15) == 2) {
|
||||
if (static_cast<u32>(language - CN) <= 1 && getABCMode() == 2) {
|
||||
if ((abcFlags & 15) != 1) {
|
||||
abcFlags = (abcFlags & ~15) | 1;
|
||||
refresh_();
|
||||
@@ -1711,14 +1717,19 @@ namespace textinput {
|
||||
util::replaceChar(name, sizeof(name), data->ascii[i].szPaneName, 0, 'T');
|
||||
nw4r::lyt::TextBox* text = nw4r::ut::DynamicCast<nw4r::lyt::TextBox*>(root->FindPaneByName(name, true));
|
||||
if (text != NULL) {
|
||||
wchar_t caption[2] = {getWCCode(i), 0};
|
||||
wchar_t caption[2];
|
||||
caption[0] = getWCCode(i);
|
||||
caption[1] = 0;
|
||||
if (language == KR && (abcFlags & 15) == 1) {
|
||||
if (owner->isCapsOn())
|
||||
caption[0] = util::reverseLetterCaseW(caption[0]);
|
||||
if (caption[0] >= L'a' && caption[0] <= L'z')
|
||||
caption[0] = KOREAN_LOWER[caption[0] - L'a'];
|
||||
else if (caption[0] >= L'A' && caption[0] <= L'Z')
|
||||
caption[0] = KOREAN_UPPER[caption[0] - L'A'];
|
||||
bool caps = owner->isCapsOn();
|
||||
u32 character = caption[0];
|
||||
if (caps)
|
||||
character = util::reverseLetterCaseW(character);
|
||||
if (character >= L'a' && character <= L'z')
|
||||
character = KOREAN_LOWER[static_cast<wchar_t>(character) - L'a'];
|
||||
else if (character >= L'A' && character <= L'Z')
|
||||
character = KOREAN_UPPER[static_cast<wchar_t>(character) - L'A'];
|
||||
caption[0] = character;
|
||||
}
|
||||
text->SetString(caption);
|
||||
}
|
||||
@@ -1728,7 +1739,9 @@ namespace textinput {
|
||||
util::replaceChar(name, sizeof(name), data->grid[i].paneName, 0, 'T');
|
||||
nw4r::lyt::TextBox* text = nw4r::ut::DynamicCast<nw4r::lyt::TextBox*>(root->FindPaneByName(name, true));
|
||||
if (text != NULL) {
|
||||
wchar_t caption[2] = {data->grid[i].codes[3 - ((aiuFlags & 15) == 0)], 0};
|
||||
wchar_t caption[2];
|
||||
caption[0] = data->grid[i].codes[(aiuFlags & 15) == 0 ? 2 : 3];
|
||||
caption[1] = 0;
|
||||
text->SetString(caption);
|
||||
}
|
||||
}
|
||||
@@ -1750,7 +1763,7 @@ namespace textinput {
|
||||
if (abcFlags & 128)
|
||||
modifiers |= 2;
|
||||
wchar_t code = data->ascii[index].wc[modifiers];
|
||||
if (inputType == 0 && (abcFlags & 15) == 0) {
|
||||
if (inputType == 0 && getABCMode() == 0) {
|
||||
if (code == 0x3001)
|
||||
code = L',';
|
||||
else if (code == 0x3002)
|
||||
@@ -1761,7 +1774,7 @@ namespace textinput {
|
||||
code = L'[';
|
||||
else if (code == 0x300d)
|
||||
code = L']';
|
||||
} else if (owner->getLanguage() == CN && (abcFlags & 15) == 1) {
|
||||
} else if (owner->getLanguage() == CN && getABCMode() == 1) {
|
||||
if (code == L'[')
|
||||
code = 0x300a;
|
||||
else if (code == L']')
|
||||
@@ -1800,7 +1813,7 @@ namespace textinput {
|
||||
}
|
||||
for (u16 i = 0; i < 56; i++) {
|
||||
if (util::strcmp(data->grid[i].paneName, paneName))
|
||||
code = data->grid[i].codes[3 - ((aiuFlags & 15) == 0)];
|
||||
code = data->grid[i].codes[(aiuFlags & 15) == 0 ? 2 : 3];
|
||||
}
|
||||
return code;
|
||||
}
|
||||
@@ -1855,6 +1868,14 @@ namespace textinput {
|
||||
EventHandler::~EventHandler() {
|
||||
}
|
||||
|
||||
inline void UIModifierButton::Create(nw4rmanager::Layout* layout, const char* pane, const char* bounding) {
|
||||
gui::PaneManager* manager = layout->getPaneManager();
|
||||
mpPaneComponent = manager->searchPaneComponent(pane);
|
||||
mpBoundingComponent = manager->searchPaneComponent(bounding);
|
||||
mpAnimation = static_cast<AnmPane*>(layout->searchAnmPane(pane));
|
||||
mpBoundingComponent->setListener(this);
|
||||
}
|
||||
|
||||
void LayoutByNW4R::create(MEMAllocator* allocator) {
|
||||
Base::create(allocator);
|
||||
void* storage = MEMAllocFromAllocator(allocator, sizeof(EventHandler));
|
||||
@@ -1863,22 +1884,9 @@ namespace textinput {
|
||||
mpPaneManager->setAllComponentTriggerTarget(false);
|
||||
mpPaneManager->setAllBoundingBoxComponentTriggerTarget(true);
|
||||
createAnmPane_(allocator);
|
||||
nw4rmanager::Layout* layout = this;
|
||||
gui::PaneManager* manager = layout->getPaneManager();
|
||||
const char* shiftBounding = "B_key_SHIFT";
|
||||
const char* shiftPane = "P_key_SHIFT";
|
||||
mShiftButton.mpPaneComponent = manager->searchPaneComponent(shiftPane);
|
||||
mShiftButton.mpBoundingComponent = manager->searchPaneComponent(shiftBounding);
|
||||
mShiftButton.mpAnimation = static_cast<AnmPane*>(layout->searchAnmPane(shiftPane));
|
||||
mShiftButton.mpBoundingComponent->setListener(&mShiftButton);
|
||||
manager = layout->getPaneManager();
|
||||
const char* capsBounding = "B_key_CAPS";
|
||||
const char* capsPane = "P_key_CAPS";
|
||||
mCapsButton.mpPaneComponent = manager->searchPaneComponent(capsPane);
|
||||
mCapsButton.mpBoundingComponent = manager->searchPaneComponent(capsBounding);
|
||||
mCapsButton.mpAnimation = static_cast<AnmPane*>(layout->searchAnmPane(capsPane));
|
||||
mCapsButton.mpBoundingComponent->setListener(&mCapsButton);
|
||||
mModePanel.Create(layout);
|
||||
mShiftButton.Create(this, "P_key_SHIFT", "B_key_SHIFT");
|
||||
mCapsButton.Create(this, "P_key_CAPS", "B_key_CAPS");
|
||||
mModePanel.Create(this);
|
||||
mShiftButton.mpBoundingComponent->setTriggerTarget(true);
|
||||
mCapsButton.mpBoundingComponent->setTriggerTarget(true);
|
||||
for (u32 i = 0; i < 5; i++)
|
||||
@@ -1889,6 +1897,7 @@ namespace textinput {
|
||||
}
|
||||
|
||||
void LayoutByNW4R::createAnmPane_(MEMAllocator* allocator) {
|
||||
const char* shared;
|
||||
for (u16 i = 0; i < 129; i++) {
|
||||
const PaneAnimation& entry = csPaneToAnimation[i];
|
||||
AnmPane* pane = NULL;
|
||||
@@ -1915,7 +1924,7 @@ namespace textinput {
|
||||
}
|
||||
}
|
||||
nw4r::ut::List_Append(&mAnmPanes, pane);
|
||||
const char* shared = entry.sharedPane;
|
||||
shared = entry.sharedPane;
|
||||
for (u16 j = 0; j < entry.count; j++) {
|
||||
void* resource = mpMultiArcResourceAccessor->GetResource(0, entry.animations[j]->fileName);
|
||||
AnimTransformPane* transform =
|
||||
@@ -1936,16 +1945,26 @@ namespace textinput {
|
||||
setLineFeedButton(true);
|
||||
setPredictLanguageButton(true);
|
||||
setSignWindowButton(true);
|
||||
const nw4r::math::VEC3 chinesePosition(-219.0f, -130.0f, 0.0f);
|
||||
const nw4r::math::VEC3 koreanPosition(-209.0f, -90.0f, 0.0f);
|
||||
nw4r::math::VEC3 koreanVector;
|
||||
nw4r::math::VEC3 chineseVector;
|
||||
SelectorPosition koreanTranslation;
|
||||
SelectorPosition chineseTranslation;
|
||||
chineseTranslation = chinesePosition;
|
||||
koreanTranslation = koreanPosition;
|
||||
if (meLanguage == CN) {
|
||||
mModePanel.mpEnglishText->GetMaterial()->SetTexture(0, mModePanel.mDirectTexture);
|
||||
mModePanel.mpHangulText->GetMaterial()->SetTexture(0, mModePanel.mPinyinTexture);
|
||||
mModePanel.mpModeSelect->SetTranslate(chinesePosition);
|
||||
chineseVector.x = chineseTranslation.coordinates[0];
|
||||
chineseVector.y = chineseTranslation.coordinates[1];
|
||||
chineseVector.z = chineseTranslation.coordinates[2];
|
||||
mModePanel.mpModeSelect->SetTranslate(chineseVector);
|
||||
} else if (meLanguage == KR) {
|
||||
mModePanel.mpEnglishText->GetMaterial()->SetTexture(0, mModePanel.mEnglishTexture);
|
||||
mModePanel.mpHangulText->GetMaterial()->SetTexture(0, mModePanel.mHangulTexture);
|
||||
mModePanel.mpModeSelect->SetTranslate(koreanPosition);
|
||||
koreanVector.x = koreanTranslation.coordinates[0];
|
||||
koreanVector.y = koreanTranslation.coordinates[1];
|
||||
koreanVector.z = koreanTranslation.coordinates[2];
|
||||
mModePanel.mpModeSelect->SetTranslate(koreanVector);
|
||||
}
|
||||
searchAnmPane("P_key_SHIFT")->changeAnimation(0);
|
||||
searchAnmPane("P_key_CAPS")->changeAnimation(0);
|
||||
@@ -2020,12 +2039,17 @@ namespace textinput {
|
||||
}
|
||||
}
|
||||
if (getLanguage() == KR || getLanguage() == CN) {
|
||||
if ((mKeyState.abcFlags & 15) == 0) {
|
||||
searchAnmPane("P_Mode_kr_eng")->changeAnimation(5);
|
||||
searchAnmPane("P_Mode_kr_han")->changeAnimation(0);
|
||||
} else {
|
||||
searchAnmPane("P_Mode_kr_eng")->changeAnimation(0);
|
||||
searchAnmPane("P_Mode_kr_han")->changeAnimation(5);
|
||||
switch (mKeyState.abcFlags & 15) {
|
||||
case 0: {
|
||||
searchAnmPane("P_Mode_kr_eng")->changeAnimation(5);
|
||||
searchAnmPane("P_Mode_kr_han")->changeAnimation(0);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
searchAnmPane("P_Mode_kr_eng")->changeAnimation(0);
|
||||
searchAnmPane("P_Mode_kr_han")->changeAnimation(5);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
mpLayout->Animate(0);
|
||||
@@ -2071,24 +2095,31 @@ namespace textinput {
|
||||
gather.changeCapsLock(caps);
|
||||
mKeyState.abcFlags = ((mKeyState.abcFlags ^ 64) & 64) | (mKeyState.abcFlags & ~64);
|
||||
mKeyState.refresh_();
|
||||
mCapsButton.mbOn = (mKeyState.abcFlags >> 6) & 1;
|
||||
if (mCapsButton.mbOn)
|
||||
mCapsButton.mpAnimation->onAnmEvent(static_cast<AnmPane::AnmPaneEvent>(10));
|
||||
else
|
||||
mCapsButton.mpAnimation->onAnmEvent(static_cast<AnmPane::AnmPaneEvent>(11));
|
||||
mCapsButton.SetState((mKeyState.abcFlags >> 6) & 1, 11);
|
||||
mpEventObserver->onSE(static_cast<sound::SE>(13));
|
||||
}
|
||||
|
||||
inline void UIModifierButton::SetState(bool enabled, u32 inactiveAnimation) {
|
||||
mbOn = enabled;
|
||||
if (mbOn)
|
||||
mpAnimation->onAnmEvent(static_cast<AnmPane::AnmPaneEvent>(10));
|
||||
else
|
||||
mpAnimation->onAnmEvent(static_cast<AnmPane::AnmPaneEvent>(inactiveAnimation));
|
||||
}
|
||||
|
||||
void LayoutByNW4R::onPressedShift(bool sound) {
|
||||
mKeyState.setABCFlag((mKeyState.abcFlags & ~15) | 128);
|
||||
mShiftButton.mbOn = true;
|
||||
mShiftButton.mpAnimation->onAnmEvent(static_cast<AnmPane::AnmPaneEvent>(10));
|
||||
u32 flags = mKeyState.getABCFlag();
|
||||
flags |= 128;
|
||||
mKeyState.setABCFlag(flags);
|
||||
mShiftButton.SetState(true, 5);
|
||||
if (sound)
|
||||
mpEventObserver->onSE(static_cast<sound::SE>(13));
|
||||
}
|
||||
|
||||
void LayoutByNW4R::onReleasedShift() {
|
||||
mKeyState.setABCFlag(mKeyState.abcFlags & ~143);
|
||||
u32 flags = mKeyState.getABCFlag();
|
||||
flags &= ~128;
|
||||
mKeyState.setABCFlag(flags);
|
||||
if (mShiftButton.mbOn) {
|
||||
mShiftButton.mbOn = false;
|
||||
mShiftButton.mpAnimation->onAnmEvent(static_cast<AnmPane::AnmPaneEvent>(5));
|
||||
@@ -2099,13 +2130,33 @@ namespace textinput {
|
||||
getWCCode(static_cast<char*>(data));
|
||||
if (event == 4 && getWCCode(static_cast<char*>(data)) == 0) {
|
||||
switch (getControlKey(static_cast<char*>(data))) {
|
||||
case 0:
|
||||
mpEventObserver->onSE(static_cast<sound::SE>(9));
|
||||
case 3: {
|
||||
LayoutGather& gather = LayoutGather::Singleton::getInstance();
|
||||
if (!gather.isHoldingShift()) {
|
||||
if (mKeyState.abcFlags & ~15) {
|
||||
mKeyState.abcFlags &= ~128;
|
||||
mKeyState.refresh_();
|
||||
}
|
||||
if (mShiftButton.mbOn) {
|
||||
mShiftButton.mbOn = false;
|
||||
mShiftButton.mpAnimation->onAnmEvent(static_cast<AnmPane::AnmPaneEvent>(5));
|
||||
}
|
||||
}
|
||||
u8 caps = !gather.isCapsLock();
|
||||
gather.changeCapsLock(caps);
|
||||
mKeyState.abcFlags = ((mKeyState.abcFlags ^ 64) & 64) | (mKeyState.abcFlags & ~64);
|
||||
mKeyState.refresh_();
|
||||
mCapsButton.mbOn = (mKeyState.abcFlags >> 6) & 1;
|
||||
if (mCapsButton.mbOn)
|
||||
mCapsButton.mpAnimation->onAnmEvent(static_cast<AnmPane::AnmPaneEvent>(10));
|
||||
else
|
||||
mCapsButton.mpAnimation->onAnmEvent(static_cast<AnmPane::AnmPaneEvent>(11));
|
||||
mpEventObserver->onSE(static_cast<sound::SE>(13));
|
||||
|
||||
break;
|
||||
case 3:
|
||||
onPressedCaps();
|
||||
break;
|
||||
case 4:
|
||||
}
|
||||
case 4: {
|
||||
LayoutGather& shiftGather = LayoutGather::Singleton::getInstance();
|
||||
if (mKeyState.abcFlags & ~15) {
|
||||
mKeyState.abcFlags &= ~64;
|
||||
mKeyState.refresh_();
|
||||
@@ -2114,17 +2165,21 @@ namespace textinput {
|
||||
mCapsButton.mbOn = false;
|
||||
mCapsButton.mpAnimation->onAnmEvent(static_cast<AnmPane::AnmPaneEvent>(5));
|
||||
}
|
||||
if (!LayoutGather::Singleton::getInstance().isHoldingShift()) {
|
||||
if (!shiftGather.isHoldingShift()) {
|
||||
mKeyState.abcFlags = ((mKeyState.abcFlags ^ 128) & 128) | (mKeyState.abcFlags & ~128);
|
||||
mKeyState.refresh_();
|
||||
}
|
||||
mShiftButton.mbOn = (mKeyState.abcFlags >> 7) & 1;
|
||||
if (!mShiftButton.mbOn)
|
||||
mShiftButton.mpAnimation->onAnmEvent(static_cast<AnmPane::AnmPaneEvent>(11));
|
||||
else
|
||||
if (mShiftButton.mbOn)
|
||||
mShiftButton.mpAnimation->onAnmEvent(static_cast<AnmPane::AnmPaneEvent>(10));
|
||||
else
|
||||
mShiftButton.mpAnimation->onAnmEvent(static_cast<AnmPane::AnmPaneEvent>(11));
|
||||
mpEventObserver->onSE(static_cast<sound::SE>(13));
|
||||
break;
|
||||
}
|
||||
case 0:
|
||||
mpEventObserver->onSE(static_cast<sound::SE>(9));
|
||||
break;
|
||||
case 11:
|
||||
if (!isABC()) {
|
||||
mpEventObserver->onSE(static_cast<sound::SE>(13));
|
||||
@@ -2137,6 +2192,18 @@ namespace textinput {
|
||||
searchAnmPane("W_JP_Chng_ABC")->changeAnimation(6);
|
||||
}
|
||||
break;
|
||||
case 18:
|
||||
if ((mKeyState.aiuFlags & 15) == 1) {
|
||||
mpEventObserver->onSE(static_cast<sound::SE>(13));
|
||||
searchAnmPane("P_katakana")->changeAnimation(6);
|
||||
}
|
||||
break;
|
||||
case 19:
|
||||
if ((mKeyState.aiuFlags & 15) == 0) {
|
||||
mpEventObserver->onSE(static_cast<sound::SE>(13));
|
||||
searchAnmPane("P_hiragana")->changeAnimation(6);
|
||||
}
|
||||
break;
|
||||
case 15:
|
||||
if ((mKeyState.abcFlags & 15) == 2)
|
||||
searchAnmPane("P_Mode_roma_kata")->changeAnimation(6);
|
||||
@@ -2159,18 +2226,6 @@ namespace textinput {
|
||||
if ((mKeyState.abcFlags & 15) == 1)
|
||||
searchAnmPane("P_Mode_roma_hira")->changeAnimation(6);
|
||||
break;
|
||||
case 18:
|
||||
if ((mKeyState.aiuFlags & 15) == 1) {
|
||||
mpEventObserver->onSE(static_cast<sound::SE>(13));
|
||||
searchAnmPane("P_katakana")->changeAnimation(6);
|
||||
}
|
||||
break;
|
||||
case 19:
|
||||
if ((mKeyState.aiuFlags & 15) == 0) {
|
||||
mpEventObserver->onSE(static_cast<sound::SE>(13));
|
||||
searchAnmPane("P_hiragana")->changeAnimation(6);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
Base::onKey(event, data);
|
||||
@@ -2303,10 +2358,12 @@ namespace textinput {
|
||||
}
|
||||
|
||||
void LayoutByNW4R::sendInputWChar(wchar_t code, bool repeat) {
|
||||
bool shift = (mKeyState.abcFlags & 128) != 0;
|
||||
bool shift = false;
|
||||
nw4r::lyt::Pane* last = NULL;
|
||||
if (shift)
|
||||
if (mKeyState.abcFlags & 128) {
|
||||
last = mAnmPaneFifo.getLast();
|
||||
shift = true;
|
||||
}
|
||||
Base::sendInputWChar(code, repeat);
|
||||
if (shift && last != NULL)
|
||||
setPaneLastDrawReceived(last);
|
||||
@@ -2390,13 +2447,15 @@ namespace textinput {
|
||||
mKeyState.setABCMode(abcMode);
|
||||
mKeyState.setAIUMode(aiuMode);
|
||||
switch (static_cast<int>(abcMode)) {
|
||||
case 1:
|
||||
case 2:
|
||||
mpInitialLanguageData = &csJapanKanaInput;
|
||||
break;
|
||||
case 0:
|
||||
mpInitialLanguageData = &csLanguageDependencyData[getLanguage()];
|
||||
break;
|
||||
case 1:
|
||||
mpInitialLanguageData = &csJapanKanaInput;
|
||||
break;
|
||||
case 2:
|
||||
mpInitialLanguageData = &csJapanKanaInput;
|
||||
break;
|
||||
}
|
||||
initLayout();
|
||||
sendCommand(41, NULL);
|
||||
@@ -2462,25 +2521,33 @@ namespace textinput {
|
||||
nw4rmanager::AnmPane* animation = NULL;
|
||||
u8 key = keys.GetKey();
|
||||
wchar_t code = keys.GetWChar();
|
||||
if (key != 0x2c) {
|
||||
if (key == 0x28 || key == 0x58) {
|
||||
switch (static_cast<int>(key)) {
|
||||
case 0x2c:
|
||||
break;
|
||||
case 0x28:
|
||||
case 0x58:
|
||||
if (!(hkb.GetModifierState() & 4))
|
||||
animation = searchAnmPane("P_key_LF");
|
||||
} else {
|
||||
break;
|
||||
default: {
|
||||
code = inputform::DeadKeyStream::ToIndependentClass(code);
|
||||
code = static_cast<const Manager*>(mpManager)->getHWKeyboard()->convertWCCode(code);
|
||||
if (static_cast<const Manager*>(mpManager)->getToolBar()->isQwerty()) {
|
||||
if (static_cast<const Manager*>(mpManager)->getPCKeyboard()->getTranslateMode() != TM_Direct &&
|
||||
mpManager->getLanguage() == KR) {
|
||||
if (isCapsOn())
|
||||
code = util::reverseLetterCaseW(code);
|
||||
if (code >= L'a' && code <= L'z')
|
||||
code = KOREAN_LOWER[code - L'a'];
|
||||
else if (code >= L'A' && code <= L'Z')
|
||||
code = KOREAN_UPPER[code - L'A'];
|
||||
bool caps = isCapsOn();
|
||||
u32 koreanCode = code;
|
||||
if (caps)
|
||||
koreanCode = util::reverseLetterCaseW(koreanCode);
|
||||
if (koreanCode >= L'a' && koreanCode <= L'z')
|
||||
koreanCode = KOREAN_LOWER[static_cast<u16>(koreanCode) - L'a'];
|
||||
else if (koreanCode >= L'A' && koreanCode <= L'Z')
|
||||
koreanCode = KOREAN_UPPER[static_cast<u16>(koreanCode) - L'A'];
|
||||
code = koreanCode;
|
||||
}
|
||||
}
|
||||
animation = searchAnmPane(code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (animation != NULL)
|
||||
@@ -2492,14 +2559,18 @@ namespace textinput {
|
||||
nw4rmanager::AnmPane* animation = NULL;
|
||||
u8 key = keys.GetKey();
|
||||
keys.GetWChar();
|
||||
if (key < 0x2c) {
|
||||
if (key == 0x2a && !(hkb.GetModifierState() & 4))
|
||||
switch (static_cast<int>(key)) {
|
||||
case 0x2a:
|
||||
if (hkb.GetModifierState() & 4)
|
||||
break;
|
||||
case 0x4c:
|
||||
animation = searchAnmPane("P_key_DELETE");
|
||||
} else if (key == 0x2c) {
|
||||
if (!(hkb.GetModifierState() & 8))
|
||||
animation = searchAnmPane("P_key_SPACE");
|
||||
} else if (key == 0x4c)
|
||||
animation = searchAnmPane("P_key_DELETE");
|
||||
break;
|
||||
case 0x2c:
|
||||
if (!(hkb.GetModifierState() & 8))
|
||||
animation = searchAnmPane("P_key_SPACE");
|
||||
break;
|
||||
}
|
||||
if (animation != NULL)
|
||||
animation->onAnmEvent(nw4rmanager::AnmPane::PE_0);
|
||||
keys = keys.GetNext();
|
||||
@@ -2559,8 +2630,7 @@ namespace textinput {
|
||||
mCapsButton.mbOn = false;
|
||||
mCapsButton.mpAnimation->onAnmEvent(static_cast<AnmPane::AnmPaneEvent>(5));
|
||||
}
|
||||
const u8 caps = 0;
|
||||
LayoutGather::Singleton::getInstance().changeCapsLock(caps);
|
||||
LayoutGather::Singleton::getInstance().changeCapsLock(0);
|
||||
}
|
||||
if (visible)
|
||||
initPaneLastDrawReceived();
|
||||
@@ -2578,44 +2648,52 @@ namespace textinput {
|
||||
void EventHandler::onTiEvent(gui::PaneComponent* component, u32 event, Input* input) {
|
||||
nw4r::lyt::Pane* pane = component->getPane();
|
||||
const char* name = pane->GetName();
|
||||
if (!util::strcmp("B_key_SHIFT", name) && !util::strcmp("B_key_CAPS", name) && name[0] == 'B') {
|
||||
char animationName[17];
|
||||
util::replaceChar(animationName, sizeof(animationName), name, 0, 'P');
|
||||
if (strncmp(name + 5, "Chng", 4) == 0 || strncmp(name + 7, "Chng", 4) == 0 || strncmp(name + 7, "prdc", 4) == 0) {
|
||||
util::replaceChar(animationName, sizeof(animationName), name, 0, 'W');
|
||||
}
|
||||
nw4rmanager::AnmPane* animation = mpKeyboard->searchAnmPane(animationName);
|
||||
switch (static_cast<int>(event)) {
|
||||
case 1:
|
||||
if (animation != NULL)
|
||||
animation->onAnmEvent(nw4rmanager::AnmPane::PE_2);
|
||||
mpKeyboard->onKey(1, animationName);
|
||||
break;
|
||||
if (!util::strcmp("B_key_SHIFT", name)) {
|
||||
switch (util::strcmp("B_key_CAPS", name)) {
|
||||
case 0:
|
||||
if (animation != NULL) {
|
||||
mpEventObserver->onSE(static_cast<sound::SE>(4));
|
||||
mpKeyboard->setPaneLastDrawReceived(animation->getPane());
|
||||
animation->onAnmEvent(nw4rmanager::AnmPane::PE_1);
|
||||
if (name[0] == 'B') {
|
||||
char animationName[17];
|
||||
util::replaceChar(animationName, sizeof(animationName), name, 0, 'P');
|
||||
if (strncmp(name + 5, "Chng", 4) == 0 || strncmp(name + 7, "Chng", 4) == 0 || strncmp(name + 7, "prdc", 4) == 0) {
|
||||
util::replaceChar(animationName, sizeof(animationName), name, 0, 'W');
|
||||
}
|
||||
nw4rmanager::AnmPane* animation = mpKeyboard->searchAnmPane(animationName);
|
||||
switch (static_cast<int>(event)) {
|
||||
case 4:
|
||||
if (input->field_0x0C & 0x800) {
|
||||
if (animation != NULL)
|
||||
animation->onAnmEvent(nw4rmanager::AnmPane::PE_0);
|
||||
mpKeyboard->onKey(4, animationName);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (animation != NULL)
|
||||
animation->onAnmEvent(nw4rmanager::AnmPane::PE_2);
|
||||
mpKeyboard->onKey(1, animationName);
|
||||
break;
|
||||
case 0:
|
||||
if (animation != NULL) {
|
||||
mpEventObserver->onSE(static_cast<sound::SE>(4));
|
||||
mpKeyboard->setPaneLastDrawReceived(animation->getPane());
|
||||
animation->onAnmEvent(nw4rmanager::AnmPane::PE_1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (event == 2 && (input->field_0x10 & 0x800) && !(input->field_0x0C & 0x800) &&
|
||||
(util::strcmp("P_key_DELETE", animationName) || util::strcmp("P_Gkey_DELETE", animationName) ||
|
||||
util::strcmp("P_key_SPACE", animationName) || util::strcmp("P_Gkey_SPACE", animationName)) &&
|
||||
component->isDragging(input->field_0x00)) {
|
||||
u32 frames = mpKeyboard->getFlightDuration(input->field_0x00, name);
|
||||
if (frames >= 30 && frames % 9 == 0) {
|
||||
animation->onAnmEvent(nw4rmanager::AnmPane::PE_0);
|
||||
mpKeyboard->onKey(4, animationName);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (input->field_0x0C & 0x800) {
|
||||
if (animation != NULL)
|
||||
animation->onAnmEvent(nw4rmanager::AnmPane::PE_0);
|
||||
mpKeyboard->onKey(4, animationName);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (event == 2 && (input->field_0x10 & 0x800) && !(input->field_0x0C & 0x800) &&
|
||||
(util::strcmp("P_key_DELETE", animationName) || util::strcmp("P_Gkey_DELETE", animationName) ||
|
||||
util::strcmp("P_key_SPACE", animationName) || util::strcmp("P_Gkey_SPACE", animationName)) &&
|
||||
component->isDragging(input->field_0x00)) {
|
||||
u32 frames = mpKeyboard->getFlightDuration(input->field_0x00, name);
|
||||
if (frames > 29 && frames % 9 == 0) {
|
||||
animation->onAnmEvent(nw4rmanager::AnmPane::PE_0);
|
||||
mpKeyboard->onKey(4, animationName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3084,6 +3162,9 @@ namespace textinput {
|
||||
void Base::setInputModeJP(bool, u32, u32) {
|
||||
}
|
||||
|
||||
SelectorPosition chinesePosition = {{-219.0f, -130.0f, 0.0f}};
|
||||
SelectorPosition koreanPosition = {{-209.0f, -90.0f, 0.0f}};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
678
src/keyboard/tiSignWindow.cpp
Normal file
678
src/keyboard/tiSignWindow.cpp
Normal file
@@ -0,0 +1,678 @@
|
||||
#define TISIGNWINDOW_IMPLEMENTATION
|
||||
#include "keyboard/tiSignWindow.h"
|
||||
#include "keyboard/tiManager.h"
|
||||
#include "keyboard/tiLanguageIndependentData.h"
|
||||
#include "keyboard/tiUtil.h"
|
||||
|
||||
#include <new>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
|
||||
|
||||
|
||||
namespace textinput {
|
||||
namespace keyboard {
|
||||
|
||||
namespace signwindow {
|
||||
|
||||
struct AnimationFile {
|
||||
u32 id;
|
||||
char name[64];
|
||||
};
|
||||
|
||||
struct PaneAnimation {
|
||||
s32 type;
|
||||
char paneName[20];
|
||||
u32 animationCount;
|
||||
const char* forceName;
|
||||
const AnimationFile* animations[8];
|
||||
};
|
||||
|
||||
struct PaneControlKey {
|
||||
char paneName[20];
|
||||
u32 key;
|
||||
};
|
||||
|
||||
const char* csSgnKeys[20] = {
|
||||
"P_SGNkey_00", "P_SGNkey_01", "P_SGNkey_02", "P_SGNkey_03", "P_SGNkey_04",
|
||||
"P_SGNkey_05", "P_SGNkey_06", "P_SGNkey_07", "P_SGNkey_08", "P_SGNkey_09",
|
||||
"P_SGNkey_10", "P_SGNkey_11", "P_SGNkey_12", "P_SGNkey_13", "P_SGNkey_14",
|
||||
"P_SGNkey_15", "P_SGNkey_16", "P_SGNkey_17", "P_SGNkey_18", "P_SGNkey_19",
|
||||
};
|
||||
|
||||
static const char* csSgnKeyBase = "P_SGNkey_00";
|
||||
static const char* csSgnKeyClose = "P_SGNkey_close";
|
||||
|
||||
const AnimationFile csAninationFileForSign[9] = {
|
||||
{0, "fs_signWindow_a_SGN_normal.brlan"},
|
||||
{1, "fs_signWindow_a_SGN_FADE-IN.brlan"},
|
||||
{8, "fs_signWindow_a_Scroll_FADE-OUT.brlan"},
|
||||
{2, "fs_signWindow_a_SGN_Focus-IN.brlan"},
|
||||
{6, "fs_signWindow_a_SGN_Focus-OUT.brlan"},
|
||||
{3, "fs_signWindow_a_SGN_Roll_over.brlan"},
|
||||
{4, "fs_signWindow_a_SGN_Pushed.brlan"},
|
||||
{7, "fs_signWindow_a_SGN_scroll_next.brlan"},
|
||||
{5, "fs_signWindow_a_SGN_scroll_prev.brlan"},
|
||||
};
|
||||
|
||||
static const PaneControlKey csPaneNameToControlKey[3] = {
|
||||
{"B_SGNkey_close", 0x18},
|
||||
{"B_SGNkey_prev", 0x1A},
|
||||
{"B_SGNkey_next", 0x19},
|
||||
};
|
||||
|
||||
static const LanguageDependency csLanguageDependencyData[10] = {
|
||||
{4, csSignKeyJP}, {10, csSignKeyUS}, {10, csSignKeyUK}, {10, csSignKeyFR}, {10, csSignKeyDE},
|
||||
{10, csSignKeyIT}, {10, csSignKeySP}, {10, csSignKeyNL}, {4, csSignKeyCN}, {4, csSignKeyKR},
|
||||
};
|
||||
|
||||
struct InputCharacter {
|
||||
wchar_t character;
|
||||
u16 type;
|
||||
bool repeat;
|
||||
u32 value;
|
||||
};
|
||||
static const InputCharacter inputCharacterTemplate = {0, 3, false, 0};
|
||||
|
||||
static PaneAnimation csPaneToAnimationInSign[25] = {
|
||||
{0, "N_SGNkeytop_all", 3, 0, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2]}},
|
||||
{1, "N_SGNkeyall", 3, 0, {&csAninationFileForSign[0], &csAninationFileForSign[7], &csAninationFileForSign[8]}},
|
||||
{2, "P_SGNkey_00", 7, 0, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_01", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_02", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_03", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_04", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_05", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_06", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_07", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_08", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_09", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_10", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_11", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_12", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_13", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_14", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_15", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_16", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_17", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_18", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_19", 7, csSgnKeyBase, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_prev", 7, csSgnKeyClose, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_next", 7, csSgnKeyClose, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
{2, "P_SGNkey_close", 7, 0, {&csAninationFileForSign[0], &csAninationFileForSign[1], &csAninationFileForSign[2], &csAninationFileForSign[3], &csAninationFileForSign[4], &csAninationFileForSign[5], &csAninationFileForSign[6]}},
|
||||
};
|
||||
|
||||
static inline s32 findControlKey(const char* paneName) {
|
||||
u32 index = 0;
|
||||
do {
|
||||
if (util::strcmp(csPaneNameToControlKey[index & 0xFFFF].paneName, paneName))
|
||||
return csPaneNameToControlKey[index & 0xFFFF].key;
|
||||
++index;
|
||||
} while (index < 3);
|
||||
return 0x1B;
|
||||
}
|
||||
|
||||
static inline wchar_t findSignCharacter(const PaneNameToCharCodeInSignMode* keys, u16 page, const char* paneName) {
|
||||
u32 index = 0;
|
||||
do {
|
||||
if (util::strcmp(keys[index & 0xFFFF].szPaneName, paneName))
|
||||
return keys[index & 0xFFFF].wc[page];
|
||||
++index;
|
||||
} while (index < 20);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Base::create(MEMAllocator*) {
|
||||
muPage = 0;
|
||||
mbLocked = 0;
|
||||
mbRepeat = 0;
|
||||
mpLanguageDependency = &csLanguageDependencyData[getLanguage()];
|
||||
}
|
||||
|
||||
void Base::init() {
|
||||
muPage = 0;
|
||||
mbLocked = 0;
|
||||
mbRepeat = 0;
|
||||
mpLanguageDependency = &csLanguageDependencyData[getLanguage()];
|
||||
}
|
||||
|
||||
void Base::onKey(u32 command, void* data) {
|
||||
s32 key;
|
||||
if (command != 4) {
|
||||
return;
|
||||
}
|
||||
|
||||
key = findControlKey(static_cast<const char*>(data));
|
||||
|
||||
if (key != 0x1B) {
|
||||
switch (key) {
|
||||
case 0x18:
|
||||
close();
|
||||
break;
|
||||
case 0x1A:
|
||||
movePrevSignPage();
|
||||
break;
|
||||
case 0x19:
|
||||
moveNextSignPage();
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
u16 code = findSignCharacter(mpLanguageDependency->keys, muPage, static_cast<const char*>(data));
|
||||
|
||||
if (code != 0) {
|
||||
InputCharacter input = inputCharacterTemplate;
|
||||
input.character = code;
|
||||
input.repeat = mbRepeat;
|
||||
if (mpManager->getInputForm()->isAtokActive()) {
|
||||
input.repeat = true;
|
||||
}
|
||||
if (meLanguage - 8U <= 1U) {
|
||||
input.repeat = 1;
|
||||
}
|
||||
sendCommand(5, &input);
|
||||
}
|
||||
}
|
||||
|
||||
void Base::close() {}
|
||||
|
||||
void Base::movePrevSignPage() {
|
||||
if (muPage == 0) {
|
||||
muPage = mpLanguageDependency->count - 1;
|
||||
return;
|
||||
}
|
||||
muPage = muPage - 1;
|
||||
return;
|
||||
}
|
||||
|
||||
void Base::moveNextSignPage() {
|
||||
u8 page = muPage + 1;
|
||||
muPage = page;
|
||||
if (page < mpLanguageDependency->count) {
|
||||
return;
|
||||
}
|
||||
muPage = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
LayoutByNW4R::~LayoutByNW4R() {
|
||||
mpEventHandler->~EventHandler();
|
||||
MEMFreeToAllocator(mpAllocator, mpEventHandler);
|
||||
AnmPane* pane = static_cast<AnmPane*>(nw4r::ut::List_GetNext(&mAnmPanes, NULL));
|
||||
while (pane != NULL) {
|
||||
nw4r::ut::List_Remove(&mAnmPanes, pane);
|
||||
pane->destroy(mpAllocator);
|
||||
pane = static_cast<AnmPane*>(nw4r::ut::List_GetNext(&mAnmPanes, NULL));
|
||||
}
|
||||
}
|
||||
|
||||
Base::~Base() {}
|
||||
|
||||
EventHandler::~EventHandler() {}
|
||||
|
||||
void LayoutByNW4R::create(MEMAllocator* allocator) {
|
||||
mpAllocator = allocator;
|
||||
Base::create(allocator);
|
||||
void* eventBuffer = MEMAllocFromAllocator(allocator, sizeof(EventHandler));
|
||||
mpEventHandler = new (eventBuffer) EventHandler(this);
|
||||
Layout::createWithEventHandler(allocator, mpEventHandler);
|
||||
mpPaneManager->setAllComponentTriggerTarget(false);
|
||||
mpPaneManager->setAllBoundingBoxComponentTriggerTarget(true);
|
||||
|
||||
const char* forceName;
|
||||
u32 animationCount;
|
||||
u32 paneIndex = 0;
|
||||
do {
|
||||
AnmPane* pane = NULL;
|
||||
const PaneAnimation& paneInfo = csPaneToAnimationInSign[paneIndex & 0xFFFF];
|
||||
switch (paneInfo.type) {
|
||||
case 2: {
|
||||
void* paneBuffer = MEMAllocFromAllocator(allocator, sizeof(CellPhoneSignButtonPane));
|
||||
pane = new (paneBuffer) CellPhoneSignButtonPane(getPane(paneInfo.paneName), this);
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
void* paneBuffer = MEMAllocFromAllocator(allocator, sizeof(CellPhoneSignScrollAnmPane));
|
||||
pane = new (paneBuffer) CellPhoneSignScrollAnmPane(getPane(paneInfo.paneName), this);
|
||||
break;
|
||||
}
|
||||
case 0: {
|
||||
void* paneBuffer = MEMAllocFromAllocator(allocator, sizeof(CellPhoneSignAllAnmPane));
|
||||
pane = new (paneBuffer) CellPhoneSignAllAnmPane(getPane(paneInfo.paneName), this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
nw4r::ut::List_Append(&mAnmPanes, pane);
|
||||
forceName = paneInfo.forceName;
|
||||
animationCount = paneInfo.animationCount;
|
||||
u16 animationIndex = 0;
|
||||
while (animationIndex < animationCount) {
|
||||
void* resource = mpMultiArcResourceAccessor->GetResource(0, paneInfo.animations[animationIndex]->name);
|
||||
AnimTransformPane* transform = static_cast<AnimTransformPane*>(
|
||||
getLayout()->CreateAnimTransform(resource, mpMultiArcResourceAccessor));
|
||||
if (forceName != NULL) {
|
||||
pane->forceAddAnimation(allocator, paneInfo.animations[animationIndex]->id, transform, forceName, false, true);
|
||||
} else {
|
||||
pane->addAnimation(allocator, paneInfo.animations[animationIndex]->id, transform, false, true);
|
||||
}
|
||||
++animationIndex;
|
||||
}
|
||||
++paneIndex;
|
||||
} while (paneIndex < 25);
|
||||
init();
|
||||
}
|
||||
|
||||
AnmPane::~AnmPane() {}
|
||||
|
||||
void LayoutByNW4R::init() {
|
||||
Base::init();
|
||||
searchAnmPane("N_SGNkeytop_all")->changeAnimation(0);
|
||||
setVisible("N_SGNkeytop_all", true);
|
||||
searchAnmPane("P_SGNkey_prev")->changeAnimation(0);
|
||||
searchAnmPane("P_SGNkey_next")->changeAnimation(0);
|
||||
setSignKeyTop(muPage, muPage);
|
||||
setPageNumber(muPage);
|
||||
mpLayout->Animate(0);
|
||||
mpLayout->CalculateMtx(mDrawInfo);
|
||||
}
|
||||
|
||||
void LayoutByNW4R::onKey(u32 command, void* data) {
|
||||
Base::onKey(command, data);
|
||||
if (command == 4) {
|
||||
s32 key;
|
||||
const char* paneName = static_cast<const char*>(data);
|
||||
key = findControlKey(paneName);
|
||||
|
||||
if (key == 0x1B) {
|
||||
goto character;
|
||||
}
|
||||
switch (key) {
|
||||
case 0x18:
|
||||
mpEventObserver->onSE(sound::SE_CHAR_DECIDE);
|
||||
break;
|
||||
case 0x19:
|
||||
case 0x1A:
|
||||
break;
|
||||
}
|
||||
return;
|
||||
|
||||
character:
|
||||
u16 code = findSignCharacter(mpLanguageDependency->keys, muPage, paneName);
|
||||
|
||||
if ((code != 0) && (mpKeyboard->getType() == 0)) {
|
||||
sendCommand(0x27, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutByNW4R::open(KeyboardBase* keyboard, bool input) {
|
||||
resetAnmSignWindow();
|
||||
throwReleaseForAll();
|
||||
getPaneManager()->init();
|
||||
if (meLanguage - 8U <= 1U) {
|
||||
sendCommand(6, NULL);
|
||||
}
|
||||
mbActive = 1;
|
||||
mbInput = 0;
|
||||
mpKeyboard = keyboard;
|
||||
initPaneLastDrawReceived();
|
||||
mbRepeat = input;
|
||||
setSignKeyTop(muPage, muPage);
|
||||
setPageNumber(muPage);
|
||||
searchAnmPane("N_SGNkeytop_all")->onAnmEvent(nw4rmanager::AnmPane::PE_6);
|
||||
mpEventObserver->onSE(sound::SE_SYMBOL_PAGE_OPEN);
|
||||
}
|
||||
|
||||
void LayoutByNW4R::close() {
|
||||
if (mpKeyboard->getType() == 0) {
|
||||
keyboard::pctype::LayoutByNW4R* keyboard = static_cast<keyboard::pctype::LayoutByNW4R*>(mpKeyboard);
|
||||
static_cast<nw4rmanager::Layout&>(*keyboard).getLayout()->GetRootPane()->SetVisible(true);
|
||||
}
|
||||
searchAnmPane("N_SGNkeytop_all")->onAnmEvent(nw4rmanager::AnmPane::PE_7);
|
||||
mbInput = 0;
|
||||
}
|
||||
|
||||
void LayoutByNW4R::endToClose() {
|
||||
if (mpKeyboard != NULL) {
|
||||
mpKeyboard->update();
|
||||
}
|
||||
mbActive = 0;
|
||||
setVisible("N_SGNkeytop_all", false);
|
||||
}
|
||||
|
||||
void LayoutByNW4R::startToInput() {
|
||||
mbInput = 1;
|
||||
if (mpKeyboard->getType() == 0) {
|
||||
keyboard::pctype::LayoutByNW4R* keyboard = static_cast<keyboard::pctype::LayoutByNW4R*>(mpKeyboard);
|
||||
static_cast<nw4rmanager::Layout&>(*keyboard).getLayout()->GetRootPane()->SetVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutByNW4R::onChangeAnmState(AnmEvent event, nw4rmanager::AnmPane* pane, nw4rmanager::Anim* anim) {
|
||||
if (util::strcmp("N_SGNkeyall", pane->getPane()->GetName()) &&
|
||||
((anim->muID == 7 || anim->muID == 5) && event == nw4rmanager::AnmObserver::E_1)) {
|
||||
setSignKeyTop(muPage, muPage);
|
||||
}
|
||||
if (util::strcmp("N_SGNkeytop_all", pane->getPane()->GetName())) {
|
||||
if ((anim->muID == 8) && (event == nw4rmanager::AnmObserver::E_1)) {
|
||||
endToClose();
|
||||
}
|
||||
if ((anim->muID == 1) && (event == nw4rmanager::AnmObserver::E_1)) {
|
||||
startToInput();
|
||||
}
|
||||
}
|
||||
if (anim->muID == 7 || anim->muID == 5) {
|
||||
if (event == nw4rmanager::AnmObserver::E_0) {
|
||||
mbLocked = 1;
|
||||
}
|
||||
if (event == nw4rmanager::AnmObserver::E_1) {
|
||||
mbLocked = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutByNW4R::throwReleaseForAll() {
|
||||
nw4rmanager::AnmPane* pane = static_cast<nw4rmanager::AnmPane*>(nw4r::ut::List_GetNext(&mAnmPanes, NULL));
|
||||
while (pane != NULL) {
|
||||
s32 keyType = static_cast<AnmPane*>(pane)->getKeyType();
|
||||
if (keyType == 2) {
|
||||
pane->onAnmEvent(nw4rmanager::AnmPane::PE_2);
|
||||
}
|
||||
pane = static_cast<nw4rmanager::AnmPane*>(nw4r::ut::List_GetNext(&mAnmPanes, pane));
|
||||
}
|
||||
}
|
||||
|
||||
u32 AnmPane::getKeyType() const {
|
||||
return muKeyType;
|
||||
}
|
||||
|
||||
void LayoutByNW4R::resetAnmSignWindow() {
|
||||
for (u16 i = 0; i < 25; i++) {
|
||||
searchAnmPane(csPaneToAnimationInSign[i].paneName)->init();
|
||||
}
|
||||
}
|
||||
|
||||
void AnmPane::init() {
|
||||
muAnimation = 0;
|
||||
}
|
||||
|
||||
void LayoutByNW4R::setSignKeyTop(u16 oldPage, u16 newPage) {
|
||||
char paneName[17];
|
||||
wchar_t oldCharacter[2];
|
||||
wchar_t newCharacter[2];
|
||||
for (u16 i = 0; i < 20; i++) {
|
||||
const char* sourcePaneName = mpLanguageDependency->keys[i].szPaneName;
|
||||
memset(paneName, 0, 0x11);
|
||||
strncpy(paneName, sourcePaneName, strlen(sourcePaneName));
|
||||
paneName[0] = 'T';
|
||||
oldCharacter[0] = mpLanguageDependency->keys[i].wc[oldPage];
|
||||
oldCharacter[1] = 0;
|
||||
const char* nextPaneName = mpLanguageDependency->keys[i].szNextPaneName;
|
||||
newCharacter[0] = mpLanguageDependency->keys[i].wc[newPage];
|
||||
newCharacter[1] = 0;
|
||||
nw4r::lyt::TextBox* textBox = static_cast<nw4r::lyt::TextBox*>(getPane(paneName));
|
||||
textBox->SetString(oldCharacter, 0);
|
||||
textBox = static_cast<nw4r::lyt::TextBox*>(getPane(nextPaneName));
|
||||
textBox->SetString(newCharacter, 0);
|
||||
}
|
||||
setString("T_SGNkey_prev", langindependent::cLanguageIndependentString[langindependent::LANG_STRID_PREV][getLanguage()]);
|
||||
setString("T_SGNkey_next", langindependent::cLanguageIndependentString[langindependent::LANG_STRID_NEXT][getLanguage()]);
|
||||
setString("T_SGNkey_close", langindependent::cLanguageIndependentString[langindependent::LANG_STRID_CLOSE][getLanguage()]);
|
||||
}
|
||||
|
||||
void LayoutByNW4R::setPageNumber(u16 page) {
|
||||
wchar_t text[17];
|
||||
swprintf(text, 0x11, L"%d/%d", page + 1, mpLanguageDependency->count);
|
||||
nw4r::lyt::TextBox* textBox = static_cast<nw4r::lyt::TextBox*>(getPane("T_SGN_pageNumber"));
|
||||
textBox->SetString(text, 0);
|
||||
}
|
||||
|
||||
void LayoutByNW4R::movePrevSignPage() {
|
||||
u8 oldPage = muPage;
|
||||
if (oldPage == 0) {
|
||||
muPage = mpLanguageDependency->count - 1;
|
||||
} else {
|
||||
muPage = oldPage - 1;
|
||||
}
|
||||
u8 newPage = muPage;
|
||||
setSignKeyTop(oldPage, newPage);
|
||||
setPageNumber(newPage);
|
||||
movePrevSignWindow();
|
||||
mpEventObserver->onSE(sound::SE_15);
|
||||
}
|
||||
|
||||
void LayoutByNW4R::moveNextSignPage() {
|
||||
u8 oldPage = muPage;
|
||||
u8 page = oldPage + 1;
|
||||
muPage = page;
|
||||
if (page >= mpLanguageDependency->count) {
|
||||
muPage = 0;
|
||||
}
|
||||
u8 newPage = muPage;
|
||||
setSignKeyTop(oldPage, newPage);
|
||||
setPageNumber(newPage);
|
||||
moveNextSignWindow();
|
||||
mpEventObserver->onSE(sound::SE_15);
|
||||
}
|
||||
|
||||
void LayoutByNW4R::movePrevSignWindow() {
|
||||
searchAnmPane("N_SGNkeyall")->onAnmEvent(static_cast<nw4rmanager::AnmPane::AnmPaneEvent>(8));
|
||||
}
|
||||
|
||||
void LayoutByNW4R::moveNextSignWindow() {
|
||||
searchAnmPane("N_SGNkeyall")->onAnmEvent(static_cast<nw4rmanager::AnmPane::AnmPaneEvent>(9));
|
||||
}
|
||||
|
||||
bool LayoutByNW4R::updateInput(int point, f32 x, f32 y, u32 trig, u32 hold, u32 release, void* data) {
|
||||
if (mbInput != 0) {
|
||||
return nw4rmanager::Layout::updateInput(point, x, y, trig, hold, release, data);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LayoutByNW4R::updateInput(input::HKBManager& manager) {
|
||||
if (mbInput == 0) {
|
||||
return false;
|
||||
}
|
||||
input::HKBManager::KeySet keySet = manager.GetTriggeredKeySet();
|
||||
if (keySet.IsValid()) {
|
||||
throwReleaseForAll();
|
||||
close();
|
||||
mpEventObserver->onSE(sound::SE_CHAR_DECIDE);
|
||||
return false;
|
||||
}
|
||||
return nw4rmanager::Layout::updateInput(manager);
|
||||
}
|
||||
|
||||
void EventHandler::onTiEvent(gui::PaneComponent* paneComponent, u32 event, Input* input) {
|
||||
s32 eventType = event;
|
||||
const char* name = paneComponent->getPane()->GetName();
|
||||
if (!mpLayoutByNW4R->isLocked() || event != 4) {
|
||||
if (event == 4 && (input->trigger & 0x800) != 0) {
|
||||
mpLayoutByNW4R->onKey(4, const_cast<char*>(name));
|
||||
}
|
||||
if (name[0] == 'B') {
|
||||
char paneName[24];
|
||||
memset(paneName, 0, 0x11);
|
||||
strncpy(paneName, name, strlen(name));
|
||||
paneName[0] = 'P';
|
||||
AnmPane* pane = static_cast<AnmPane*>(mpLayoutByNW4R->searchAnmPane(paneName));
|
||||
if (pane != NULL) {
|
||||
switch (eventType) {
|
||||
case 4:
|
||||
if ((input->trigger & 0x800) != 0) {
|
||||
pane->onAnmEvent(nw4rmanager::AnmPane::PE_0);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
pane->onAnmEvent(nw4rmanager::AnmPane::PE_2);
|
||||
break;
|
||||
case 0:
|
||||
mpEventObserver->onSE(sound::SE_SELECT);
|
||||
mpLayoutByNW4R->setPaneLastDrawReceived(pane->getPane());
|
||||
pane->onAnmEvent(nw4rmanager::AnmPane::PE_1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Base::isLocked() {
|
||||
return mbLocked;
|
||||
}
|
||||
|
||||
void CellPhoneSignAllAnmPane::onAnmEvent(AnmPaneEvent event) {
|
||||
if (event == 6) {
|
||||
getPane()->SetVisible(true);
|
||||
changeAnimation(1);
|
||||
return;
|
||||
}
|
||||
if (event == 7) {
|
||||
changeAnimation(8);
|
||||
return;
|
||||
}
|
||||
if (muAnimation != 8) {
|
||||
if (muAnimation >= 8) {
|
||||
return;
|
||||
}
|
||||
if (muAnimation != 1) {
|
||||
return;
|
||||
}
|
||||
if (event != 4) {
|
||||
return;
|
||||
}
|
||||
changeAnimation(0);
|
||||
return;
|
||||
}
|
||||
if (event == 4) {
|
||||
getPane()->SetVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
void AnmPane::changeAnimation(u32 animation) {
|
||||
muAnimation = animation;
|
||||
nw4rmanager::AnmPane::changeAnimation(animation);
|
||||
}
|
||||
|
||||
void CellPhoneSignScrollAnmPane::onAnmEvent(AnmPaneEvent event) {
|
||||
switch (muAnimation) {
|
||||
case 0:
|
||||
if (event == 9) {
|
||||
changeAnimation(5);
|
||||
}
|
||||
if (event != 8) {
|
||||
return;
|
||||
}
|
||||
changeAnimation(7);
|
||||
return;
|
||||
case 5:
|
||||
case 7:
|
||||
if (event != 4) {
|
||||
return;
|
||||
}
|
||||
changeAnimation(0);
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void CellPhoneSignButtonPane::onAnmEvent(AnmPaneEvent event) {
|
||||
if (event == 0) {
|
||||
changeAnimation(4);
|
||||
}
|
||||
switch (muAnimation) {
|
||||
case 0:
|
||||
if (event == 1) {
|
||||
changeAnimation(2);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (event == 4) {
|
||||
changeAnimation(3);
|
||||
}
|
||||
if (event == 2) {
|
||||
changeAnimation(6);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (event == 2) {
|
||||
changeAnimation(6);
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
if (event == 4) {
|
||||
changeAnimation(0);
|
||||
}
|
||||
if (event == 1) {
|
||||
changeAnimation(2);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (event == 4) {
|
||||
changeAnimation(3);
|
||||
}
|
||||
if (event == 2) {
|
||||
changeAnimation(6);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutByNW4R::draw() {
|
||||
nw4rmanager::Layout::draw();
|
||||
}
|
||||
|
||||
}
|
||||
void KeyboardBase::onActive() {}
|
||||
namespace signwindow {
|
||||
|
||||
u8 Base::getPage() {
|
||||
return muPage;
|
||||
}
|
||||
|
||||
void Base::setPage(u8 page) {
|
||||
muPage = page;
|
||||
if (muPage < mpLanguageDependency->count) {
|
||||
return;
|
||||
}
|
||||
muPage = 0;
|
||||
}
|
||||
|
||||
void Base::setLanguage(Language language) {
|
||||
meLanguage = language;
|
||||
init();
|
||||
}
|
||||
|
||||
int Base::getType() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
bool LayoutByNW4R::isActive() {
|
||||
return mbActive;
|
||||
}
|
||||
|
||||
CellPhoneSignButtonPane::~CellPhoneSignButtonPane() {}
|
||||
|
||||
void CellPhoneSignButtonPane::init() {
|
||||
muAnimation = 0;
|
||||
}
|
||||
|
||||
void CellPhoneSignScrollAnmPane::init() {
|
||||
muAnimation = 0;
|
||||
}
|
||||
|
||||
CellPhoneSignAllAnmPane::~CellPhoneSignAllAnmPane() {}
|
||||
|
||||
void CellPhoneSignAllAnmPane::init() {
|
||||
muAnimation = 0;
|
||||
}
|
||||
|
||||
CellPhoneSignScrollAnmPane::~CellPhoneSignScrollAnmPane() {}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
315
src/keyboard/tiTextDrawer.cpp
Normal file
315
src/keyboard/tiTextDrawer.cpp
Normal file
@@ -0,0 +1,315 @@
|
||||
#define TITEXTDRAWER_IMPLEMENTATION
|
||||
#include "keyboard/tiTextDrawer.h"
|
||||
#include "keyboard/tiUtil.h"
|
||||
|
||||
#include <revolution/gx/GXCull.h>
|
||||
#include <revolution/gx/GXGet.h>
|
||||
#include <revolution/gx/GXTransform.h>
|
||||
#include <revolution/mtx.h>
|
||||
|
||||
namespace textinput {
|
||||
namespace textdrawer {
|
||||
s32 snWidthTable[0x160];
|
||||
|
||||
void Base::create(MEMAllocator*) {
|
||||
for (s32 index = 0; index < 0x160; ++index) {
|
||||
snWidthTable[index] = -1;
|
||||
}
|
||||
mfVIWidth = 640.0f;
|
||||
}
|
||||
|
||||
void Base::setAspectRatio(bool aspect4x3) {
|
||||
mbAspect4x3 = aspect4x3;
|
||||
if (aspect4x3) {
|
||||
util::getProjectionRect4x3(&mProjectionRect);
|
||||
} else {
|
||||
util::getProjectionRect16x9(&mProjectionRect);
|
||||
}
|
||||
}
|
||||
|
||||
void Base::setDrawString(const wchar_t* wcString, u32 startPos, u32 endPos) {
|
||||
mpDrawString = wcString;
|
||||
muDrawStartPos = startPos;
|
||||
muDrawEndPos = endPos;
|
||||
}
|
||||
|
||||
void Base::modifyCursorCache(s32 line, u32 pos, f32 left, f32 top, f32 right, f32 bottom) {
|
||||
f32 height = mfDrawScrollY;
|
||||
mnCachedCursorLine = line;
|
||||
mCachedCursor.uCursorPos = pos;
|
||||
mCachedCursor.fCursorX = left;
|
||||
mCachedCursor.fCursorY = top - height;
|
||||
mfCachedCursorX = right;
|
||||
mfCachedCursorY = bottom - height;
|
||||
mbCursorCache = true;
|
||||
}
|
||||
|
||||
void Base::setDrawModifyScopeLine(s32 startLine, s32 endLine) {
|
||||
muDrawModifyStartLine = startLine;
|
||||
muDrawModifyEndLine = endLine;
|
||||
}
|
||||
|
||||
void Base::setDrawCacheScopeLine(s32 startLine, s32 endLine) {
|
||||
if (startLine < 0) {
|
||||
startLine = 0;
|
||||
}
|
||||
if (muDrawModifyStartPos != startLine) {
|
||||
dirtyDrawCache();
|
||||
}
|
||||
muDrawModifyStartPos = startLine;
|
||||
muDrawModifyEndPos = endLine;
|
||||
}
|
||||
|
||||
void Base::procCursor(CursorPos* cursorPos, s32) {
|
||||
GetCursorX();
|
||||
GetCursorY();
|
||||
if (!onCursor(cursorPos)) {
|
||||
cursorPos->fCursorX = GetCursorX();
|
||||
cursorPos->fCursorY = GetCursorY();
|
||||
}
|
||||
}
|
||||
|
||||
bool Base::onCursor(CursorPos*) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void Base::makeUpCursorPos(CursorPos* cursorPos, u32 pos, s32 line, s32) {
|
||||
const wchar_t* drawString = mpDrawString;
|
||||
if (drawString != NULL) {
|
||||
const wchar_t* ch = drawString + pos;
|
||||
f32 y = GetCursorY();
|
||||
while (*ch != 0) {
|
||||
DrawInfo drawInfo;
|
||||
drawInfo.rect.left = 0.0f;
|
||||
drawInfo.rect.top = 0.0f;
|
||||
drawInfo.rect.right = 0.0f;
|
||||
drawInfo.rect.bottom = 0.0f;
|
||||
drawInfo.character = *ch;
|
||||
calcRect(drawInfo);
|
||||
doBeforeDrawProcess(drawString, pos, drawInfo);
|
||||
if (cursorPos != NULL && cursorPos->uCursorPos == pos) {
|
||||
procCursor(cursorPos, line + (y == GetCursorY() ? 0 : 1));
|
||||
}
|
||||
if (*ch == L'\n') {
|
||||
doLineFeed();
|
||||
break;
|
||||
}
|
||||
MoveCursorX((drawInfo.rect.right - drawInfo.rect.left) * getScale().x);
|
||||
doAfterDrawProcess(drawString, pos, drawInfo);
|
||||
if (y != GetCursorY()) {
|
||||
line++;
|
||||
}
|
||||
y = GetCursorY();
|
||||
++ch;
|
||||
++pos;
|
||||
}
|
||||
if (cursorPos != NULL && *ch == 0 && cursorPos->uCursorPos == pos) {
|
||||
procCursor(cursorPos, line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Base::doBeforeDrawProcess(const wchar_t*, u32, const DrawInfo&) {}
|
||||
|
||||
void Base::doLineFeed() {
|
||||
++muLine;
|
||||
}
|
||||
|
||||
void Base::doAfterDrawProcess(const wchar_t*, u32, const DrawInfo&) {}
|
||||
|
||||
void Base::put(wchar_t wc) {
|
||||
if (!mbSecretMode) {
|
||||
Print(wc);
|
||||
} else {
|
||||
Print(L'*');
|
||||
}
|
||||
}
|
||||
|
||||
void Base::draw(CursorPos* cursorPos) {
|
||||
u32 startPos;
|
||||
const wchar_t* drawString = mpDrawString;
|
||||
u32 endPos;
|
||||
if (GetFont() != NULL) {
|
||||
startPos = muDrawStartPos;
|
||||
endPos = muDrawEndPos;
|
||||
muCachedStartPos = startPos;
|
||||
muDrawCacheStartPos = startPos;
|
||||
preDraw(startPos);
|
||||
drawString += startPos;
|
||||
SetFontSize(mfFontWidth * getScale().x,
|
||||
mfFontHeight * getScale().y);
|
||||
SetupGX();
|
||||
while (*drawString != 0 && muDrawCacheStartPos < endPos) {
|
||||
DrawInfo drawInfo;
|
||||
drawInfo.rect.left = 0.0f;
|
||||
drawInfo.rect.top = 0.0f;
|
||||
drawInfo.rect.right = 0.0f;
|
||||
drawInfo.rect.bottom = 0.0f;
|
||||
drawInfo.character = *drawString;
|
||||
calcRect(drawInfo);
|
||||
doBeforeDrawProcess(mpDrawString,
|
||||
muDrawCacheStartPos,
|
||||
drawInfo);
|
||||
if (cursorPos != NULL && cursorPos->uCursorPos == muDrawCacheStartPos) {
|
||||
procCursor(cursorPos, 0);
|
||||
}
|
||||
if (*drawString == L'\n') {
|
||||
nw4r::ut::Color color = GetTextColor();
|
||||
SetTextColor(nw4r::ut::Color(200, 200, 200, color.a));
|
||||
Print(0xe056);
|
||||
SetTextColor(color);
|
||||
doLineFeed();
|
||||
} else if (*drawString != static_cast<wchar_t>(-1)) {
|
||||
put(*drawString);
|
||||
MoveCursorX(mfCharacterSpacing * getScale().x);
|
||||
}
|
||||
doAfterDrawProcess(mpDrawString,
|
||||
muDrawCacheStartPos,
|
||||
drawInfo);
|
||||
++drawString;
|
||||
++muDrawCacheStartPos;
|
||||
}
|
||||
if (cursorPos != NULL && cursorPos->uCursorPos == muDrawCacheStartPos) {
|
||||
procCursor(cursorPos, 0);
|
||||
}
|
||||
finishDraw(muDrawCacheStartPos);
|
||||
}
|
||||
}
|
||||
|
||||
void Base::preDraw(u32) {}
|
||||
|
||||
void Base::finishDraw(u32) {}
|
||||
|
||||
f32 Base::getLineHeight() {
|
||||
if (getScale().y == 0.0f) {
|
||||
return 1.0f;
|
||||
}
|
||||
f32 height = getScale().y * (mfFontHeight +
|
||||
mfLineSpacing);
|
||||
return height >= 1.0f ? height : 1.0f;
|
||||
}
|
||||
|
||||
void Base::setFont(const nw4r::ut::Font& font) {
|
||||
nw4r::ut::CharWriter::SetFont(font);
|
||||
for (s32 index = 0; index < 0x160; ++index) {
|
||||
snWidthTable[index] = -1;
|
||||
}
|
||||
u32 ch = 0x20;
|
||||
do {
|
||||
DrawInfo drawInfo;
|
||||
drawInfo.rect.left = 0.0f;
|
||||
drawInfo.rect.top = 0.0f;
|
||||
drawInfo.rect.right = 0.0f;
|
||||
drawInfo.rect.bottom = 0.0f;
|
||||
drawInfo.character = static_cast<wchar_t>(ch);
|
||||
calcRect(drawInfo);
|
||||
u16 index = static_cast<u16>(ch);
|
||||
snWidthTable[index - 0x20] = static_cast<s32>(drawInfo.rect.right - drawInfo.rect.left);
|
||||
ch++;
|
||||
} while (ch <= 0x17f);
|
||||
}
|
||||
|
||||
void Base::calcRect(DrawInfo& drawInfo) {
|
||||
drawInfo.rect.left = 0.0f;
|
||||
u16 ch = drawInfo.character;
|
||||
drawInfo.rect.right = 0.0f;
|
||||
drawInfo.rect.top = 0.0f;
|
||||
drawInfo.rect.bottom = getLineHeight();
|
||||
f32 width = 0.0f;
|
||||
width += mfCharacterSpacing;
|
||||
if (IsWidthFixed()) {
|
||||
width += GetFixedWidth();
|
||||
} else {
|
||||
f32 height = getScale().x;
|
||||
if (height == 0.0f) {
|
||||
height = 0.0001f;
|
||||
}
|
||||
f32 scale = GetScaleH();
|
||||
const nw4r::ut::Font* font = GetFont();
|
||||
s32 charWidth = font->GetCharWidth(ch);
|
||||
f32 widthOffset = static_cast<f32>(charWidth) * scale / height;
|
||||
width += widthOffset;
|
||||
}
|
||||
drawInfo.rect.right = drawInfo.rect.right < width ? width : drawInfo.rect.right;
|
||||
}
|
||||
|
||||
f32 Base::getWidth(const wchar_t* sz) {
|
||||
f32 width = 0.0f;
|
||||
DrawInfo drawInfo;
|
||||
drawInfo.rect.left = 0.0f;
|
||||
drawInfo.rect.top = 0.0f;
|
||||
drawInfo.rect.right = 0.0f;
|
||||
drawInfo.rect.bottom = 0.0f;
|
||||
u16 ch;
|
||||
goto check;
|
||||
body:
|
||||
drawInfo.character = ch;
|
||||
calcRect(drawInfo);
|
||||
width += drawInfo.rect.right - drawInfo.rect.left;
|
||||
++sz;
|
||||
check:
|
||||
ch = *sz;
|
||||
if (ch != 0) {
|
||||
goto body;
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
void Base::beginDraw(const nw4r::ut::Rect& rect) {
|
||||
Mtx44 projection;
|
||||
Mtx matrix;
|
||||
f32 viewport[6];
|
||||
muDrawCacheStartPos = 0;
|
||||
GXGetViewportv(&mSavedViewport.xOrig);
|
||||
GXGetProjectionv(mSavedProjection);
|
||||
C_MTXOrtho(projection, 0.0f, rect.top - rect.bottom, -50.0f, 50.0f + (rect.right - rect.left), -1.0f, 1.0f);
|
||||
GXSetProjection(projection, GX_ORTHOGRAPHIC);
|
||||
f32 width = mProjectionRect.right -
|
||||
mProjectionRect.left;
|
||||
f32 scale = mfVIWidth / width;
|
||||
f32 halfWidth = width;
|
||||
halfWidth *= 0.5f;
|
||||
f32 left = (rect.left + halfWidth) - 50.0f;
|
||||
f32 xOffset = left;
|
||||
xOffset *= scale - 1.0f;
|
||||
viewport[0] = left + xOffset;
|
||||
f32 height = (mProjectionRect.bottom -
|
||||
mProjectionRect.top) * 0.5f;
|
||||
viewport[1] = rect.bottom + height;
|
||||
viewport[2] = scale * (100.0f + (rect.right - rect.left));
|
||||
viewport[3] = rect.top - rect.bottom;
|
||||
viewport[4] = mSavedViewport.nearZ;
|
||||
viewport[5] = mSavedViewport.farZ;
|
||||
GXSetViewport(viewport[0], viewport[1], viewport[2], viewport[3], viewport[4], viewport[5]);
|
||||
u32 x = static_cast<u32>(viewport[0]);
|
||||
u32 y = static_cast<u32>(viewport[1]);
|
||||
u32 viewportWidth = static_cast<u32>(viewport[2]);
|
||||
if (viewportWidth >= 0x5dc) {
|
||||
viewportWidth = 0x5dc;
|
||||
}
|
||||
u32 viewportHeight = static_cast<u32>(viewport[3]);
|
||||
if (viewportHeight >= 0x5dc) {
|
||||
viewportHeight = 0x5dc;
|
||||
}
|
||||
GXSetScissor(x, y, viewportWidth, viewportHeight);
|
||||
PSMTXIdentity(matrix);
|
||||
GXLoadPosMtxImm(matrix, 0);
|
||||
mfMinScrollY = GetCursorY();
|
||||
muLine = 0;
|
||||
}
|
||||
|
||||
void Base::endDraw() {
|
||||
f32* viewport = &mSavedViewport.xOrig;
|
||||
GXSetViewport(viewport[0], viewport[1], viewport[2], viewport[3], viewport[4], viewport[5]);
|
||||
GXSetScissor(static_cast<u32>(viewport[0]), static_cast<u32>(viewport[1]),
|
||||
static_cast<u32>(viewport[2]), static_cast<u32>(viewport[3]));
|
||||
mfModifyStartY = GetCursorX();
|
||||
mfMinScrollY =
|
||||
(mfMinScrollY - GetCursorY()) + getLineHeight();
|
||||
}
|
||||
|
||||
void Base::drawCursor(f32, f32) {}
|
||||
|
||||
void Base::draw() {}
|
||||
}
|
||||
}
|
||||
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() {}
|
||||
|
||||
}
|
||||
}
|
||||
1299
src/scene/cardSequence/iplCardSequence.cpp
Normal file
1299
src/scene/cardSequence/iplCardSequence.cpp
Normal file
File diff suppressed because it is too large
Load Diff
912
src/scene/memoryCard/iplGCWindow.cpp
Normal file
912
src/scene/memoryCard/iplGCWindow.cpp
Normal file
@@ -0,0 +1,912 @@
|
||||
#define IPL_MEMORYCARD_BASE_CTOR_OUT_OF_LINE
|
||||
#define IPL_MEMORYCARD_BASE_EVENT_OUT_OF_LINE
|
||||
#define IPL_GCW_PANEMANAGER_CTOR_OUT_OF_LINE
|
||||
#define IPL_GCW_INTP_CTOR_OUT_OF_LINE
|
||||
#define IPL_GC_WINDOW_CPP
|
||||
#include "scene/memoryCard/iplGCWindow.h"
|
||||
#include "scene/memoryCard/iplMemoryCard.h"
|
||||
#include "scene/settingSelect/iplSettingButton.h"
|
||||
#include "iplSound.h"
|
||||
#include "iplSystem.h"
|
||||
#include "system/iplDialogWindow.h"
|
||||
#include "system/iplHomeButton.h"
|
||||
#include <wchar.h>
|
||||
#include <cstring>
|
||||
|
||||
namespace ipl {
|
||||
namespace math {
|
||||
template <typename T>
|
||||
LinearIntp<T>::LinearIntp() {}
|
||||
}
|
||||
namespace scene {
|
||||
struct TextboxToMessageID {
|
||||
const char* name;
|
||||
u32 id;
|
||||
};
|
||||
|
||||
static const MemoryBase::AnmName scAnmName[16] = {
|
||||
{"it_CubeDetail_a_SeenIn.brlan", "G_Mask"},
|
||||
{"it_CubeDetail_a_SeenOut.brlan", "G_Mask"},
|
||||
{"it_CubeDetail_a_MoveFoucusIn.brlan", "G_Move"},
|
||||
{"it_CubeDetail_a_MoveFoucusOut.brlan", "G_Move"},
|
||||
{"it_CubeDetail_a_MoveFlash.brlan", "G_MoveFlash"},
|
||||
{"it_CubeDetail_a_CopyFoucusIn.brlan", "G_Copy"},
|
||||
{"it_CubeDetail_a_CopyFoucusOut.brlan", "G_Copy"},
|
||||
{"it_CubeDetail_a_CopyFlash.brlan", "G_CopyFlash"},
|
||||
{"it_CubeDetail_a_DelFoucusIn.brlan", "G_Del"},
|
||||
{"it_CubeDetail_a_DelFoucusOut.brlan", "G_Del"},
|
||||
{"it_CubeDetail_a_DelFlash.brlan", "G_DelFlash"},
|
||||
{"it_CubeDetail_a_SelectOut.brlan", "G_Select"},
|
||||
{"it_CubeDetail_a_SeenOutYes.brlan", "G_Mask"},
|
||||
{"it_CubeDetail_a_SeenOutYesOk.brlan", "G_Mask"},
|
||||
{"it_CubeDetail_a_SeenOutNo.brlan", "G_Mask"},
|
||||
{"it_CubeDetail_a_Wait.brlan", "G_Wait"},
|
||||
};
|
||||
|
||||
static const TextboxToMessageID scTextboxToMessageID[3] = {
|
||||
{"T_Move_00", 0xA7},
|
||||
{"T_Copy_00", 0xB2},
|
||||
{"T_Del_00", 0xBD},
|
||||
};
|
||||
|
||||
static const char* scButtonName[3] = {"B_Move_00", "B_Copy_00", "B_Del_00"};
|
||||
GCWindow::GCWindow(EGG::Heap* heap, nand::LayoutFile* layoutFile, const char* directory, const char* fileName)
|
||||
: MemoryBase(), MemCardEventHandler(), mState(0), mLinearInterp(), mCardState(0), mCardIndex(0), mOperation(0), mActive(false),
|
||||
mWaiting(false) {
|
||||
mpLayout = new layout::Object(heap, layoutFile, directory, fileName);
|
||||
add_animation(scAnmName, 0x10);
|
||||
mpLayout->finishBinding();
|
||||
set_visible("N_Wait", false);
|
||||
mpEvent = new MemoryBaseEvent(this);
|
||||
mpPaneManager = new gui::PaneManager(mpEvent, mpLayout->getDrawInfo(), NULL, NULL, true);
|
||||
mpPaneManager->createLayoutScene(*mpLayout->getNW4RLyt());
|
||||
mpPaneManager->setAllComponentTriggerTarget(false);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
mpPaneManager->setTriggerTarget(mpLayout->getNW4RLyt()->GetRootPane()->FindPaneByName(scButtonName[i], true), true);
|
||||
}
|
||||
add_anmbutton(scButtonName[0], get_animation(2), get_animation(3), get_animation(4));
|
||||
add_anmbutton(scButtonName[1], get_animation(5), get_animation(6), get_animation(7));
|
||||
add_anmbutton(scButtonName[2], get_animation(8), get_animation(9), get_animation(10));
|
||||
for (int i = 0; i < 3; i++) {
|
||||
set_textbox(scTextboxToMessageID[i].name, scTextboxToMessageID[i].id);
|
||||
}
|
||||
for (int i = 0; i < 2; i++) {
|
||||
mFlags0[i] = 0;
|
||||
mFlags1[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MemoryBase::MemoryBase() : mpLayout(NULL), unk_0x08(NULL) {
|
||||
nw4r::ut::List_Init(&mAnmList, offsetof(Anm, mLink));
|
||||
nw4r::ut::List_Init(&mButtonList, offsetof(Button, mLink));
|
||||
nw4r::ut::List_Init(&mAnmButtonList, offsetof(AnmButton, mLink));
|
||||
}
|
||||
|
||||
MemCardEventHandler::~MemCardEventHandler() {}
|
||||
|
||||
MemoryBaseEvent::MemoryBaseEvent(MemoryBase* memoryBase) : mpBase(memoryBase) {}
|
||||
|
||||
void GCWindow::init(const math::VEC3& translate, MemoryCardManager* manager, u8 cardState, short cardIndex) {
|
||||
mActive = true;
|
||||
mFlags1[cardState] = 0;
|
||||
set_visible("N_Banner", true);
|
||||
mpMemoryCardManager = manager;
|
||||
mpMemoryCardManager->setEventHandler(this);
|
||||
mCardState = cardState;
|
||||
mCardIndex = cardIndex;
|
||||
set_textbox("T_Title_00", mpMemoryCardManager->getComment(cardState, cardIndex, 0), 450.0f, 31.0f);
|
||||
set_textbox("T_Title_01", mpMemoryCardManager->getComment(cardState, cardIndex, 1), 450.0f, 31.0f);
|
||||
int i = 0;
|
||||
for (i = 0; i < 3; i++) {
|
||||
mpPaneManager->initPane(mpLayout->getNW4RLyt()->GetRootPane()->FindPaneByName(scButtonName[i], true));
|
||||
}
|
||||
int blocks = mpMemoryCardManager->getBlocks(cardState, cardIndex);
|
||||
wchar_t digits[10] = {L'0', L'1', L'2', L'3', L'4', L'5', L'6', L'7', L'8', L'9'};
|
||||
int blockCount = static_cast<u16>(blocks);
|
||||
wchar_t decimal[5] = {0};
|
||||
int skipCount = 0;
|
||||
wchar_t blockText[5] = {0};
|
||||
decimal[0] = digits[blockCount / 1000];
|
||||
decimal[1] = digits[(blockCount / 100) % 10];
|
||||
decimal[2] = digits[(blockCount / 10) % 10];
|
||||
decimal[3] = digits[blockCount % 10];
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (decimal[i] != L'0') {
|
||||
break;
|
||||
}
|
||||
skipCount++;
|
||||
}
|
||||
wcscpy(blockText, decimal + skipCount);
|
||||
set_textbox("T_Block_00", blockText);
|
||||
mTranslate = translate;
|
||||
math::VEC3 zero(0.0f, 0.0f, 0.0f);
|
||||
mLinearInterp.init(ANIM_TYPE_FORWARD, 12.0f, 0.0f, mTranslate, zero, 1.0f);
|
||||
mLinearInterp.initFrame();
|
||||
mLinearInterp.restart();
|
||||
math::VEC3 position = mLinearInterp.get();
|
||||
mpLayout->FindPaneByName("N_Window")->SetTranslate(position);
|
||||
do_animation(0);
|
||||
mState = 1;
|
||||
}
|
||||
|
||||
void GCWindow::calc() {
|
||||
mpLayout->calc();
|
||||
mpPaneManager->calc();
|
||||
void* button = NULL;
|
||||
while ((button = nw4r::ut::List_GetNext(&mAnmButtonList, button)) != NULL) {
|
||||
((MemoryBase::AnmButton*)button)->calc();
|
||||
}
|
||||
switch (mState) {
|
||||
case 0:
|
||||
on_wait();
|
||||
break;
|
||||
case 1:
|
||||
on_fadein();
|
||||
break;
|
||||
case 2:
|
||||
on_normal();
|
||||
break;
|
||||
case 3:
|
||||
on_fadeout1st();
|
||||
break;
|
||||
case 4:
|
||||
if (!is_animation(1)) {
|
||||
destroy();
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
on_fadeout_yes1st();
|
||||
break;
|
||||
case 6:
|
||||
if (!is_animation(0xd)) {
|
||||
destroy();
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
if (!is_animation(0xe)) {
|
||||
destroy();
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
on_focus_move();
|
||||
break;
|
||||
case 9:
|
||||
on_focus_copy();
|
||||
break;
|
||||
case 10:
|
||||
on_focus_del();
|
||||
break;
|
||||
case 0xb:
|
||||
on_select_out();
|
||||
break;
|
||||
case 0xc:
|
||||
on_dialog();
|
||||
break;
|
||||
case 0xd:
|
||||
on_error_message();
|
||||
break;
|
||||
case 0xe:
|
||||
on_error_message1st();
|
||||
break;
|
||||
case 0xf:
|
||||
on_error_message2nd();
|
||||
break;
|
||||
case 0x10:
|
||||
on_error_message3rd();
|
||||
break;
|
||||
case 0x11:
|
||||
on_process();
|
||||
break;
|
||||
case 0x12:
|
||||
on_format1st();
|
||||
break;
|
||||
case 0x13:
|
||||
on_format2nd();
|
||||
break;
|
||||
case 0x14:
|
||||
on_format3rd();
|
||||
break;
|
||||
case 0x15:
|
||||
on_format4th();
|
||||
break;
|
||||
case 0x16:
|
||||
on_format_error();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GCWindow::draw() {
|
||||
mpLayout->getNW4RLyt()->GetRootPane()->FindPaneByName("Banner_00", true)->SetVisible(false);
|
||||
mpLayout->getNW4RLyt()->GetRootPane()->FindPaneByName("Banner_01", true)->SetVisible(false);
|
||||
if (mpMemoryCardManager->isIconValidate(mCardState, mCardIndex)) {
|
||||
if (mpMemoryCardManager->isBannerEnable(mCardState, mCardIndex)) {
|
||||
const GXTexObj* banner = mpMemoryCardManager->create_banner(mCardState, mCardIndex);
|
||||
if (banner != NULL) {
|
||||
set_texture("Banner_00", *banner);
|
||||
mpLayout->getNW4RLyt()->GetRootPane()->FindPaneByName("Banner_00", true)->SetVisible(true);
|
||||
}
|
||||
} else {
|
||||
const GXTexObj* icon = mpMemoryCardManager->create_icon(mCardState, mCardIndex, 0);
|
||||
if (icon != NULL) {
|
||||
set_texture("Banner_01", *icon);
|
||||
mpLayout->getNW4RLyt()->GetRootPane()->FindPaneByName("Banner_01", true)->SetVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
mpLayout->draw();
|
||||
}
|
||||
|
||||
void GCWindow::destroy() {
|
||||
((MemoryCard*)System::getScene(0xe))->onRelease();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
clear_button(scButtonName[i]);
|
||||
}
|
||||
System::getHomeButtonMenu()->enable();
|
||||
mWaiting = false;
|
||||
show_button_return();
|
||||
mActive = false;
|
||||
mState = 0;
|
||||
}
|
||||
|
||||
void GCWindow::onPoint(const char* name, controller::Interface* controller) {
|
||||
MemoryBase::AnmButton* button = get_anmbutton(name);
|
||||
if (button != NULL) {
|
||||
if (button->unk_0x04 == 0) {
|
||||
button->onCmdRecv(1);
|
||||
snd::sSystem.startSE("WIPL_SE_BT_TARGETTING");
|
||||
if (controller != NULL) {
|
||||
controller->rumble(0);
|
||||
}
|
||||
}
|
||||
button->unk_0x04++;
|
||||
}
|
||||
}
|
||||
|
||||
void GCWindow::onLeft(const char* name) {
|
||||
MemoryBase::AnmButton* button = get_anmbutton(name);
|
||||
if (button != NULL) {
|
||||
if (button->unk_0x04 == 1) {
|
||||
button->onCmdRecv(2);
|
||||
}
|
||||
button->unk_0x04--;
|
||||
}
|
||||
}
|
||||
|
||||
void GCWindow::onTrig(const char* name) {
|
||||
MemoryBase::AnmButton* button = get_anmbutton(name);
|
||||
if (button != NULL) {
|
||||
if (strcmp(name, scButtonName[0]) == 0) {
|
||||
do_animation(4);
|
||||
mState = 8;
|
||||
} else if (strcmp(name, scButtonName[1]) == 0) {
|
||||
do_animation(7);
|
||||
mState = 9;
|
||||
} else if (strcmp(name, scButtonName[2]) == 0) {
|
||||
do_animation(10);
|
||||
set_textbox("T_Message_00", 0xf7);
|
||||
mState = 10;
|
||||
}
|
||||
snd::sSystem.startSE("WIPL_SE_DECIDE");
|
||||
}
|
||||
}
|
||||
|
||||
void GCWindow::on_wait() {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (mFlags0[i] != 0) {
|
||||
((MemoryCard*)System::getScene(0xe))->onFocus(NULL);
|
||||
System::getDialog()->callBtn2(i == 0 ? 0xec : 0xed, 0x142, 0x141, true);
|
||||
mFlags0[i] = 0;
|
||||
mCardState = i;
|
||||
mState = 0x12;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GCWindow::on_fadein() {
|
||||
mLinearInterp.calc();
|
||||
mpLayout->getNW4RLyt()->GetRootPane()->FindPaneByName("N_Window", true)->SetTranslate(mLinearInterp.get());
|
||||
if (!is_animation(0)) {
|
||||
mState = 2;
|
||||
}
|
||||
}
|
||||
|
||||
void GCWindow::on_normal() {
|
||||
if (mActive) {
|
||||
if (get_setting_button()->update()) {
|
||||
change_button_text_return();
|
||||
mState = 3;
|
||||
} else {
|
||||
mpPaneManager->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GCWindow::on_fadeout1st() {
|
||||
if (!get_setting_button()->isPlaying()) {
|
||||
math::VEC3 zero(0.0f, 0.0f, 0.0f);
|
||||
mLinearInterp.init(ANIM_TYPE_FORWARD, 20.0f, 0.0f, mTranslate, zero);
|
||||
mLinearInterp.setAnmType(ANIM_TYPE_BACKWARD);
|
||||
mLinearInterp.initFrame();
|
||||
mLinearInterp.restart();
|
||||
do_animation(1);
|
||||
mState = 4;
|
||||
}
|
||||
}
|
||||
|
||||
void GCWindow::on_fadeout_yes1st() {
|
||||
change_textbox_done();
|
||||
if (!is_animation(0xc)) {
|
||||
math::VEC3 zero(0.0f, 0.0f, 0.0f);
|
||||
mLinearInterp.init(ANIM_TYPE_FORWARD, 20.0f, 0.0f, mTranslate, zero);
|
||||
mLinearInterp.setAnmType(ANIM_TYPE_BACKWARD);
|
||||
mLinearInterp.initFrame();
|
||||
mLinearInterp.restart();
|
||||
show_button_return();
|
||||
do_animation(0xd);
|
||||
mState = 6;
|
||||
}
|
||||
}
|
||||
|
||||
void GCWindow::on_focus_move() {
|
||||
if (!is_animation(4)) {
|
||||
do_animation(0xb, false);
|
||||
long error;
|
||||
if (mpMemoryCardManager->isMoveEnable(mCardState, mCardIndex, &error)) {
|
||||
set_textbox("T_Message_00", mCardState == 0 ? 0xf5 : 0xf3);
|
||||
mOperation = 2;
|
||||
mState = 0xb;
|
||||
} else {
|
||||
switch (error) {
|
||||
case -26:
|
||||
set_textbox("T_Message_00", 0xcd);
|
||||
break;
|
||||
case -23:
|
||||
set_textbox("T_Message_00", 0xce + (mCardState == 0));
|
||||
break;
|
||||
case -28:
|
||||
case -22:
|
||||
set_textbox("T_Message_00", 0xd0 + (mCardState == 0));
|
||||
break;
|
||||
case -27:
|
||||
set_textbox("T_Message_00", 0xd4);
|
||||
break;
|
||||
case -24:
|
||||
set_textbox("T_Message_00", 0xd5);
|
||||
break;
|
||||
case -25:
|
||||
set_textbox("T_Message_00", 0xd6);
|
||||
break;
|
||||
}
|
||||
change_button_text_ok();
|
||||
mState = 0xf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GCWindow::on_focus_copy() {
|
||||
if (!is_animation(7)) {
|
||||
do_animation(0xb, false);
|
||||
long error;
|
||||
if (mpMemoryCardManager->isCopyEnable(mCardState, mCardIndex, &error)) {
|
||||
set_textbox("T_Message_00", mCardState == 0 ? 0xf6 : 0xf4);
|
||||
mOperation = 1;
|
||||
mState = 0xb;
|
||||
} else {
|
||||
switch (error) {
|
||||
case -26:
|
||||
set_textbox("T_Message_00", 0xd9);
|
||||
break;
|
||||
case -23:
|
||||
set_textbox("T_Message_00", 0xda + (mCardState == 0));
|
||||
break;
|
||||
case -28:
|
||||
case -22:
|
||||
set_textbox("T_Message_00", 0xdc + (mCardState == 0));
|
||||
break;
|
||||
case -27:
|
||||
set_textbox("T_Message_00", 0xe0);
|
||||
break;
|
||||
case -24:
|
||||
set_textbox("T_Message_00", 0xe1);
|
||||
break;
|
||||
case -25:
|
||||
set_textbox("T_Message_00", 0xe2);
|
||||
break;
|
||||
}
|
||||
change_button_text_ok();
|
||||
mState = 0xf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GCWindow::on_focus_del() {
|
||||
if (!is_animation(10)) {
|
||||
mOperation = 3;
|
||||
do_animation(0xb, false);
|
||||
mState = 0xb;
|
||||
}
|
||||
}
|
||||
|
||||
void GCWindow::on_select_out() {
|
||||
if (!is_animation(0xb)) {
|
||||
System::getDialog()->callS2Btn2(0x142, 0x141, true);
|
||||
get_setting_button()->hideBtn();
|
||||
mState = 0xc;
|
||||
}
|
||||
}
|
||||
|
||||
void GCWindow::on_dialog() {
|
||||
int result = System::getDialog()->getLastResult();
|
||||
long error;
|
||||
if (result != 2) {
|
||||
if (result < 2) {
|
||||
if (result < 1) {
|
||||
return;
|
||||
}
|
||||
} else if (result != 6) {
|
||||
return;
|
||||
}
|
||||
goto cancel_dialog;
|
||||
}
|
||||
{
|
||||
switch (mOperation) {
|
||||
case 1:
|
||||
if (mpMemoryCardManager->isCopyEnable(mCardState, mCardIndex, &error)) {
|
||||
set_visible("N_Wait", true);
|
||||
do_animation(0xf);
|
||||
snd::sSystem.startSE("WIPL_SE_COPYING");
|
||||
mpMemoryCardManager->sendCardCmdCopy(mCardState, mCardIndex);
|
||||
} else {
|
||||
switch (error) {
|
||||
case -26:
|
||||
set_textbox("T_Message_00", 0xd9);
|
||||
break;
|
||||
case -23:
|
||||
set_textbox("T_Message_00", 0xda + (mCardState == 0));
|
||||
break;
|
||||
case -28:
|
||||
case -22:
|
||||
set_textbox("T_Message_00", 0xdc + (mCardState == 0));
|
||||
break;
|
||||
case -27:
|
||||
set_textbox("T_Message_00", 0xe0);
|
||||
break;
|
||||
case -24:
|
||||
set_textbox("T_Message_00", 0xe1);
|
||||
break;
|
||||
case -25:
|
||||
set_textbox("T_Message_00", 0xe2);
|
||||
break;
|
||||
}
|
||||
change_button_text_ok();
|
||||
mState = 0xf;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
set_visible("N_Banner", false);
|
||||
mpMemoryCardManager->sendCardCmdDelete(mCardState, mCardIndex);
|
||||
break;
|
||||
case 2:
|
||||
if (mpMemoryCardManager->isMoveEnable(mCardState, mCardIndex, &error)) {
|
||||
set_visible("N_Banner", false);
|
||||
set_visible("N_Wait", true);
|
||||
do_animation(0xf);
|
||||
snd::sSystem.startSE("WIPL_SE_COPYING");
|
||||
mpMemoryCardManager->sendCardCmdMove(mCardState, mCardIndex);
|
||||
} else {
|
||||
switch (error) {
|
||||
case -26:
|
||||
set_textbox("T_Message_00", 0xcd);
|
||||
break;
|
||||
case -23:
|
||||
set_textbox("T_Message_00", 0xce + (mCardState == 0));
|
||||
break;
|
||||
case -28:
|
||||
case -22:
|
||||
set_textbox("T_Message_00", 0xd0 + (mCardState == 0));
|
||||
break;
|
||||
case -27:
|
||||
set_textbox("T_Message_00", 0xd4);
|
||||
break;
|
||||
case -24:
|
||||
set_textbox("T_Message_00", 0xd5);
|
||||
break;
|
||||
case -25:
|
||||
set_textbox("T_Message_00", 0xd6);
|
||||
break;
|
||||
}
|
||||
change_button_text_ok();
|
||||
mState = 0xf;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ((u32)mOperation - 1 <= 1) {
|
||||
do_animation(0xc);
|
||||
}
|
||||
System::getHomeButtonMenu()->disable();
|
||||
mWaiting = true;
|
||||
mState = 0x11;
|
||||
return;
|
||||
}
|
||||
|
||||
cancel_dialog:
|
||||
do_animation(0xb, true);
|
||||
mState = 2;
|
||||
get_setting_button()->showBtn();
|
||||
}
|
||||
|
||||
void GCWindow::on_error_message() {
|
||||
if (System::getDialog()->getLastResult() >= 0) {
|
||||
destroy();
|
||||
}
|
||||
}
|
||||
|
||||
void GCWindow::on_process() {
|
||||
change_textbox_doing();
|
||||
if (!is_animation(0xc) && !mWaiting) {
|
||||
stop_wait_anim();
|
||||
System::getHomeButtonMenu()->enable();
|
||||
mWaiting = false;
|
||||
do_animation(0xc);
|
||||
mState = 5;
|
||||
}
|
||||
}
|
||||
|
||||
void GCWindow::on_error_message1st() {
|
||||
if (!is_animation(0xb) && get_setting_button()->update()) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
clear_button(scButtonName[i]);
|
||||
}
|
||||
do_animation(0xb, true);
|
||||
mState = 0x10;
|
||||
change_button_text_close();
|
||||
}
|
||||
}
|
||||
|
||||
void GCWindow::on_error_message2nd() {
|
||||
if (!is_animation(0xb) && get_setting_button()->update()) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
clear_button(scButtonName[i]);
|
||||
}
|
||||
do_animation(0xb, true);
|
||||
mState = 0x10;
|
||||
change_button_text_close();
|
||||
}
|
||||
}
|
||||
|
||||
void GCWindow::on_error_message3rd() {
|
||||
if (mFlags1[mCardState] != 0) {
|
||||
goto fadeout;
|
||||
}
|
||||
if (mOperation != 2) {
|
||||
goto check_animation;
|
||||
}
|
||||
|
||||
fadeout:
|
||||
mState = 3;
|
||||
return;
|
||||
|
||||
check_animation:
|
||||
if (!is_animation(0xb)) {
|
||||
mState = 2;
|
||||
}
|
||||
}
|
||||
|
||||
void GCWindow::on_format1st() {
|
||||
int result = System::getDialog()->getLastResult();
|
||||
switch (result) {
|
||||
case 1:
|
||||
case 6:
|
||||
destroy();
|
||||
break;
|
||||
case 2:
|
||||
System::getDialog()->callBtn2(0xee, 0x142, 0x141, true);
|
||||
mState = 0x13;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GCWindow::on_format2nd() {
|
||||
int result = System::getDialog()->getLastResult();
|
||||
switch (result) {
|
||||
case 1:
|
||||
case 6:
|
||||
destroy();
|
||||
break;
|
||||
case 2:
|
||||
mOperation = 4;
|
||||
mpMemoryCardManager->sendCardCmdFormat(mCardState);
|
||||
System::getHomeButtonMenu()->disable();
|
||||
mWaiting = true;
|
||||
mState = 0x14;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GCWindow::on_format3rd() {
|
||||
if (!mWaiting) {
|
||||
System::getDialog()->callBtn0(0xf0, 0xb4, false);
|
||||
mState = 0x15;
|
||||
}
|
||||
}
|
||||
|
||||
void GCWindow::on_format4th() {
|
||||
if (System::getDialog()->getLastResult() >= 0) {
|
||||
destroy();
|
||||
}
|
||||
}
|
||||
|
||||
void GCWindow::on_format_error() {
|
||||
if (System::getDialog()->getLastResult() >= 0) {
|
||||
destroy();
|
||||
}
|
||||
}
|
||||
|
||||
void GCWindow::change_textbox_doing() {
|
||||
switch (mOperation) {
|
||||
case 2:
|
||||
set_textbox("T_Message_00", 0xfa, 0xc, 0x14);
|
||||
break;
|
||||
case 1:
|
||||
set_textbox("T_Message_00", 0xf9, 0xc, 0x14);
|
||||
break;
|
||||
case 3:
|
||||
set_textbox("T_Message_00", 0xfb, 0xc, 0x14);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GCWindow::change_textbox_done() {
|
||||
switch (mOperation) {
|
||||
case 2:
|
||||
set_textbox("T_Message_00", 0x10d, 0xc, 0x14);
|
||||
break;
|
||||
case 1:
|
||||
set_textbox("T_Message_00", 0x107, 0xc, 0x14);
|
||||
break;
|
||||
case 3:
|
||||
set_textbox("T_Message_00", 0xf8, 0xc, 0x14);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GCWindow::set_texture(const char* name, const GXTexObj& texture) {
|
||||
nw4r::lyt::Pane* pane = mpLayout->getNW4RLyt()->GetRootPane()->FindPaneByName(name, true);
|
||||
nw4r::lyt::Material* material = pane->FindMaterialByName(name, true);
|
||||
material->SetTexture(0, texture);
|
||||
}
|
||||
|
||||
void GCWindow::onMemEvent(long event, u8 cardState) {
|
||||
if (event - 1U <= 3) {
|
||||
System::getHomeButtonMenu()->enable();
|
||||
mWaiting = false;
|
||||
} else if (event == 0) {
|
||||
mFlags0[cardState] = 1;
|
||||
} else if (event == 6) {
|
||||
mFlags1[cardState] = 1;
|
||||
mFlags0[cardState] = 0;
|
||||
switch (mState) {
|
||||
case 0xe:
|
||||
case 0xf:
|
||||
if (mCardState == cardState) {
|
||||
set_visible("N_Banner", false);
|
||||
}
|
||||
break;
|
||||
case 0x12:
|
||||
case 0x13:
|
||||
if (mCardState == cardState) {
|
||||
System::getDialog()->terminate();
|
||||
mState = 3;
|
||||
}
|
||||
break;
|
||||
case 0xc:
|
||||
if (mCardState == cardState) {
|
||||
System::getDialog()->terminate();
|
||||
mState = 3;
|
||||
} else if (mState - 1U <= 1) {
|
||||
System::getDialog()->terminate();
|
||||
set_textbox("T_Message_00", 0xda + (mCardState == 0));
|
||||
show_button_ok();
|
||||
mState = 0xe;
|
||||
}
|
||||
break;
|
||||
case 0x14:
|
||||
if (mCardState == cardState) {
|
||||
System::getDialog()->callBtn0(0xf1, 0xb4, false);
|
||||
mState = 0x16;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
case 8:
|
||||
case 9:
|
||||
case 10:
|
||||
if (mCardState == cardState) {
|
||||
mState = 3;
|
||||
}
|
||||
break;
|
||||
case 0x11:
|
||||
switch (mOperation) {
|
||||
case 2:
|
||||
stop_wait_anim();
|
||||
set_textbox("T_Message_00", 0xd7);
|
||||
break;
|
||||
case 1:
|
||||
stop_wait_anim();
|
||||
set_textbox("T_Message_00", 0xe3);
|
||||
break;
|
||||
case 3:
|
||||
if (mCardState != cardState) {
|
||||
return;
|
||||
}
|
||||
set_textbox("T_Message_00", 0xe5);
|
||||
break;
|
||||
}
|
||||
goto process_complete;
|
||||
case 0x15:
|
||||
return;
|
||||
|
||||
process_complete:
|
||||
System::getHomeButtonMenu()->enable();
|
||||
mWaiting = false;
|
||||
show_button_ok();
|
||||
mState = 0xe;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool GCWindow::isProcess() {
|
||||
return mWaiting;
|
||||
}
|
||||
|
||||
void GCWindow::stop_wait_anim() {
|
||||
set_visible("N_Wait", false);
|
||||
MemoryBase::Anm* animation = get_animation(0xf);
|
||||
animation->mAnim->stop();
|
||||
snd::sSystem.startSE("WIPL_SE_COPY_FINISH");
|
||||
}
|
||||
|
||||
SavedataEditWindow::SavedataEditWindow(EGG::Heap* heap, nand::LayoutFile* layoutFile,
|
||||
const char* directory, const char* fileName)
|
||||
: mState(0), mActive(false) {
|
||||
mpLayout = new layout::Object(heap, layoutFile, directory, fileName);
|
||||
add_animation("it_DataDetail_a_SeenIn.brlan", scAnmName[0].groupName);
|
||||
add_animation("it_DataDetail_a_SeenOut.brlan", scAnmName[0].groupName);
|
||||
add_animation("it_DataDetail_a_DelFoucusIn.brlan", scAnmName[8].groupName);
|
||||
add_animation("it_DataDetail_a_DelFoucusOut.brlan", scAnmName[8].groupName);
|
||||
add_animation("it_DataDetail_a_DelFlash.brlan", scAnmName[10].groupName);
|
||||
add_animation("it_DataDetail_a_SelectOut.brlan", scAnmName[11].groupName);
|
||||
add_animation("it_DataDetail_a_SeenOutYes.brlan", scAnmName[0].groupName);
|
||||
add_animation("it_DataDetail_a_SeenOutYesOk.brlan", scAnmName[0].groupName);
|
||||
add_animation("it_DataDetail_a_SeenOutNo.brlan", scAnmName[0].groupName);
|
||||
add_animation("it_DataDetail_a_Wait.brlan", scAnmName[15].groupName);
|
||||
mpLayout->finishBinding();
|
||||
set_visible("N_Wait", false);
|
||||
set_visible("T_Block_01", false);
|
||||
mpEvent = new MemoryBaseEvent(this);
|
||||
mpPaneManager = new gui::PaneManager(mpEvent, mpLayout->getDrawInfo(), NULL, NULL, true);
|
||||
mpPaneManager->setupScene(mpLayout);
|
||||
mpPaneManager->setAllComponentTriggerTarget(false);
|
||||
mpPaneManager->setTriggerTarget(mpLayout->FindPaneByName(scButtonName[2]), true);
|
||||
add_anmbutton(scButtonName[2], get_animation(2), get_animation(3), get_animation(4));
|
||||
set_textbox("T_Del_00", 0xbd);
|
||||
}
|
||||
|
||||
void SavedataEditWindow::calc() {
|
||||
mpLayout->calc();
|
||||
mpPaneManager->calc();
|
||||
void* button = NULL;
|
||||
while ((button = nw4r::ut::List_GetNext(&mAnmButtonList, button)) != NULL) {
|
||||
((MemoryBase::AnmButton*)button)->calc();
|
||||
}
|
||||
switch (mState) {
|
||||
case 0:
|
||||
on_normal();
|
||||
break;
|
||||
case 1:
|
||||
on_fadein();
|
||||
break;
|
||||
case 2:
|
||||
on_fadeout1st();
|
||||
break;
|
||||
case 3:
|
||||
if (!is_animation(1)) {
|
||||
destroy();
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
on_fadeout_yes1st();
|
||||
break;
|
||||
case 5:
|
||||
if (!is_animation(7)) {
|
||||
destroy();
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
if (!is_animation(8)) {
|
||||
destroy();
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
on_focus_del();
|
||||
break;
|
||||
case 8:
|
||||
on_select_out();
|
||||
break;
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
case 12:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void SavedataEditWindow::on_normal() {
|
||||
if (mActive) {
|
||||
if (get_setting_button()->update()) {
|
||||
change_button_text_return();
|
||||
mState = 2;
|
||||
} else {
|
||||
mpPaneManager->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SavedataEditWindow::on_fadein() {
|
||||
mLinearInterp.calc();
|
||||
mpLayout->getNW4RLyt()->GetRootPane()->FindPaneByName("N_Window", true)->SetTranslate(mLinearInterp.get());
|
||||
if (!is_animation(0)) {
|
||||
mState = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void SavedataEditWindow::on_fadeout1st() {
|
||||
if (!get_setting_button()->isPlaying()) {
|
||||
math::VEC3 zero(0.0f, 0.0f, 0.0f);
|
||||
mLinearInterp.init(ANIM_TYPE_FORWARD, 20.0f, 0.0f, mTranslate, zero);
|
||||
mLinearInterp.setAnmType(ANIM_TYPE_BACKWARD);
|
||||
mLinearInterp.initFrame();
|
||||
mLinearInterp.restart();
|
||||
do_animation(1);
|
||||
mState = 3;
|
||||
}
|
||||
}
|
||||
|
||||
void SavedataEditWindow::on_focus_del() {
|
||||
if (!is_animation(4)) {
|
||||
do_animation(5, false);
|
||||
mState = 8;
|
||||
}
|
||||
}
|
||||
|
||||
void SavedataEditWindow::on_select_out() {
|
||||
if (!is_animation(5)) {
|
||||
System::getDialog()->callS2Btn2(0x142, 0x141, true);
|
||||
get_setting_button()->hideBtn();
|
||||
mState = 9;
|
||||
}
|
||||
}
|
||||
|
||||
void SavedataEditWindow::on_fadeout_yes1st() {
|
||||
set_textbox("T_Message_00", 0xf8, 6, 0x14);
|
||||
if (!is_animation(6)) {
|
||||
math::VEC3 zero(0.0f, 0.0f, 0.0f);
|
||||
mLinearInterp.init(ANIM_TYPE_FORWARD, 20.0f, 0.0f, mTranslate, zero);
|
||||
mLinearInterp.setAnmType(ANIM_TYPE_BACKWARD);
|
||||
mLinearInterp.initFrame();
|
||||
mLinearInterp.restart();
|
||||
get_setting_button()->setText(0x13b);
|
||||
get_setting_button()->showBtn();
|
||||
do_animation(7);
|
||||
mState = 5;
|
||||
}
|
||||
}
|
||||
|
||||
GCWindow::~GCWindow() {}
|
||||
|
||||
}
|
||||
}
|
||||
706
src/scene/memoryCard/iplMemoryCard.cpp
Normal file
706
src/scene/memoryCard/iplMemoryCard.cpp
Normal file
@@ -0,0 +1,706 @@
|
||||
#define IPL_MEMORY_CARD_CPP
|
||||
#define IPL_MEMORYCARD_BASE_OUT_OF_LINE
|
||||
#define IPL_CHANNEL_TITLE_NOVTABLE
|
||||
#include "scene/memoryCard/iplMemoryCard.h"
|
||||
#undef IPL_CHANNEL_TITLE_NOVTABLE
|
||||
|
||||
#include "scene/memoryCard/iplGCWindow.h"
|
||||
#include "scene/memoryCard/iplGCSaveData.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <cwchar>
|
||||
|
||||
#include "iplSystem.h"
|
||||
#include "scene/iplSceneCreator.h"
|
||||
#include "scene/settingSelect/iplSettingButton.h"
|
||||
#include "scene/settingSelect/iplSettingSelect.h"
|
||||
#include "scene/textBalloon/iplBalloon.h"
|
||||
#include "private/card.h"
|
||||
#include "sound/iplSound.h"
|
||||
#include "system/iplController.h"
|
||||
#include "system/iplNandManager.h"
|
||||
#include "utility/iplGraphics.h"
|
||||
|
||||
namespace ipl {
|
||||
namespace scene {
|
||||
static const char* scSavedataPaneName[] = {
|
||||
"N_Data_a_00", "N_Data_a_01", "N_Data_a_02", "N_Data_a_03", "N_Data_a_04",
|
||||
"N_Data_a_05", "N_Data_a_06", "N_Data_a_07", "N_Data_a_08", "N_Data_a_09",
|
||||
"N_Data_a_10", "N_Data_a_11", "N_Data_a_12", "N_Data_a_13", "N_Data_a_14",
|
||||
"N_Data_b_00", "N_Data_b_01", "N_Data_b_02", "N_Data_b_03", "N_Data_b_04",
|
||||
"N_Data_b_05", "N_Data_b_06", "N_Data_b_07", "N_Data_b_08", "N_Data_b_09",
|
||||
"N_Data_b_10", "N_Data_b_11", "N_Data_b_12", "N_Data_b_13", "N_Data_b_14",
|
||||
"N_Data_c_00", "N_Data_c_01", "N_Data_c_02", "N_Data_c_03", "N_Data_c_04",
|
||||
"N_Data_c_05", "N_Data_c_06", "N_Data_c_07", "N_Data_c_08", "N_Data_c_09",
|
||||
"N_Data_c_10", "N_Data_c_11", "N_Data_c_12", "N_Data_c_13", "N_Data_c_14",
|
||||
};
|
||||
|
||||
static const MemoryBase::AnmName scAnmName[] = {
|
||||
{"it_ObjCubeEdit_a_CubeSwitch.brlan", "G_Switch"},
|
||||
{"it_ObjCubeEdit_a_DataIn.brlan", "G_DataAll"},
|
||||
{"it_ObjCubeEdit_a_SelectIn.brlan", "G_SelectWii"},
|
||||
{"it_ObjCubeEdit_a_SelectIn.brlan", "G_SelectSd"},
|
||||
{"it_ObjCubeEdit_a_DataOut.brlan", "G_DataAll"},
|
||||
{"it_ObjCubeEdit_a_SelectIn.brlan", "G_Select"},
|
||||
{"it_ObjCubeEdit_a_SelectWiiFoucusIn.brlan", "G_SelectWii"},
|
||||
{"it_ObjCubeEdit_a_SelectWiiFoucusOut.brlan", "G_SelectWii"},
|
||||
{"it_ObjCubeEdit_a_SelectWiiFlash.brlan", "G_Select"},
|
||||
{"it_ObjCubeEdit_a_SelectSdIn.brlan", "G_SelectSd"},
|
||||
{"it_ObjCubeEdit_a_SelectSdOut.brlan", "G_SelectSd"},
|
||||
{"it_ObjCubeEdit_a_SelectSdFlash.brlan", "G_Select"},
|
||||
{"it_ObjCubeEdit_a_ArwL1.brlan", "G_Arw"},
|
||||
{"it_ObjCubeEdit_a_AwrR1.brlan", "G_Arw"},
|
||||
{"it_ObjCubeEdit_a_Select.brlan", "G_ArwR_Ac"},
|
||||
{"it_ObjCubeEdit_a_Select.brlan", "G_ArwL_Ac"},
|
||||
{"it_ObjCubeEdit_a_FocusOn.brlan", "G_ArwR_Focus"},
|
||||
{"it_ObjCubeEdit_a_FocusOn.brlan", "G_ArwL_Focus"},
|
||||
{"it_ObjCubeEdit_a_FocusOff.brlan", "G_ArwR_Focus"},
|
||||
{"it_ObjCubeEdit_a_FocusOff.brlan", "G_ArwL_Focus"},
|
||||
{"it_ObjCubeEdit_a_Loop.brlan", "G_ArwRoop"},
|
||||
{"it_ObjCubeEdit_a_Appear.brlan", "G_ArwR_End"},
|
||||
{"it_ObjCubeEdit_a_Appear.brlan", "G_ArwL_End"},
|
||||
{"it_ObjCubeEdit_a_Lost.brlan", "G_ArwR_End"},
|
||||
{"it_ObjCubeEdit_a_Lost.brlan", "G_ArwL_End"},
|
||||
{"it_ObjCubeEdit_a_ErrorTxtIn.brlan", "G_ErrorTxt"},
|
||||
{"it_ObjCubeEdit_a_ErrorTxtOut.brlan", "G_ErrorTxt"},
|
||||
};
|
||||
|
||||
struct TextboxMessage {
|
||||
const char* paneName;
|
||||
u32 messageId;
|
||||
};
|
||||
|
||||
static const TextboxMessage scTextboxToMessageID[] = {
|
||||
{"T_SelectWii_00", 0x13F},
|
||||
{"T_SelectWii_01", 0x13F},
|
||||
{"T_SelectSd_00", 0x140},
|
||||
{"T_SelectSd_01", 0x140},
|
||||
{"T_Error_00", 0xE6},
|
||||
};
|
||||
|
||||
static const char* scTriggerPaneName[] = {
|
||||
"B_ArwR", "B_ArwL", "B_SelectWii_00", "B_SelectSd_00",
|
||||
};
|
||||
|
||||
MemoryCard::MemoryCard(EGG::Heap* heap)
|
||||
: Base(heap), MemoryBase(), mState(2), mPrevState(2), mSlot(0), mIconIndex(-15), mIconCount(0),
|
||||
mShowArwR(0), mShowArwL(0), mpEvent(NULL), mpFocusSaveData(NULL) {
|
||||
System::getMem2App()->dump();
|
||||
nw4r::ut::List_Init(&mSaveDataList, offsetof(GCSaveData, mLink));
|
||||
nw4r::ut::List_Init(&mBalloonList, 0);
|
||||
}
|
||||
|
||||
MemoryBase::~MemoryBase() {}
|
||||
|
||||
void MemoryCard::prepare() {
|
||||
System::getBS2Manager()->abort();
|
||||
unk_0x08 = System::getNandManager()->readLayoutAsync(getSceneHeap(), "gcMem.ash");
|
||||
mBalloonLayoutFile = System::getNandManager()->readLayoutAsync(getSceneHeap(), "balloon.ash");
|
||||
}
|
||||
|
||||
void MemoryCard::create() {
|
||||
u32 start = OSGetTick();
|
||||
while (System::getBS2Manager()->getIPLState() != 8) {
|
||||
System::getBS2Manager()->update();
|
||||
OSReport(" ... wait for bs2 abord\n");
|
||||
VIWaitForRetrace();
|
||||
}
|
||||
u32 end = OSGetTick();
|
||||
OSReport("*** BS2 abort costs: %dms\n", OSTicksToMilliseconds(end - start));
|
||||
ES_SetUid((u64(1) << 32) | 2);
|
||||
|
||||
mpLayout = new layout::Object(getSceneHeap(), unk_0x08, "arc", "it_ObjCubeEdit_a.brlyt");
|
||||
add_animation(scAnmName, 0x1B);
|
||||
get_animation(7)->mAnim->setAnmType(1);
|
||||
get_animation(10)->mAnim->setAnmType(1);
|
||||
mpLayout->finishBinding();
|
||||
do_animation(0);
|
||||
do_animation(1);
|
||||
do_animation(0x14);
|
||||
do_animation(0x17);
|
||||
do_animation(0x18);
|
||||
mPrevState = mState;
|
||||
mState = 0;
|
||||
mpLayout->FindPaneByName("N_ArwR")->SetVisible(false);
|
||||
mpLayout->FindPaneByName("N_ArwL")->SetVisible(false);
|
||||
|
||||
mpEvent = new MemoryBaseEvent(this);
|
||||
mpPaneManager = new gui::PaneManager(mpEvent, mpLayout->getDrawInfo(), NULL, NULL, true);
|
||||
mpPaneManager->setupScene(mpLayout);
|
||||
mpPaneManager->setAllComponentTriggerTarget(false);
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
nw4r::lyt::Pane* pane = mpLayout->FindPaneByName(scTriggerPaneName[i]);
|
||||
mpPaneManager->setTriggerTarget(pane, true);
|
||||
}
|
||||
|
||||
add_anmbutton(scTriggerPaneName[2], get_animation(6), get_animation(7), get_animation(8));
|
||||
add_anmbutton(scTriggerPaneName[3], get_animation(9), get_animation(10), get_animation(11));
|
||||
add_anmbutton(scTriggerPaneName[0], get_animation(16), get_animation(18), get_animation(12));
|
||||
add_anmbutton(scTriggerPaneName[1], get_animation(17), get_animation(19), get_animation(13));
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
set_textbox(scTextboxToMessageID[i].paneName, scTextboxToMessageID[i].messageId);
|
||||
}
|
||||
|
||||
mpGCWindow = new GCWindow(getSceneHeap(), unk_0x08, "arc", "it_CubeDetail_a.brlyt");
|
||||
mpGCWindow->do_animation(0);
|
||||
|
||||
MemoryCardManager* manager = new MemoryCardManager();
|
||||
mpManager = manager;
|
||||
mpManager->setEventHandler(mpGCWindow);
|
||||
mpGCWindow->mpMemoryCardManager = mpManager;
|
||||
|
||||
for (int i = 0; i < 0x2D; i++) {
|
||||
nw4r::lyt::Pane* pane = mpLayout->FindPaneByName(scSavedataPaneName[i]);
|
||||
nw4r::math::VEC3 position(0.0f, 0.0f, 0.0f);
|
||||
PSMTXMultVec(pane->GetGlobalMtx(), reinterpret_cast<const Vec*>(&position), reinterpret_cast<Vec*>(&position));
|
||||
GCSaveData* saveData =
|
||||
new GCSaveData(getSceneHeap(), unk_0x08, "arc", "it_ObjCubeEdit_b.brlyt", position);
|
||||
saveData->set_visible("N_Data_00", false);
|
||||
nw4r::ut::List_Append(&mSaveDataList, saveData);
|
||||
if (i >= 0xF && i < 0x1E) {
|
||||
position.y -= 55.0f;
|
||||
TextBalloon* balloon =
|
||||
new TextBalloon(getSceneHeap(), mBalloonLayoutFile, "arc", "my_IplTopBalloon_a.brlyt",
|
||||
math::VEC3(position), 90.0f, 60.0f);
|
||||
nw4r::ut::List_Append(&mBalloonList, balloon);
|
||||
saveData->setBalloon(balloon);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 2; i++) {
|
||||
mSlotState[i] = 0;
|
||||
}
|
||||
set_visible("N_Capa_00", false);
|
||||
set_visible("T_Error_00", false);
|
||||
}
|
||||
|
||||
void MemoryCard::calc() {
|
||||
mpManager->calc();
|
||||
if (is_fadein_enable()) {
|
||||
mpLayout->calc();
|
||||
mpPaneManager->calc();
|
||||
s16 index = mIconIndex;
|
||||
mIconCount = 0;
|
||||
GCSaveData* saveData = NULL;
|
||||
while ((saveData = static_cast<GCSaveData*>(nw4r::ut::List_GetNext(&mSaveDataList, saveData))) != NULL) {
|
||||
if (mpManager->isIconValidate(mSlot, index) || index < 0) {
|
||||
mIconCount++;
|
||||
}
|
||||
saveData->mSlot = mSlot;
|
||||
saveData->mIndex = index;
|
||||
saveData->calc();
|
||||
index++;
|
||||
}
|
||||
MemoryBase::AnmButton* button = NULL;
|
||||
while ((button = static_cast<MemoryBase::AnmButton*>(nw4r::ut::List_GetNext(&mAnmButtonList, button))) != NULL) {
|
||||
button->calc();
|
||||
}
|
||||
TextBalloon* balloon = NULL;
|
||||
while ((balloon = static_cast<TextBalloon*>(nw4r::ut::List_GetNext(&mBalloonList, balloon))) != NULL) {
|
||||
balloon->calc();
|
||||
}
|
||||
switch (mState) {
|
||||
case 0:
|
||||
on_fadein1st();
|
||||
break;
|
||||
case 1:
|
||||
on_fadein2nd();
|
||||
break;
|
||||
case 2:
|
||||
on_normal();
|
||||
break;
|
||||
case 3:
|
||||
on_scroll_r();
|
||||
break;
|
||||
case 4:
|
||||
on_scroll_l();
|
||||
break;
|
||||
case 5:
|
||||
on_change_tag1st();
|
||||
break;
|
||||
case 6:
|
||||
on_change_tag2nd();
|
||||
break;
|
||||
case 7:
|
||||
on_fadeout1st();
|
||||
break;
|
||||
case 8:
|
||||
on_fadeout2nd();
|
||||
break;
|
||||
case 9:
|
||||
mpGCWindow->calc();
|
||||
show_capacity(mSlot);
|
||||
break;
|
||||
case 10:
|
||||
on_error();
|
||||
break;
|
||||
case 11:
|
||||
on_insert_card();
|
||||
break;
|
||||
case 12:
|
||||
on_detach_card();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryCard::on_fadein1st() {
|
||||
if (!is_animation(1)) {
|
||||
do_animation(5);
|
||||
mpLayout->FindPaneByName("N_ArwR")->SetVisible(true);
|
||||
mpLayout->FindPaneByName("N_ArwL")->SetVisible(true);
|
||||
if (mpManager->isSlotReady(mSlot)) {
|
||||
mSlotState[mSlot] = 1;
|
||||
start_savedata_fadein();
|
||||
mPrevState = mState;
|
||||
mState = 1;
|
||||
} else {
|
||||
start_errormessage_fadein();
|
||||
mPrevState = mState;
|
||||
mState = 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryCard::on_fadein2nd() {
|
||||
GCSaveData* saveData = static_cast<GCSaveData*>(nw4r::ut::List_GetNext(&mSaveDataList, NULL));
|
||||
if (!is_animation(5) && !saveData->is_animation(0)) {
|
||||
mPrevState = mState;
|
||||
mState = 2;
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryCard::on_normal() {
|
||||
if (get_setting_button()->update()) {
|
||||
if (mPrevState == 10) {
|
||||
do_animation(0x1A);
|
||||
}
|
||||
mPrevState = mState;
|
||||
mState = 7;
|
||||
return;
|
||||
}
|
||||
show_arw();
|
||||
show_capacity(mSlot);
|
||||
if (!update_slot()) {
|
||||
mpPaneManager->update();
|
||||
GCSaveData* saveData = NULL;
|
||||
while ((saveData = static_cast<GCSaveData*>(nw4r::ut::List_GetNext(&mSaveDataList, saveData))) != NULL) {
|
||||
saveData->update();
|
||||
}
|
||||
mpGCWindow->calc();
|
||||
if (mIconCount <= 15) {
|
||||
bool canScroll = false;
|
||||
if (mIconIndex >= 0 && mState == 2) {
|
||||
canScroll = true;
|
||||
}
|
||||
if (canScroll) {
|
||||
start_scroll_l();
|
||||
return;
|
||||
}
|
||||
}
|
||||
controller::Interface* controller = System::getYoungController();
|
||||
if (controller != NULL) {
|
||||
if (controller->down(0x30001000)) {
|
||||
start_scroll_l();
|
||||
} else if (controller->down(0x06000010)) {
|
||||
start_scroll_r();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryCard::on_scroll_r() {
|
||||
if (!is_animation(0xC)) {
|
||||
get_animation(0xC)->mAnim->initAnmFrame();
|
||||
mpLayout->calc();
|
||||
mState = 2;
|
||||
mIconIndex += 0xF;
|
||||
}
|
||||
scroll_common();
|
||||
}
|
||||
|
||||
void MemoryCard::on_scroll_l() {
|
||||
if (!is_animation(0xD)) {
|
||||
get_animation(0xC)->mAnim->initAnmFrame();
|
||||
mpLayout->calc();
|
||||
mState = 2;
|
||||
mIconIndex -= 0xF;
|
||||
}
|
||||
scroll_common();
|
||||
}
|
||||
|
||||
void MemoryCard::on_change_tag1st() {
|
||||
GCSaveData* first = static_cast<GCSaveData*>(nw4r::ut::List_GetNext(&mSaveDataList, NULL));
|
||||
if (!first->is_animation(1)) {
|
||||
GCSaveData* saveData = NULL;
|
||||
while ((saveData = static_cast<GCSaveData*>(nw4r::ut::List_GetNext(&mSaveDataList, saveData))) != NULL) {
|
||||
saveData->set_visible("N_Data_00", false);
|
||||
}
|
||||
mSlot ^= 1;
|
||||
mSlotState[mSlot] = 0;
|
||||
mIconIndex = -15;
|
||||
mPrevState = mState;
|
||||
mState = 2;
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryCard::on_change_tag2nd() {
|
||||
GCSaveData* saveData = NULL;
|
||||
while ((saveData = static_cast<GCSaveData*>(nw4r::ut::List_GetNext(&mSaveDataList, saveData))) != NULL) {
|
||||
if (!saveData->is_animation(0)) {
|
||||
mState = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryCard::on_fadeout1st() {
|
||||
if (!get_setting_button()->isPlaying()) {
|
||||
do_animation(4);
|
||||
GCSaveData* saveData = NULL;
|
||||
while ((saveData = static_cast<GCSaveData*>(nw4r::ut::List_GetNext(&mSaveDataList, saveData))) != NULL) {
|
||||
saveData->do_animation(1);
|
||||
}
|
||||
mState = 8;
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryCard::on_fadeout2nd() {
|
||||
if (!is_animation(4)) {
|
||||
bool shutdown = memorycard::shutdownCardThread();
|
||||
if (shutdown) {
|
||||
requestSceneDestruction();
|
||||
System::getBS2Manager()->restart();
|
||||
OSReport(" ... bs2 manager restarted\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryCard::on_error() {
|
||||
if (!is_animation(0x19)) {
|
||||
mPrevState = mState;
|
||||
mState = 2;
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryCard::on_insert_card() {
|
||||
if (!is_animation(0x1A)) {
|
||||
start_savedata_fadein();
|
||||
mPrevState = mState;
|
||||
mState = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryCard::on_detach_card() {
|
||||
GCSaveData* first = static_cast<GCSaveData*>(nw4r::ut::List_GetNext(&mSaveDataList, NULL));
|
||||
if (!first->is_animation(1)) {
|
||||
start_errormessage_fadein();
|
||||
mPrevState = mState;
|
||||
mState = 10;
|
||||
GCSaveData* saveData = NULL;
|
||||
while ((saveData = static_cast<GCSaveData*>(nw4r::ut::List_GetNext(&mSaveDataList, saveData))) != NULL) {
|
||||
saveData->set_visible("N_Data_00", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryCard::start_savedata_fadein() {
|
||||
GCSaveData* saveData = NULL;
|
||||
while ((saveData = static_cast<GCSaveData*>(nw4r::ut::List_GetNext(&mSaveDataList, saveData))) != NULL) {
|
||||
saveData->set_visible("N_Data_00", true);
|
||||
saveData->do_animation(0);
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryCard::start_savedata_fadeout() {
|
||||
GCSaveData* saveData = NULL;
|
||||
while ((saveData = static_cast<GCSaveData*>(nw4r::ut::List_GetNext(&mSaveDataList, saveData))) != NULL) {
|
||||
saveData->do_animation(1);
|
||||
}
|
||||
set_visible("N_Capa_00", false);
|
||||
}
|
||||
|
||||
void MemoryCard::start_errormessage_fadein() {
|
||||
if (mpManager->isSlotWrongDevice(mSlot) != 0) {
|
||||
mSlotState[mSlot] = 3;
|
||||
set_textbox("T_Error_00", mSlot == 0 ? 0xE8 : 0xE9);
|
||||
} else {
|
||||
mSlotState[mSlot] = 2;
|
||||
set_textbox("T_Error_00", mSlot == 0 ? 0xE6 : 0xE7);
|
||||
}
|
||||
set_visible("T_Error_00", true);
|
||||
do_animation(0x19);
|
||||
}
|
||||
|
||||
int MemoryCard::update_slot() {
|
||||
if (mSlotState[mSlot] != 1 && mpManager->isSlotReady(mSlot) != 0) {
|
||||
for (u16 i = 0xF; i < 0x1E; i++) {
|
||||
static_cast<GCSaveData*>(nw4r::ut::List_GetNth(&mSaveDataList, i))->init();
|
||||
}
|
||||
mSlotState[mSlot] = 1;
|
||||
if (mPrevState == 10) {
|
||||
do_animation(0x1A);
|
||||
}
|
||||
mPrevState = mState;
|
||||
mState = 0xB;
|
||||
return true;
|
||||
}
|
||||
if (mSlotState[mSlot] != 2 && mpManager->isSlotNoCard(mSlot) != 0) {
|
||||
for (u16 i = 0xF; i < 0x1E; i++) {
|
||||
static_cast<GCSaveData*>(nw4r::ut::List_GetNth(&mSaveDataList, i))->init();
|
||||
}
|
||||
mSlotState[mSlot] = 2;
|
||||
mIconIndex = -15;
|
||||
start_savedata_fadeout();
|
||||
mPrevState = mState;
|
||||
mState = 0xC;
|
||||
return true;
|
||||
}
|
||||
if ((mSlotState[mSlot] != 3 && mpManager->isSlotWrongDevice(mSlot) != 0) || mSlotState[mSlot] == 0) {
|
||||
for (u16 i = 0xF; i < 0x1E; i++) {
|
||||
static_cast<GCSaveData*>(nw4r::ut::List_GetNth(&mSaveDataList, i))->init();
|
||||
}
|
||||
mSlotState[mSlot] = 3;
|
||||
start_savedata_fadeout();
|
||||
mPrevState = mState;
|
||||
mState = 0xC;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void MemoryCard::show_arw() {
|
||||
if (mShowArwR == 0 && can_scroll_r()) {
|
||||
do_animation(0x15);
|
||||
do_animation(0x12);
|
||||
mShowArwR = 1;
|
||||
} else if (mShowArwR != 0 && !can_scroll_r()) {
|
||||
do_animation(0x17);
|
||||
mShowArwR = 0;
|
||||
}
|
||||
if (mShowArwL == 0 && can_scroll_l()) {
|
||||
do_animation(0x16);
|
||||
do_animation(0x13);
|
||||
mShowArwL = 1;
|
||||
} else if (mShowArwL != 0 && !can_scroll_l()) {
|
||||
do_animation(0x18);
|
||||
mShowArwL = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryCard::show_capacity(u8 slot) {
|
||||
if (!mpManager->isSlotReady(slot)) {
|
||||
set_visible("N_Capa_00", false);
|
||||
return;
|
||||
}
|
||||
u32 freeBlocks = mpManager->getFreeBlocks(slot);
|
||||
wchar_t digits[5];
|
||||
wchar_t digitTable[10] = {L'0', L'1', L'2', L'3', L'4', L'5', L'6', L'7', L'8', L'9'};
|
||||
digits[0] = L'\0';
|
||||
digits[1] = L'\0';
|
||||
digits[2] = L'\0';
|
||||
digits[3] = L'\0';
|
||||
digits[4] = L'\0';
|
||||
wchar_t text[0x40] = L"";
|
||||
int blocks = static_cast<u16>(freeBlocks);
|
||||
digits[0] = digitTable[blocks / 1000];
|
||||
digits[1] = digitTable[blocks / 100 % 10];
|
||||
digits[2] = digitTable[blocks / 10 % 10];
|
||||
digits[3] = digitTable[blocks % 10];
|
||||
|
||||
int zeroOffset;
|
||||
for (zeroOffset = 0; zeroOffset < 3; zeroOffset++) {
|
||||
if (digits[zeroOffset] != L'0') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int blockOpenOffset = 0;
|
||||
const wchar_t* blockOpenMessage = System::getMessage(0x9C);
|
||||
const wchar_t* blankMessage = System::getMessage(0xF2);
|
||||
|
||||
while (true) {
|
||||
wchar_t chr = *blockOpenMessage++;
|
||||
text[blockOpenOffset++] = chr;
|
||||
if (chr == L'\0') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
text[--blockOpenOffset] = L' ';
|
||||
wcscpy(text + blockOpenOffset, digits + zeroOffset);
|
||||
wcscat(text, blankMessage);
|
||||
|
||||
set_textbox("T_Capa_00", text);
|
||||
set_visible("N_Capa_00", true);
|
||||
}
|
||||
|
||||
void MemoryCard::scroll_common() {
|
||||
for (u16 i = 0; i < 0x2D; i++) {
|
||||
nw4r::lyt::Pane* pane = mpLayout->FindPaneByName(scSavedataPaneName[i]);
|
||||
GCSaveData* saveData = static_cast<GCSaveData*>(nw4r::ut::List_GetNth(&mSaveDataList, i));
|
||||
nw4r::math::VEC3 position(0.0f, 0.0f, 0.0f);
|
||||
PSMTXMultVec(pane->GetGlobalMtx(), reinterpret_cast<const Vec*>(&position), reinterpret_cast<Vec*>(&position));
|
||||
saveData->setTranslate(position);
|
||||
saveData->init();
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryCard::start_scroll_r() {
|
||||
bool canScroll = false;
|
||||
if (mIconCount > 0x1E && mState == 2) {
|
||||
canScroll = true;
|
||||
}
|
||||
if (canScroll) {
|
||||
do_animation(0xC);
|
||||
mState = 3;
|
||||
snd::getSystem()->startSE("WSD_SELECT");
|
||||
GCSaveData* saveData = NULL;
|
||||
while ((saveData = static_cast<GCSaveData*>(nw4r::ut::List_GetNext(&mSaveDataList, saveData))) != NULL) {
|
||||
saveData->init();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryCard::start_scroll_l() {
|
||||
bool canScroll = false;
|
||||
if (mIconIndex >= 0 && mState == 2) {
|
||||
canScroll = true;
|
||||
}
|
||||
if (canScroll) {
|
||||
do_animation(0xD);
|
||||
mState = 4;
|
||||
snd::getSystem()->startSE("WSD_SELECT");
|
||||
GCSaveData* saveData = NULL;
|
||||
while ((saveData = static_cast<GCSaveData*>(nw4r::ut::List_GetNext(&mSaveDataList, saveData))) != NULL) {
|
||||
saveData->init();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryCard::draw() {
|
||||
if (System::onDefaultDrawLayer()) {
|
||||
utility::Graphics::setOrtho(0);
|
||||
mpLayout->draw();
|
||||
GCSaveData* saveData = NULL;
|
||||
while ((saveData = static_cast<GCSaveData*>(nw4r::ut::List_GetNext(&mSaveDataList, saveData))) != NULL) {
|
||||
saveData->draw();
|
||||
}
|
||||
mpLayout->draw("N_ArwR");
|
||||
mpLayout->draw("N_ArwL");
|
||||
if (mpFocusSaveData != NULL) {
|
||||
mpGCWindow->draw();
|
||||
}
|
||||
if (mState == 2) {
|
||||
TextBalloon* balloon = NULL;
|
||||
while ((balloon = static_cast<TextBalloon*>(nw4r::ut::List_GetNext(&mBalloonList, balloon))) != NULL) {
|
||||
balloon->draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryCard::onPoint(const char* paneName, controller::Interface* controller) {
|
||||
MemoryBase::AnmButton* button = get_anmbutton(paneName);
|
||||
if (button != NULL) {
|
||||
if (button->unk_0x04 == 0 &&
|
||||
(strcmp(paneName, scTriggerPaneName[2]) != 0 || mSlot != 0) &&
|
||||
(strcmp(paneName, scTriggerPaneName[3]) != 0 || mSlot != 1)) {
|
||||
button->onCmdRecv(1);
|
||||
snd::getSystem()->startSE("WIPL_SE_BT_TARGETTING");
|
||||
if (controller != NULL) {
|
||||
controller->rumble(0);
|
||||
}
|
||||
}
|
||||
button->unk_0x04++;
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryCard::onLeft(const char* paneName) {
|
||||
MemoryBase::AnmButton* button = get_anmbutton(paneName);
|
||||
if (button != NULL) {
|
||||
if (button->unk_0x04 == 1 &&
|
||||
(strcmp(paneName, scTriggerPaneName[2]) != 0 || mSlot != 0) &&
|
||||
(strcmp(paneName, scTriggerPaneName[3]) != 0 || mSlot != 1)) {
|
||||
button->onCmdRecv(2);
|
||||
}
|
||||
button->unk_0x04--;
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryCard::onTrig(const char* paneName) {
|
||||
if (mpFocusSaveData == NULL && get_anmbutton(paneName) != NULL) {
|
||||
if (strcmp(paneName, scTriggerPaneName[0]) == 0) {
|
||||
do_animation(0xE);
|
||||
start_scroll_r();
|
||||
} else if (strcmp(paneName, scTriggerPaneName[1]) == 0) {
|
||||
do_animation(0xF);
|
||||
start_scroll_l();
|
||||
} else if (strcmp(paneName, scTriggerPaneName[2]) == 0) {
|
||||
if (mSlot == 1) {
|
||||
do_animation(0xB);
|
||||
GCSaveData* saveData = NULL;
|
||||
while ((saveData = static_cast<GCSaveData*>(nw4r::ut::List_GetNext(&mSaveDataList, saveData))) != NULL) {
|
||||
saveData->do_animation(1);
|
||||
}
|
||||
if (mPrevState == 10) {
|
||||
do_animation(0x1A);
|
||||
}
|
||||
snd::getSystem()->startSE("WIPL_SE_BT_PUSH");
|
||||
mState = 5;
|
||||
}
|
||||
} else if (strcmp(paneName, scTriggerPaneName[3]) == 0) {
|
||||
if (mSlot == 0) {
|
||||
do_animation(8);
|
||||
GCSaveData* saveData = NULL;
|
||||
while ((saveData = static_cast<GCSaveData*>(nw4r::ut::List_GetNext(&mSaveDataList, saveData))) != NULL) {
|
||||
saveData->do_animation(1);
|
||||
}
|
||||
if (mPrevState == 10) {
|
||||
do_animation(0x1A);
|
||||
}
|
||||
snd::getSystem()->startSE("WIPL_SE_BT_PUSH");
|
||||
mState = 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryCard::onFocus(void* data) {
|
||||
if (mState == 2) {
|
||||
if (data != NULL) {
|
||||
snd::getSystem()->startSE("WIPL_SE_DECIDE");
|
||||
GCSaveData* saveData = static_cast<GCSaveData*>(data);
|
||||
mpFocusSaveData = saveData;
|
||||
mpGCWindow->init(math::VEC3(*saveData->getTranslate()), mpManager,
|
||||
saveData->mSlot,
|
||||
saveData->mIndex);
|
||||
change_button_text_close();
|
||||
}
|
||||
mState = 9;
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryCard::onRelease() {
|
||||
if (mpFocusSaveData != NULL) {
|
||||
TextBalloon* balloon = mpFocusSaveData->mpBalloon;
|
||||
if (balloon != NULL) {
|
||||
balloon->terminate();
|
||||
}
|
||||
}
|
||||
mpFocusSaveData = NULL;
|
||||
mState = 2;
|
||||
}
|
||||
|
||||
BOOL MemoryCard::isResetAcceptable() const {
|
||||
return !mpGCWindow->isProcess();
|
||||
}
|
||||
|
||||
void MemoryBase::onMove(const char*) {}
|
||||
|
||||
MemoryCardManager::~MemoryCardManager() {}
|
||||
|
||||
MemoryCard::~MemoryCard() {}
|
||||
|
||||
}
|
||||
}
|
||||
804
src/scene/sdChannelSelect/iplSDChannelObj.cpp
Normal file
804
src/scene/sdChannelSelect/iplSDChannelObj.cpp
Normal file
@@ -0,0 +1,804 @@
|
||||
#define IPL_SD_CHANNEL_OBJ_CPP
|
||||
#include "scene/sdChannelSelect/iplSDChannelSelect.h"
|
||||
|
||||
#include "iplSound.h"
|
||||
#include "iplSystem.h"
|
||||
#include <private/es.h>
|
||||
#include <revolution/sc.h>
|
||||
|
||||
namespace ipl {
|
||||
namespace scene {
|
||||
static const wchar_t scUnknownName[] = L"???";
|
||||
static const char* scCursur = "Cursur_a";
|
||||
static const char* scCursorAnims[] = {
|
||||
"my_IplTop_d_FocusOff.brlan",
|
||||
"my_IplTop_d_FocusOn.brlan",
|
||||
"my_IplTop_d_Select.brlan",
|
||||
};
|
||||
static const char* scBalloon = "T_Balloon";
|
||||
static const char* scBase = "W_Base";
|
||||
static const char* scShade = "W_Shade";
|
||||
static const char* scLangGroups[] = {"JPN", "ENG", "GER", "FRA", "SPA", "ITA", "NED", "CHN", "ENG", "KOR"};
|
||||
static const char* scRegionGroups[SC_PRODUCT_AREA_MAX][16] = {
|
||||
{"JPN"},
|
||||
{"ENG", "FRA", "SPA"},
|
||||
{"ENG", "FRA", "GER", "SPA", "ITA", "NED"},
|
||||
{NULL},
|
||||
{NULL},
|
||||
{NULL},
|
||||
{"KOR"},
|
||||
{NULL},
|
||||
{NULL},
|
||||
{NULL},
|
||||
{NULL},
|
||||
{"CHN"},
|
||||
};
|
||||
static const u32 scLangLookup[SC_PRODUCT_AREA_MAX][16] = {
|
||||
{SC_LANG_JAPANESE, -1},
|
||||
{SC_LANG_ENGLISH, SC_LANG_FRENCH, SC_LANG_SPANISH, -1},
|
||||
{SC_LANG_ENGLISH, SC_LANG_FRENCH, SC_LANG_GERMAN, SC_LANG_SPANISH, SC_LANG_ITALIAN, SC_LANG_DUTCH, -1},
|
||||
{-1},
|
||||
{-1},
|
||||
{-1},
|
||||
{SC_LANG_KOREAN, -1},
|
||||
{-1},
|
||||
{-1},
|
||||
{-1},
|
||||
{-1},
|
||||
{SC_PRODUCT_AREA_HKG, -1},
|
||||
};
|
||||
|
||||
static const f32 scThumbnailOffsets[][2] = {{64.0f, 48.0f}, {85.0f, 48.0f}};
|
||||
extern "C" void iplSDChannelObj_813E3104(SDChannelObj* channel) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E311C(SDChannelObj* channel, EGG::ExpHeap* firstHeap,
|
||||
EGG::ExpHeap* secondHeap) NO_INLINE;
|
||||
extern "C" void* iplSDChannelObj_813E3128(SDChannelObj* channel) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E3178(SDChannelObj* channel, nw4r::lyt::Pane* pane) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E3180(SDChannelObj* channel, nand::LayoutFile* layoutFile) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E322C(SDChannelObj* channel) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E32C8(SDChannelObj* channel) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E3304(SDChannelObj* channel) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E330C(SDChannelObj* channel) NO_INLINE;
|
||||
extern "C" bool iplSDChannelObj_813E3330(SDChannelObj* channel) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E3354(SDChannelObj* channel, int request) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E33EC(SDChannelObj* channel, int request) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E3480(SDChannelObj* channel, bool request) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E34E0(SDChannelObj* channel) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E34E8(SDChannelObj* channel, int request) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E3534(SDChannelObj* channel, bool request) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E3580(const layout::Object* layout) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E3858(SDChannelObj* channel) NO_INLINE;
|
||||
extern "C" f32 iplSDChannelObj_813E3920(SDChannelObj* channel) NO_INLINE;
|
||||
extern "C" f32 iplSDChannelObj_813E3A84(SDChannelObj* channel) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E3B1C(SDChannelObj* channel) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E3BA0(SDChannelObj* channel) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E3C58(SDChannelObj* channel, const nw4r::math::VEC3& vec) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E3C9C(SDChannelObj* channel, int request) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E3E38(SDChannelObj* channel) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E3F28(SDChannelObj* channel, int request) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E3F74(SDChannelObj* channel) NO_INLINE;
|
||||
extern "C" const wchar_t* iplSDChannelObj_813E4060(SDChannelObj* channel, int index) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E413C(SDChannelObj* channel, const wchar_t* text) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E4410(SDChannelObj* channel, const nw4r::math::VEC3& vec) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E4558(SDChannelObj* channel, int request) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E4704(SDChannelObj* channel) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E481C(SDChannelObj* channel, layout::Object* layout) NO_INLINE;
|
||||
extern "C" void iplSDChannelObj_813E49A8(SDChannelObj* channel) NO_INLINE;
|
||||
extern "C" BOOL iplSDChannelObj_813E4A54(SDChannelObj* channel) NO_INLINE;
|
||||
|
||||
SDChannelObj::SDChannelObj(EGG::Heap* heap, int page, int index)
|
||||
: mpHeap(heap), mpDialogHeap(NULL), mpChannelHeap(NULL), mState(0), mPage(page), mIndex(index),
|
||||
mpPane(NULL), mpBaseLayout(NULL), mpPageLayout(NULL), mPageAnimation(0), mPageAnimationFrame(0),
|
||||
mpDialogLayout(NULL), mDialogState(0), mDialogFrame(0), mDialogTimer(0), mAnimationState(0),
|
||||
mpNewMessageGroup(NULL), mpNewMessageAnimator(NULL), mbNewMessageGroupActive(false), mNewMessageState(0),
|
||||
mNewMessageFrame(0), mOffsetX(scThumbnailOffsets[SCGetAspectRatio()][0]),
|
||||
mOffsetY(scThumbnailOffsets[SCGetAspectRatio()][1]), mStateFlags(1), mpThumbnailData(NULL) {
|
||||
if (SCGetAspectRatio() == SC_ASPECT_RATIO_16x9) {
|
||||
nw4r::ut::Rect projection4x3;
|
||||
System::getProjectionRect4x3(&projection4x3);
|
||||
nw4r::ut::Rect projection16x9;
|
||||
System::getProjectionRect16x9(&projection16x9);
|
||||
mAspectRatioScale = projection16x9.GetWidth() / projection4x3.GetWidth();
|
||||
} else {
|
||||
mAspectRatioScale = 1.0f;
|
||||
}
|
||||
memset(&mAppMeta, 0, sizeof(mAppMeta));
|
||||
}
|
||||
SDChannelObj::~SDChannelObj() {
|
||||
if (mpBaseLayout != NULL)
|
||||
mpBaseLayout->destroyHeap();
|
||||
if (mpPageLayout != NULL)
|
||||
delete mpPageLayout;
|
||||
if (mpDialogLayout != NULL)
|
||||
delete mpDialogLayout;
|
||||
}
|
||||
extern "C" void iplSDChannelObj_813E3104(SDChannelObj* channel) {
|
||||
if (channel->mState == 0)
|
||||
channel->mState = 2;
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E311C(SDChannelObj* channel, EGG::ExpHeap* firstHeap,
|
||||
EGG::ExpHeap* secondHeap) {
|
||||
channel->mpDialogHeap = firstHeap;
|
||||
channel->mpChannelHeap = secondHeap;
|
||||
}
|
||||
|
||||
extern "C" void* iplSDChannelObj_813E3128(SDChannelObj* channel) {
|
||||
if (channel->mpThumbnailData == NULL)
|
||||
channel->mpThumbnailData = new (channel->mpHeap, 32) u8[0x19000];
|
||||
return channel->mpThumbnailData;
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E3178(SDChannelObj* channel, nw4r::lyt::Pane* pane) {
|
||||
channel->mpPane = pane;
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E3180(SDChannelObj* channel, nand::LayoutFile* layoutFile) {
|
||||
if (!SDChannelSelect::isChannelReady(channel)) {
|
||||
channel->mpLayoutFile = layoutFile;
|
||||
if (channel->mpPageLayout == NULL)
|
||||
iplSDChannelObj_813E3BA0(channel);
|
||||
if (channel->mpDialogLayout == NULL)
|
||||
iplSDChannelObj_813E3F74(channel);
|
||||
if (channel->mState == 2 || channel->mState == 1 && channel->mpPaneAnimator->isFinished()) {
|
||||
iplSDChannelObj_813E3858(channel);
|
||||
channel->mState = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E322C(SDChannelObj* channel) {
|
||||
switch (channel->mState) {
|
||||
case 0:
|
||||
channel->mState = 2;
|
||||
break;
|
||||
case 1:
|
||||
if (!channel->mpPaneAnimator->isFinished())
|
||||
break;
|
||||
channel->mState = 2;
|
||||
case 2:
|
||||
iplSDChannelObj_813E3858(channel);
|
||||
channel->mState = 3;
|
||||
break;
|
||||
case 3:
|
||||
iplSDChannelObj_813E3B1C(channel);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E32C8(SDChannelObj* channel) {
|
||||
if (SDChannelSelect::isChannelReady(channel))
|
||||
channel->mpBaseLayout->draw();
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E3304(SDChannelObj* channel) {
|
||||
channel->mpPageLayout->draw();
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E330C(SDChannelObj* channel) {
|
||||
if (channel->mpDialogLayout != NULL)
|
||||
channel->mpDialogLayout->draw();
|
||||
}
|
||||
|
||||
nw4r::math::VEC3& SDChannelObj::getTranslate() const {
|
||||
return (nw4r::math::VEC3&)mpBaseLayout->GetRootPane()->GetTranslate();
|
||||
}
|
||||
|
||||
extern "C" bool iplSDChannelObj_813E3330(SDChannelObj* channel) {
|
||||
if (channel->mStateFlags == 0 || channel->mStateFlags == 3)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E3354(SDChannelObj* channel, int request) {
|
||||
if (request & 0x10000U) {
|
||||
channel->mAnimationState = 0;
|
||||
} else if (request & 0x20000U) {
|
||||
channel->mAnimationState = 1;
|
||||
} else if ((channel->mAnimationState += 1) > 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(request & 1)) {
|
||||
iplSDChannelObj_813E3C9C(channel, 1);
|
||||
}
|
||||
if (!(request & 2)) {
|
||||
iplSDChannelObj_813E4558(channel, 1);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E33EC(SDChannelObj* channel, int request) {
|
||||
if (request & 0x10000U) {
|
||||
channel->mAnimationState = 0;
|
||||
} else if (request & 0x20000U) {
|
||||
channel->mAnimationState = 1;
|
||||
} else if ((channel->mAnimationState -= 1) > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(request & 1)) {
|
||||
iplSDChannelObj_813E3C9C(channel, 3);
|
||||
}
|
||||
if (!(request & 2)) {
|
||||
iplSDChannelObj_813E4558(channel, 4);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E3480(SDChannelObj* channel, bool request) {
|
||||
if (request) {
|
||||
iplSDChannelObj_813E3C9C(channel, 1);
|
||||
channel->mAnimationState = 1;
|
||||
} else {
|
||||
iplSDChannelObj_813E3C9C(channel, 0);
|
||||
channel->mAnimationState = 0;
|
||||
}
|
||||
|
||||
iplSDChannelObj_813E4558(channel, 0);
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E34E0(SDChannelObj* channel) {
|
||||
iplSDChannelObj_813E3C9C(channel, 4);
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E34E8(SDChannelObj* channel, int request) {
|
||||
iplSDChannelObj_813E3C9C(channel, 0);
|
||||
if (request) {
|
||||
channel->mAnimationState = 0;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E3534(SDChannelObj* channel, bool request) {
|
||||
iplSDChannelObj_813E4558(channel, 0);
|
||||
if (request) {
|
||||
channel->mAnimationState = 0;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E3580(const layout::Object* layout) {
|
||||
int lang = System::getLanguage();
|
||||
const char* langGroup = scLangGroups[lang];
|
||||
char availableLanguages[10][4] = {};
|
||||
|
||||
bool languageFound = false;
|
||||
|
||||
for (nw4r::lyt::GroupList::Iterator it = layout->GetGroupList().GetBeginIter();
|
||||
it != layout->GetGroupList().GetEndIter(); it++) {
|
||||
if (strcmp(it->GetName(), langGroup) == 0) {
|
||||
languageFound = true;
|
||||
} else {
|
||||
bool languageGroup = true;
|
||||
for (int i = 0; i < channel::MAX_ANIMS; i++) {
|
||||
char name[8];
|
||||
sprintf(name, "Rso%d", i);
|
||||
if (strncmp(it->GetName(), name, 5) == 0) {
|
||||
languageGroup = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (languageGroup) {
|
||||
for (nw4r::lyt::PaneLinkList::Iterator it2 = it->GetPaneList().GetBeginIter();
|
||||
it2 != it->GetPaneList().GetEndIter(); it2++) {
|
||||
it2->mTarget->SetVisible(false);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (strncmp(it->GetName(), scLangGroups[i], 3) == 0) {
|
||||
memcpy(availableLanguages[i], it->GetName(), 3);
|
||||
availableLanguages[i][3] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (languageFound) {
|
||||
nw4r::lyt::Group* group = layout->FindGroupByName(langGroup);
|
||||
for (nw4r::lyt::PaneLinkList::Iterator it = group->GetPaneList().GetBeginIter();
|
||||
it != group->GetPaneList().GetEndIter(); it++) {
|
||||
it->mTarget->SetVisible(true);
|
||||
}
|
||||
} else {
|
||||
s32 region = System::getRegion();
|
||||
for (int i = 0; i < channel::MAX_ANIMS; i++) {
|
||||
if (scRegionGroups[region][i] != NULL) {
|
||||
if (strcmp(scRegionGroups[region][i], availableLanguages[scLangLookup[region][i]]) == 0) {
|
||||
nw4r::lyt::Group* group = layout->FindGroupByName(scRegionGroups[region][i]);
|
||||
for (nw4r::lyt::PaneLinkList::Iterator it = group->GetPaneList().GetBeginIter();
|
||||
it != group->GetPaneList().GetEndIter(); it++) {
|
||||
it->mTarget->SetVisible(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E3858(SDChannelObj* channel) {
|
||||
bool adjust = false;
|
||||
if (channel->mpDialogLayout == NULL)
|
||||
iplSDChannelObj_813E3F74(channel);
|
||||
f32 frame;
|
||||
if (iplSDChannelObj_813E3330(channel))
|
||||
frame = iplSDChannelObj_813E3920(channel);
|
||||
else {
|
||||
frame = iplSDChannelObj_813E3A84(channel);
|
||||
adjust = true;
|
||||
}
|
||||
iplSDChannelObj_813E3B1C(channel);
|
||||
if (channel->mpBaseAnimator != NULL)
|
||||
channel->mpBaseAnimator->play();
|
||||
channel->mpBaseLayout->finishBinding();
|
||||
if (channel->mpBaseAnimator != NULL)
|
||||
channel->mpBaseAnimator->setCurrentFrame(frame);
|
||||
if (adjust)
|
||||
channel->mpBaseLayout->adjustHeap();
|
||||
}
|
||||
|
||||
extern "C" f32 iplSDChannelObj_813E3920(SDChannelObj* channel) {
|
||||
f32 frame = 0.0f;
|
||||
channel->mpBaseLayout =
|
||||
layout::Object::create(channel->mpHeap, 0x8000, channel->mpThumbnailData, "arc", "icon.brlyt");
|
||||
iplSDChannelObj_813E3580(channel->mpBaseLayout);
|
||||
if (channel->mpBaseLayout->searchFile("icon.brlan"))
|
||||
channel->mpBaseAnimator = channel->mpBaseLayout->bind("icon.brlan");
|
||||
else if (channel->mpBaseLayout->searchFile("icon_Whole.brlan"))
|
||||
channel->mpBaseAnimator = channel->mpBaseLayout->bind("icon_Whole.brlan");
|
||||
else
|
||||
channel->mpBaseAnimator = NULL;
|
||||
if (channel->mpBaseAnimator != NULL) {
|
||||
f32 minimum = channel->mpBaseAnimator->getMinFrame();
|
||||
f32 maximum = channel->mpBaseAnimator->getMaxFrame();
|
||||
frame = minimum + (System::getRndm()->get_u16() % (u16)(maximum - minimum));
|
||||
}
|
||||
if (channel->mStateFlags == 0) {
|
||||
iplSDChannelObj_813E481C(channel, channel->mpBaseLayout);
|
||||
channel->mNewMessageState = 1;
|
||||
}
|
||||
return frame;
|
||||
}
|
||||
|
||||
extern "C" f32 iplSDChannelObj_813E3A84(SDChannelObj* channel) {
|
||||
channel->mpBaseLayout =
|
||||
layout::Object::create(channel->mpHeap, 0x8000, channel->mpLayoutFile, "arc", "mn_SdcardMenu_d.brlyt");
|
||||
channel->mpBaseAnimator = channel->mpBaseLayout->bind("mn_SdcardMenu_d.brlan");
|
||||
return System::getRndm()->get_u16() % 2000;
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E3B1C(SDChannelObj* channel) {
|
||||
iplSDChannelObj_813E49A8(channel);
|
||||
nw4r::math::VEC3 position(0, 0, 0);
|
||||
MTXMultVec(channel->mpPane->GetGlobalMtx(), position, position);
|
||||
channel->mpBaseLayout->GetRootPane()->SetTranslate(position);
|
||||
channel->mpBaseLayout->calc();
|
||||
iplSDChannelObj_813E3C58(channel, position);
|
||||
iplSDChannelObj_813E4410(channel, position);
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E3BA0(SDChannelObj* channel) {
|
||||
channel->mpPageLayout = new (channel->mpDialogHeap, 4)
|
||||
layout::Object(channel->mpDialogHeap, channel->mpLayoutFile, "arc", "my_IplTop_d.brlyt");
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
channel->mpPageAnimators[i] = channel->mpPageLayout->bind(scCursorAnims[i], scCursur, false);
|
||||
}
|
||||
|
||||
iplSDChannelObj_813E3C9C(channel, 0);
|
||||
channel->mpPageLayout->finishBinding();
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E3C58(SDChannelObj* channel, const nw4r::math::VEC3& vec) {
|
||||
channel->mpPageLayout->GetRootPane()->SetTranslate(vec);
|
||||
iplSDChannelObj_813E3E38(channel);
|
||||
channel->mpPageLayout->calc();
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E3C9C(SDChannelObj* channel, int request) {
|
||||
if (request == 0) {
|
||||
channel->mPageAnimation = 0;
|
||||
channel->mPageAnimationFrame = 0;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
channel->mpPageAnimators[i]->initFrame();
|
||||
}
|
||||
|
||||
channel->mpPageLayout->getAnim(1)->initAnmFrame();
|
||||
channel->mpPageLayout->GetRootPane()->SetVisible(false);
|
||||
} else if (request == 4) {
|
||||
channel->mPageAnimation = 4;
|
||||
channel->mPageAnimationFrame = 0;
|
||||
channel->mpPageLayout->GetRootPane()->SetVisible(true);
|
||||
iplSDChannelObj_813E3F28(channel, 2);
|
||||
} else {
|
||||
switch (channel->mPageAnimation) {
|
||||
case 0: {
|
||||
if (request == 1) {
|
||||
channel->mPageAnimation = 1;
|
||||
channel->mpPageLayout->GetRootPane()->SetVisible(true);
|
||||
iplSDChannelObj_813E3F28(channel, 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
if (request == 2) {
|
||||
channel->mPageAnimation = 2;
|
||||
} else if (request == 3) {
|
||||
channel->mPageAnimationFrame = 3;
|
||||
} else if (request == 1) {
|
||||
channel->mPageAnimationFrame = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
if (request == 3) {
|
||||
channel->mPageAnimation = 3;
|
||||
iplSDChannelObj_813E3F28(channel, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
if (request == 1) {
|
||||
channel->mPageAnimationFrame = 1;
|
||||
} else if (request == 3) {
|
||||
channel->mPageAnimationFrame = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E3E38(SDChannelObj* channel) {
|
||||
switch (channel->mPageAnimation) {
|
||||
case 1: {
|
||||
if (!channel->mpPageAnimators[1]->isPlaying()) {
|
||||
int prev = channel->mPageAnimationFrame;
|
||||
switch (channel->mPageAnimation) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
channel->mPageAnimation = 2;
|
||||
break;
|
||||
case 2:
|
||||
break;
|
||||
case 3:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (prev == 3) {
|
||||
iplSDChannelObj_813E3C9C(channel, 3);
|
||||
channel->mPageAnimationFrame = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
if (!channel->mpPageAnimators[0]->isPlaying()) {
|
||||
int prev = channel->mPageAnimationFrame;
|
||||
iplSDChannelObj_813E3C9C(channel, 0);
|
||||
if (prev == 1) {
|
||||
iplSDChannelObj_813E3C9C(channel, 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
if (!channel->mpPageAnimators[2]->isPlaying()) {
|
||||
iplSDChannelObj_813E3C9C(channel, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E3F28(SDChannelObj* channel, int request) {
|
||||
channel->mpPageAnimators[request]->setAnmType(ANIM_TYPE_FORWARD);
|
||||
channel->mpPageAnimators[request]->play();
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E3F74(SDChannelObj* channel) {
|
||||
if (!iplSDChannelObj_813E3330(channel)) {
|
||||
channel->mpDialogLayout = NULL;
|
||||
return;
|
||||
}
|
||||
channel->mpDialogLayout = new (channel->mpChannelHeap, 4)
|
||||
layout::Object(channel->mpChannelHeap, channel->mpLayoutFile, "arc", "my_IplTopBalloon_a.brlyt");
|
||||
if (channel->mStateFlags == 0)
|
||||
iplSDChannelObj_813E413C(channel, iplSDChannelObj_813E4060(channel, 0));
|
||||
else if (channel->mStateFlags == 3)
|
||||
iplSDChannelObj_813E413C(channel, scUnknownName);
|
||||
else
|
||||
iplSDChannelObj_813E413C(channel, L"");
|
||||
channel->mpDialogAnimator = channel->mpDialogLayout->bind("my_IplTopBalloon_a_BalloonInOut.brlan");
|
||||
iplSDChannelObj_813E4558(channel, 0);
|
||||
channel->mpDialogLayout->finishBinding();
|
||||
}
|
||||
|
||||
extern "C" const wchar_t* iplSDChannelObj_813E4060(SDChannelObj* channel, int index) {
|
||||
if (channel->mAppMeta.metaHdr.names[System::getLanguage()][index][0] != 0)
|
||||
return channel->mAppMeta.metaHdr.names[System::getLanguage()][index];
|
||||
const u32* languages = scLangLookup[System::getRegion()];
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
if (channel->mAppMeta.metaHdr.names[languages[i]][index][0] != 0)
|
||||
return channel->mAppMeta.metaHdr.names[languages[i]][index];
|
||||
if (languages[i] == -1)
|
||||
break;
|
||||
}
|
||||
return channel->mAppMeta.metaHdr.names[languages[0]][index];
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E413C(SDChannelObj* channel, const wchar_t* text) {
|
||||
nw4r::lyt::TextBox* textPane =
|
||||
nw4r::ut::DynamicCast<nw4r::lyt::TextBox*>(channel->mpDialogLayout->FindPaneByName(scBalloon));
|
||||
|
||||
wchar_t titleText[channel::META_CHANNEL_NAME_LENGTH + 3] = L"";
|
||||
u32 titleLength;
|
||||
|
||||
wcsncpy(titleText, text, channel::META_CHANNEL_NAME_LENGTH);
|
||||
titleLength = wcslen(titleText);
|
||||
|
||||
f32 ellipsisWidth = 0.0f;
|
||||
int ellipsisLength = 0;
|
||||
|
||||
if (titleLength == 0) {
|
||||
textPane->SetString(titleText, 0, 1);
|
||||
} else {
|
||||
for (u32 i = titleLength; i != 0; i--) {
|
||||
textPane->SetString(titleText, 0, i + ellipsisLength);
|
||||
textPane->CalculateMtx(*channel->mpDialogLayout->getDrawInfo());
|
||||
|
||||
nw4r::ut::Rect textRect = textPane->GetTextDrawRect(*channel->mpDialogLayout->getDrawInfo());
|
||||
if (textRect.GetWidth() <= ellipsisWidth + 391.5f) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (System::getRegion() == SC_PRODUCT_AREA_JPN) {
|
||||
titleText[i - 1] = NULL;
|
||||
titleText[i - 2] = L'…';
|
||||
} else {
|
||||
ellipsisWidth = -1.179962f;
|
||||
ellipsisLength = 2;
|
||||
titleText[i + 1] = NULL;
|
||||
titleText[i] = '.';
|
||||
titleText[i - 1] = '.';
|
||||
titleText[i - 2] = '.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nw4r::ut::Rect textRect = textPane->GetTextDrawRect(*channel->mpDialogLayout->getDrawInfo());
|
||||
|
||||
nw4r::lyt::Size newSize(channel->mpDialogLayout->FindPaneByName(scBase)->GetSize());
|
||||
newSize.width = textRect.right - textRect.left + 40.0f;
|
||||
|
||||
if (newSize.width < channel->mAspectRatioScale * 160.0f) {
|
||||
newSize.width = channel->mAspectRatioScale * 160.0f;
|
||||
}
|
||||
|
||||
channel->mpDialogLayout->FindPaneByName(scShade)->SetSize(newSize);
|
||||
channel->mpDialogLayout->FindPaneByName(scBase)->SetSize(newSize);
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E4410(SDChannelObj* channel, const nw4r::math::VEC3& vec) {
|
||||
if (channel->mpDialogLayout != NULL) {
|
||||
nw4r::lyt::Size size;
|
||||
|
||||
size = channel->mpDialogLayout->FindPaneByName(scBase)->GetSize();
|
||||
|
||||
f32 verticalOffset = -2.0f + ((size.height / 2) + channel->mOffsetY);
|
||||
verticalOffset *= -1.0f;
|
||||
|
||||
nw4r::ut::Rect projRect;
|
||||
System::getProjectionRect(&projRect);
|
||||
|
||||
f32 centerX = vec.x;
|
||||
f32 halfWidth = size.width / 2;
|
||||
f32 horizontalOffset = 0.0f;
|
||||
f32 leftMargin = (centerX - halfWidth) - projRect.left;
|
||||
f32 rightMargin = projRect.right - (centerX + halfWidth);
|
||||
if (leftMargin < 60.0f) {
|
||||
horizontalOffset = 60.0f - leftMargin;
|
||||
} else if (rightMargin < 60.0f) {
|
||||
horizontalOffset = rightMargin - 60.0f;
|
||||
}
|
||||
|
||||
const nw4r::math::VEC3 pos(vec.x + horizontalOffset, vec.y + verticalOffset, 0.0f);
|
||||
channel->mpDialogLayout->GetRootPane()->SetTranslate(pos);
|
||||
|
||||
iplSDChannelObj_813E4704(channel);
|
||||
channel->mpDialogLayout->calc();
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E4558(SDChannelObj* channel, int request) {
|
||||
if (channel->mpDialogLayout != NULL) {
|
||||
if (request == 0) {
|
||||
channel->mDialogState = 0;
|
||||
channel->mDialogFrame = 0;
|
||||
|
||||
channel->mpDialogLayout->setMinFrame(0.0f);
|
||||
channel->mpDialogLayout->GetRootPane()->SetVisible(false);
|
||||
} else {
|
||||
switch (channel->mDialogState) {
|
||||
case 0: {
|
||||
if (request == 1) {
|
||||
channel->mDialogTimer = 0;
|
||||
channel->mDialogState = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
if (request == 2) {
|
||||
channel->mDialogState = 2;
|
||||
channel->mpDialogLayout->GetRootPane()->SetVisible(true);
|
||||
channel->mpDialogLayout->setAnmType(ANIM_TYPE_FORWARD);
|
||||
channel->mpDialogLayout->start();
|
||||
snd::getSystem()->startSE("WIPL_SE_BALLOON");
|
||||
} else if (request == 4) {
|
||||
channel->mDialogState = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
if (request == 3) {
|
||||
channel->mDialogState = 3;
|
||||
} else if (request == 4) {
|
||||
channel->mDialogFrame = 4;
|
||||
} else if (request == 1) {
|
||||
channel->mDialogFrame = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
if (request == 4) {
|
||||
channel->mDialogState = 4;
|
||||
channel->mpDialogLayout->setAnmType(ANIM_TYPE_BACKWARD);
|
||||
channel->mpDialogLayout->start();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
if (request == 1) {
|
||||
channel->mDialogFrame = 1;
|
||||
} else if (request == 4) {
|
||||
channel->mDialogFrame = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E4704(SDChannelObj* channel) {
|
||||
switch (channel->mDialogState) {
|
||||
case 1: {
|
||||
if ((reinterpret_cast<u32&>(channel->mDialogTimer) += 1) >= 20.0f) {
|
||||
iplSDChannelObj_813E4558(channel, 2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
case 3: {
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
if (!channel->mpDialogLayout->isPlaying(0)) {
|
||||
int prev = channel->mDialogFrame;
|
||||
iplSDChannelObj_813E4558(channel, 3);
|
||||
if (prev == 4) {
|
||||
iplSDChannelObj_813E4558(channel, 4);
|
||||
channel->mDialogFrame = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
if (!channel->mpDialogLayout->isPlaying(0)) {
|
||||
int prev = channel->mDialogFrame;
|
||||
iplSDChannelObj_813E4558(channel, 0);
|
||||
if (prev == 1) {
|
||||
iplSDChannelObj_813E4558(channel, 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E481C(SDChannelObj* channel, layout::Object* layout) {
|
||||
char groupName[20];
|
||||
char** lookup;
|
||||
nw4r::lyt::Group* group;
|
||||
|
||||
group = layout->FindGroupByName("New");
|
||||
if (group != NULL) {
|
||||
channel->mpNewMessageGroup = group;
|
||||
} else {
|
||||
sprintf(groupName, "New_%s", scLangGroups[System::getLanguage()]);
|
||||
|
||||
group = layout->FindGroupByName(groupName);
|
||||
if (group != NULL) {
|
||||
channel->mpNewMessageGroup = group;
|
||||
} else {
|
||||
lookup = (char**)scRegionGroups[System::getRegion()];
|
||||
|
||||
for (int i = 0; lookup[i] != NULL; i++) {
|
||||
sprintf(groupName, "New_%s", lookup[i]);
|
||||
|
||||
group = layout->FindGroupByName(groupName);
|
||||
if (group != NULL) {
|
||||
channel->mpNewMessageGroup = group;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (group != NULL) {
|
||||
for (nw4r::lyt::PaneLinkList::Iterator it = group->GetPaneList().GetBeginIter();
|
||||
it != group->GetPaneList().GetEndIter(); it++) {
|
||||
it->mTarget->UnbindAllAnimation();
|
||||
}
|
||||
|
||||
if (layout->searchFile("icon_New.brlan")) {
|
||||
channel->mpNewMessageAnimator = layout->bindToGroup("icon_New.brlan", group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void iplSDChannelObj_813E49A8(SDChannelObj* channel) {
|
||||
if (System::getNwc24Manager() != NULL) {
|
||||
switch (channel->mNewMessageState) {
|
||||
case 1: {
|
||||
if (iplSDChannelObj_813E4A54(channel)) {
|
||||
channel->mNewMessageState = 2;
|
||||
channel->mNewMessageFrame = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
if (++reinterpret_cast<u32&>(channel->mNewMessageFrame) >= 4200) {
|
||||
channel->mNewMessageState = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" BOOL iplSDChannelObj_813E4A54(SDChannelObj* channel) {
|
||||
if (System::getNwc24Manager() == NULL || !System::getNwc24Manager()->getNewTitleTbl(NULL)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
u32 titleCode = ES_TITLE_CODE(channel->mAppMeta.titleId);
|
||||
if (!System::getNwc24Manager()->isNewMessageThere(titleCode)) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (!channel->mbNewMessageGroupActive) {
|
||||
if (channel->mpNewMessageGroup != NULL) {
|
||||
for (nw4r::lyt::PaneLinkList::Iterator it =
|
||||
channel->mpNewMessageGroup->GetPaneList().GetBeginIter();
|
||||
it != channel->mpNewMessageGroup->GetPaneList().GetEndIter(); it++) {
|
||||
it->mTarget->SetVisible(true);
|
||||
}
|
||||
|
||||
if (channel->mpNewMessageAnimator != NULL) {
|
||||
channel->mpNewMessageAnimator->play();
|
||||
}
|
||||
}
|
||||
|
||||
channel->mbNewMessageGroupActive = true;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
} // namespace scene
|
||||
} // namespace ipl
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user