Compare commits
57 Commits
agent/read
...
agent/w092
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f534407d2 | ||
|
|
9845b3d75e | ||
|
|
88ab8325db | ||
|
|
2060db15f6 | ||
|
|
eaee2295cc | ||
|
|
856a31f8c9 | ||
|
|
9ea683dd61 | ||
|
|
ea4ec10115 | ||
|
|
97a2eb1f23 | ||
|
|
3cbf4bb3e9 | ||
|
|
033b33a486 | ||
|
|
6b6215ad3e | ||
|
|
9ad0863dbf | ||
|
|
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 |
|
||||
|:---:|:---:|:---:|:---:|
|
||||
| 91.60% | 80.76% | 56.95% | 88.75% |
|
||||
|
||||
units 758/1027 complete, functions 11609/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] |
|
||||
|
||||
52
configure.py
52
configure.py
@@ -1448,10 +1448,10 @@ config.libs = [
|
||||
Object(Matching, "axfx/AXFXReverbHi.c"),
|
||||
Object(Matching, "axfx/AXFXReverbHiDpl2.c"),
|
||||
Object(Matching, "axfx/AXFXReverbHiExp.c"),
|
||||
Object(NonMatching, "axfx/AXFXReverbHiExpDpl2.c"),
|
||||
Object(Matching, "axfx/AXFXReverbHiExpDpl2.c"),
|
||||
Object(Matching, "axfx/AXFXDelay.c"),
|
||||
Object(Matching, "axfx/AXFXReverbStd.c"),
|
||||
Object(NonMatching, "axfx/AXFXReverbStdExp.c"),
|
||||
Object(Matching, "axfx/AXFXReverbStdExp.c"),
|
||||
Object(Matching, "axfx/AXFXChorus.c"),
|
||||
Object(NonMatching, "axfx/AXFXChorusExp.c"),
|
||||
Object(Matching, "axfx/AXFXLfoTable.c"),
|
||||
@@ -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"),
|
||||
@@ -1708,7 +1708,7 @@ config.libs = [
|
||||
Object(NonMatching, "fa/pf_volume_apiadd.c"),
|
||||
Object(NonMatching, "fa/pf_cp932.c"),
|
||||
Object(Matching, "fa/pf_api_util.c"),
|
||||
Object(NonMatching, "fa/pf_attach.c"),
|
||||
Object(Matching, "fa/pf_attach.c"),
|
||||
Object(NonMatching, "fa/pf_buffering.c"),
|
||||
Object(NonMatching, "fa/pf_cdelete.c"),
|
||||
Object(NonMatching, "fa/pf_chdir.c"),
|
||||
@@ -1721,7 +1721,7 @@ config.libs = [
|
||||
Object(NonMatching, "fa/pf_createdir.c"),
|
||||
Object(NonMatching, "fa/pf_cut.c"),
|
||||
Object(NonMatching, "fa/pf_derrnum.c"),
|
||||
Object(NonMatching, "fa/pf_detach.c"),
|
||||
Object(Matching, "fa/pf_detach.c"),
|
||||
Object(NonMatching, "fa/pf_divide.c"),
|
||||
Object(Matching, "fa/pf_errnum.c"),
|
||||
Object(NonMatching, "fa/pf_fadjust.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"),
|
||||
@@ -1750,16 +1750,16 @@ config.libs = [
|
||||
Object(NonMatching, "fa/pf_init_prfile2.c"),
|
||||
Object(NonMatching, "fa/pf_insert.c"),
|
||||
Object(NonMatching, "fa/pf_iswriteprotected.c"),
|
||||
Object(NonMatching, "fa/pf_mkdir.c"),
|
||||
Object(NonMatching, "fa/pf_mount.c"),
|
||||
Object(Matching, "fa/pf_mkdir.c"),
|
||||
Object(Matching, "fa/pf_mount.c"),
|
||||
Object(NonMatching, "fa/pf_move.c"),
|
||||
Object(NonMatching, "fa/pf_opendir.c"),
|
||||
Object(NonMatching, "fa/pf_readdir.c"),
|
||||
Object(NonMatching, "fa/pf_regctx.c"),
|
||||
Object(NonMatching, "fa/pf_remove.c"),
|
||||
Object(NonMatching, "fa/pf_rename.c"),
|
||||
Object(Matching, "fa/pf_remove.c"),
|
||||
Object(Matching, "fa/pf_rename.c"),
|
||||
Object(NonMatching, "fa/pf_rewinddir.c"),
|
||||
Object(NonMatching, "fa/pf_rmdir.c"),
|
||||
Object(Matching, "fa/pf_rmdir.c"),
|
||||
Object(NonMatching, "fa/pf_rmvvol.c"),
|
||||
Object(NonMatching, "fa/pf_seekdir.c"),
|
||||
Object(NonMatching, "fa/pf_setclstlink.c"),
|
||||
@@ -1771,7 +1771,7 @@ config.libs = [
|
||||
Object(NonMatching, "fa/pf_setvolcfg.c"),
|
||||
Object(NonMatching, "fa/pf_sync.c"),
|
||||
Object(NonMatching, "fa/pf_telldir.c"),
|
||||
Object(NonMatching, "fa/pf_unmount.c"),
|
||||
Object(Matching, "fa/pf_unmount.c"),
|
||||
Object(NonMatching, "fa/pf_unregctx.c"),
|
||||
Object(NonMatching, "fa/pf_xdivide.c"),
|
||||
Object(Matching, "fa/pf_w_api_util.c"),
|
||||
@@ -1944,7 +1944,7 @@ config.libs = [
|
||||
Object(Matching, "MSL_Common/alloc.c"),
|
||||
Object(Matching, "MSL_Common/errno.c"),
|
||||
Object(Matching, "MSL_Common/ansi_files.c"),
|
||||
Object(NonMatching, "MSL_Common_Embedded/ansi_fp.c"),
|
||||
Object(NonMatching, "MSL_Common_Embedded/ansi_fp.c", extra_cflags=["-Cpp_exceptions on"]),
|
||||
Object(Matching, "MSL_Common/ctype.c"),
|
||||
Object(NonMatching, "MSL_Common/locale.c"),
|
||||
Object(Matching, "MSL_Common/arith.c", extra_cflags=["-Cpp_exceptions on"]),
|
||||
@@ -1958,19 +1958,19 @@ config.libs = [
|
||||
Object(Matching, "MSL_Common/mem_funcs.c"),
|
||||
Object(Matching, "MSL_Common/math_api.c"),
|
||||
Object(Matching, "MSL_Common/misc_io.c"),
|
||||
Object(NonMatching, "MSL_Common/printf.c"),
|
||||
Object(NonMatching, "MSL_Common/printf.c", extra_cflags=["-Cpp_exceptions on"]),
|
||||
Object(Matching, "MSL_Common/qsort.c", extra_cflags=["-Cpp_exceptions on"]),
|
||||
Object(Matching, "MSL_Common/rand.c"),
|
||||
Object(NonMatching, "MSL_Common/scanf.c"),
|
||||
Object(NonMatching, "MSL_Common/scanf.c", extra_cflags=["-Cpp_exceptions on"]),
|
||||
Object(Matching, "MSL_Common/signal.c", extra_cflags=["-Cpp_exceptions on"]),
|
||||
Object(Matching, "MSL_Common/string.c"),
|
||||
Object(Matching, "MSL_Common/float.c"),
|
||||
Object(NonMatching, "MSL_Common/strtold.c"),
|
||||
Object(NonMatching, "MSL_Common/strtold.c", extra_cflags=["-Cpp_exceptions on"]),
|
||||
Object(Matching, "MSL_Common/strtoul.c", extra_cflags=["-Cpp_exceptions on"]),
|
||||
Object(NonMatching, "MSL_Common/time.c"),
|
||||
Object(NonMatching, "MSL_Common/time.c", extra_cflags=["-Cpp_exceptions on"]),
|
||||
Object(Matching, "MSL_Common/wctype.c"),
|
||||
Object(Matching, "MSL_Common/wmem.c"),
|
||||
Object(NonMatching, "MSL_Common/wprintf.c"),
|
||||
Object(NonMatching, "MSL_Common/wprintf.c", extra_cflags=["-Cpp_exceptions on"]),
|
||||
Object(Matching, "MSL_Common/wstring.c"),
|
||||
Object(Matching, "MSL_Common/wchar_io.c"),
|
||||
Object(Matching, "PPC_EABI/time.dolphin.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
|
||||
|
||||
|
||||
@@ -18,7 +18,9 @@ namespace textinput {
|
||||
LayoutByNW4R(nw4r::lyt::MultiArcResourceAccessor* multiArc, const char* layoutName, EventObserver* event)
|
||||
: nw4rmanager::Layout(multiArc, layoutName, event) {}
|
||||
#endif
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
#if defined(MYTIMANAGER_MATCHING)
|
||||
virtual ~LayoutByNW4R() {}
|
||||
#elif defined(MYTIMANAGER_IMPLEMENTATION)
|
||||
virtual ~LayoutByNW4R();
|
||||
#else
|
||||
virtual ~LayoutByNW4R() {}
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -167,6 +167,25 @@ namespace textinput {
|
||||
void setManager(Manager* manager) { mpManager = manager; }
|
||||
#endif
|
||||
virtual ~State();
|
||||
#ifdef MYTIMANAGER_MATCHING
|
||||
virtual Manager::StateType getStateType() = 0;
|
||||
|
||||
virtual void create() = 0;
|
||||
|
||||
virtual void init() = 0;
|
||||
|
||||
virtual void draw() = 0;
|
||||
virtual void memoDraw() = 0;
|
||||
|
||||
virtual void calc() = 0;
|
||||
|
||||
virtual bool updateInput(int chan, f32 x, f32 y, u32 trig, u32 hold, u32 release) = 0;
|
||||
virtual bool updateInput(input::HKBManager& hkbManager) = 0;
|
||||
|
||||
virtual void start() = 0;
|
||||
virtual void end() = 0;
|
||||
|
||||
#else
|
||||
virtual Manager::StateType getStateType();
|
||||
|
||||
virtual void create();
|
||||
@@ -184,6 +203,7 @@ namespace textinput {
|
||||
virtual void start();
|
||||
virtual void end();
|
||||
|
||||
#endif
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
virtual InputForm* InputForm();
|
||||
virtual keyboard::hwkey::HWKeyboard* HWKeyboard();
|
||||
|
||||
@@ -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,58 @@
|
||||
#define TEXTINPUT_CELL_PHONE_H
|
||||
|
||||
#include "tiNw4rManager.h"
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIHWKEYBOARD_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
#include "tiKeyboard.h"
|
||||
#endif
|
||||
|
||||
#ifdef TI_CELLPHONE_IMPLEMENTATION
|
||||
#include <revolution/gx.h>
|
||||
#endif
|
||||
|
||||
namespace textinput {
|
||||
class Manager;
|
||||
#ifdef TI_CELLPHONE_SAMPLE_CLASS
|
||||
class EventObserver;
|
||||
#endif
|
||||
namespace predictlang {
|
||||
class LayoutByNW4R;
|
||||
}
|
||||
namespace keyboard {
|
||||
#ifdef TI_CELLPHONE_IMPLEMENTATION
|
||||
enum VKeyCode {
|
||||
VK_LINE_FEED = 0,
|
||||
VK_DELETE = 1,
|
||||
VK_SIGN_INPUT = 9,
|
||||
VK_PREDICT_LANGUAGE = 10,
|
||||
VK_INPUT_MODE_02 = 11,
|
||||
VK_INPUT_MODE_03 = 13,
|
||||
VK_INPUT_MODE_00 = 18,
|
||||
VK_INPUT_MODE_01 = 19,
|
||||
VK_TOGGLE_ABC_MODE = 23,
|
||||
};
|
||||
#endif
|
||||
namespace signwindow {
|
||||
class LayoutByNW4R;
|
||||
}
|
||||
}
|
||||
|
||||
namespace keyboard {
|
||||
namespace cellphonetype {
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
class EventHandler;
|
||||
#ifdef TI_CELLPHONE_IMPLEMENTATION
|
||||
class CellPhoneAnmPane;
|
||||
struct PaneNameToCharCode;
|
||||
#endif
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIHWKEYBOARD_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(TIHWKEYBOARD_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) && defined(TI_CELLPHONE_SAMPLE_CLASS)
|
||||
Base(Manager* manager) : mPreviousInputMode(0), mCurrentInputMode(0), mpManager(manager) {}
|
||||
#endif
|
||||
enum InputMode {
|
||||
IM_00,
|
||||
IM_01,
|
||||
@@ -29,7 +67,18 @@ 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) {}
|
||||
#endif
|
||||
#if defined(TI_CELLPHONE_IMPLEMENTATION)
|
||||
virtual u32 getType() override;
|
||||
#elif defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISIGNWINDOW_IMPLEMENTATION)
|
||||
virtual int getType() override;
|
||||
#elif defined(TIHWKEYBOARD_IMPLEMENTATION)
|
||||
virtual int getType() override;
|
||||
#else
|
||||
virtual void getType() override;
|
||||
#endif
|
||||
virtual void onActive() override;
|
||||
virtual void calc();
|
||||
virtual void draw();
|
||||
@@ -52,6 +101,9 @@ namespace textinput {
|
||||
virtual bool isAtokActive();
|
||||
virtual void doInput();
|
||||
virtual void updateFixMode();
|
||||
#ifdef TI_CELLPHONE_IMPLEMENTATION
|
||||
wchar_t convertToZiCellphoneInput_(wchar_t value);
|
||||
#endif
|
||||
#else
|
||||
virtual void vt_0x08();
|
||||
virtual void vt_0x0C();
|
||||
@@ -74,7 +126,7 @@ namespace textinput {
|
||||
|
||||
virtual void vt_0x4C();
|
||||
virtual void vt_0x50();
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIHWKEYBOARD_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
virtual void doNumericMode(bool);
|
||||
#else
|
||||
virtual void vt_0x54();
|
||||
@@ -90,9 +142,16 @@ namespace textinput {
|
||||
|
||||
// TODO enum?
|
||||
int getInputType() const;
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIHWKEYBOARD_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
void resetHoldingButton();
|
||||
#endif
|
||||
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIHWKEYBOARD_IMPLEMENTATION) || defined(TIMANAGER_IMPLEMENTATION)
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) && defined(TI_CELLPHONE_IMPLEMENTATION)
|
||||
protected:
|
||||
#else
|
||||
private:
|
||||
#endif
|
||||
u32 mPreviousInputMode;
|
||||
u32 mCurrentInputMode;
|
||||
bool mbInputModeLocked;
|
||||
@@ -101,20 +160,70 @@ namespace textinput {
|
||||
bool mbUpperCaseMode;
|
||||
bool mbAbcMode;
|
||||
bool mbLanguageKeyMode;
|
||||
#ifdef TI_CELLPHONE_IMPLEMENTATION
|
||||
const PaneNameToCharCode* mHoldingButton;
|
||||
#else
|
||||
u32 mHoldingButton;
|
||||
#endif
|
||||
void* mpInputModeTable;
|
||||
MEMAllocator* mpAllocator;
|
||||
#ifdef TI_CELLPHONE_IMPLEMENTATION
|
||||
Manager* mpManager;
|
||||
bool mInputState;
|
||||
#elif defined(TIMANAGER_IMPLEMENTATION)
|
||||
Manager* mpManager;
|
||||
u32 mInputState;
|
||||
#else
|
||||
void* mpInputSettings;
|
||||
u32 mInputState;
|
||||
#endif
|
||||
#ifdef TI_CELLPHONE_IMPLEMENTATION
|
||||
void onCtrlKey_(VKeyCode keyCode);
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
class LayoutByNW4R : public Base, public nw4rmanager::Layout {
|
||||
public:
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) || defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIHWKEYBOARD_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
|
||||
#if defined(MYTIMANAGER_IMPLEMENTATION) && defined(TI_CELLPHONE_SAMPLE_CLASS)
|
||||
LayoutByNW4R(Manager* manager, nw4r::lyt::MultiArcResourceAccessor* resAccessor, EventObserver* observer)
|
||||
: Base(manager), nw4rmanager::Layout(resAccessor, "fs_VK_cellPhone_a.brlyt", observer), mpSignWindow(NULL) {}
|
||||
#endif
|
||||
virtual void doNumericMode(bool);
|
||||
#ifdef TI_CELLPHONE_IMPLEMENTATION
|
||||
virtual void setPredictLanguageDialog(predictlang::LayoutByNW4R*);
|
||||
virtual void setSignWindow(signwindow::LayoutByNW4R*);
|
||||
#else
|
||||
virtual void setPredictLanguageDialog(void*);
|
||||
virtual void setSignWindow(void*);
|
||||
#endif
|
||||
#endif
|
||||
virtual void doNumericWithDotMode(bool);
|
||||
virtual void setLineFeedButton(bool);
|
||||
virtual void setPredictLanguageButton(bool);
|
||||
@@ -124,12 +233,133 @@ namespace textinput {
|
||||
|
||||
void onPressedShift(bool shift);
|
||||
void onReleasedShift();
|
||||
#ifdef MYTIMANAGER_IMPLEMENTATION
|
||||
#if defined(TIINPUTFORM_IMPLEMENTATION) || defined(TIHWKEYBOARD_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(TIHWKEYBOARD_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 TI_CELLPHONE_IMPLEMENTATION
|
||||
virtual ~LayoutByNW4R();
|
||||
virtual void create(MEMAllocator* allocator) override;
|
||||
virtual void init() override;
|
||||
virtual void draw() override;
|
||||
virtual void calc() override;
|
||||
virtual void update() override;
|
||||
virtual void onKey(u32 key, void* data) override;
|
||||
virtual void onActive() override;
|
||||
virtual void updateFromReceiver(u32 command, void* data) override;
|
||||
virtual void changeInputMode(InputMode mode) override;
|
||||
virtual void changePredictLanguage() override;
|
||||
virtual void setAbcMode(bool enabled) override;
|
||||
virtual void goSignInputMode() override;
|
||||
virtual void setInputMode(InputMode mode) override;
|
||||
virtual void setLanguage(Language language) override;
|
||||
virtual void setCommandReceiver(CommandReceiver* receiver) override;
|
||||
|
||||
virtual CellPhoneAnmPane* getAnmPane(InputMode mode);
|
||||
virtual void throwReleaseForAll();
|
||||
virtual void changeAnimationAllToNormal();
|
||||
virtual void updatePredictLanguage(CommandReceiver::ChangePredictMode* mode);
|
||||
virtual void changeKeyTop(const PaneNameToCharCode* keys);
|
||||
virtual void changeSpaceKeyTop(const PaneNameToCharCode* keys);
|
||||
void setUpperCaseJP(bool enabled);
|
||||
void setLangKeyActive(bool enabled);
|
||||
void resetHoldingButton();
|
||||
|
||||
private:
|
||||
bool mbLineFeedButton;
|
||||
GXTexObj mTextures[3];
|
||||
EventHandler* mpEventHandler;
|
||||
predictlang::LayoutByNW4R* mpPredictLanguageDialog;
|
||||
signwindow::LayoutByNW4R* mpSignWindow;
|
||||
#elif defined(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
|
||||
};
|
||||
|
||||
#ifdef TI_CELLPHONE_SAMPLE_CLASS
|
||||
class Sample : public LayoutByNW4R {
|
||||
public:
|
||||
Sample(Manager* manager, nw4r::lyt::MultiArcResourceAccessor* resAccessor, EventObserver* observer)
|
||||
: LayoutByNW4R(manager, resAccessor, observer) {}
|
||||
virtual ~Sample() {}
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef TI_CELLPHONE_IMPLEMENTATION
|
||||
enum Animation {
|
||||
ANM_Normal,
|
||||
ANM_FocusIn,
|
||||
ANM_FocusOut,
|
||||
ANM_RollOver,
|
||||
ANM_Pushed,
|
||||
ANM_05,
|
||||
ANM_06,
|
||||
ANM_ToggleOff,
|
||||
ANM_Last,
|
||||
};
|
||||
|
||||
enum KeyType {
|
||||
KT_NormalButton,
|
||||
KT_ControlButton,
|
||||
};
|
||||
|
||||
class CellPhoneAnmPane : public nw4rmanager::AnmPane {
|
||||
public:
|
||||
CellPhoneAnmPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer)
|
||||
: nw4rmanager::AnmPane(pane, observer), meState(ANM_Normal), meKeyType(KT_NormalButton) {}
|
||||
|
||||
virtual void init() override;
|
||||
virtual void onAnmEvent(AnmPaneEvent event) override;
|
||||
virtual void changeAnimation(u32 id) override;
|
||||
virtual KeyType getKeyType() const;
|
||||
u32 getAnimationState() const { return meState; }
|
||||
virtual ~CellPhoneAnmPane();
|
||||
|
||||
protected:
|
||||
Animation meState;
|
||||
KeyType meKeyType;
|
||||
};
|
||||
|
||||
class CellPhoneControlAnmPane : public CellPhoneAnmPane {
|
||||
public:
|
||||
CellPhoneControlAnmPane(nw4r::lyt::Pane* pane, nw4rmanager::AnmObserver* observer)
|
||||
: CellPhoneAnmPane(pane, observer) { meKeyType = KT_ControlButton; }
|
||||
|
||||
virtual void onAnmEvent(AnmPaneEvent event) override;
|
||||
virtual ~CellPhoneControlAnmPane();
|
||||
};
|
||||
|
||||
class EventHandler : public nw4rmanager::TiEventHandler {
|
||||
public:
|
||||
EventHandler(LayoutByNW4R* layout) : mpLayoutByNW4R(layout) {}
|
||||
virtual ~EventHandler();
|
||||
virtual void onTiEvent(gui::PaneComponent* pane, u32 event, Input* input) override;
|
||||
|
||||
private:
|
||||
LayoutByNW4R* mpLayoutByNW4R;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace cellphonetype
|
||||
} // namespace keyboard
|
||||
} // namespace textinput
|
||||
|
||||
@@ -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,143 @@
|
||||
#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;
|
||||
#ifdef TIHWKEYBOARD_IMPLEMENTATION
|
||||
KeySet GetReleasedKeySet() const;
|
||||
#endif
|
||||
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 +151,22 @@ namespace textinput {
|
||||
u32 GetModifierState() const;
|
||||
void SetModifierState(u32, u32);
|
||||
|
||||
#ifdef TI_PC_KEYBOARD_IMPLEMENTATION
|
||||
#if defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TISIGNWINDOW_IMPLEMENTATION) || defined(TIHWKEYBOARD_IMPLEMENTATION)
|
||||
class KeySet {
|
||||
public:
|
||||
u8 GetKey() const;
|
||||
#ifdef TIHWKEYBOARD_IMPLEMENTATION
|
||||
u32 GetWChar() const;
|
||||
#else
|
||||
wchar_t GetWChar() const;
|
||||
#endif
|
||||
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) {}
|
||||
#ifdef TIHWKEYBOARD_IMPLEMENTATION
|
||||
KeySet() : mpManager(NULL), mKind(0), mIndex(-1), mDevice(0), mCharacter(0) {}
|
||||
#endif
|
||||
private:
|
||||
const HKBManager* mpManager;
|
||||
u8 mKind;
|
||||
@@ -35,6 +176,9 @@ namespace textinput {
|
||||
};
|
||||
KeySet GetTriggeredKeySet() const;
|
||||
KeySet GetRepeatedKeySet() const;
|
||||
#ifdef TIHWKEYBOARD_IMPLEMENTATION
|
||||
KeySet GetReleasedKeySet() const;
|
||||
#endif
|
||||
void SetForceModifierState(u32 mask, u32 state);
|
||||
#else
|
||||
class KeySet {
|
||||
@@ -43,14 +187,28 @@ namespace textinput {
|
||||
wchar_t szKeySetName[17]; // 0x04
|
||||
u16 uNum; // 0x26
|
||||
u16 uType; // 0x28
|
||||
|
||||
#ifdef TI_CELLPHONE_IMPLEMENTATION
|
||||
public:
|
||||
bool IsValid() const;
|
||||
u32 GetKey() const;
|
||||
wchar_t GetWChar() const;
|
||||
KeySet GetNext() const;
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef TI_CELLPHONE_IMPLEMENTATION
|
||||
KeySet GetTriggeredKeySet() const;
|
||||
KeySet GetRepeatedKeySet() const;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
private:
|
||||
u8 unk_0x00[0xFC];
|
||||
|
||||
static HKBManager sInstance;
|
||||
};
|
||||
#endif
|
||||
} // namespace input
|
||||
} // namespace textinput
|
||||
|
||||
|
||||
@@ -8,24 +8,43 @@ 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
|
||||
#if defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TIHWKEYBOARD_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:
|
||||
#ifdef TIHWKEYBOARD_IMPLEMENTATION
|
||||
bool updateRepeatKey_(input::HKBManager&);
|
||||
bool updateTriggerKey_(input::HKBManager&);
|
||||
bool updateTappingShift_(input::HKBManager&);
|
||||
#endif
|
||||
void updateShift(input::HKBManager& hkbManager);
|
||||
void controlKeyTriggeredHandler(input::HKBManager);
|
||||
|
||||
@@ -33,8 +52,18 @@ namespace textinput {
|
||||
|
||||
Manager* mpManager; // 0x10
|
||||
u8 field_0x14; // 0x14
|
||||
#ifdef TIINPUTFORM_IMPLEMENTATION
|
||||
u8 mbSingleQuoteClosing;
|
||||
u8 mbDoubleQuoteClosing;
|
||||
#else
|
||||
#ifdef TIHWKEYBOARD_IMPLEMENTATION
|
||||
bool field_0x15;
|
||||
bool field_0x16;
|
||||
#else
|
||||
u8 field_0x15; // 0x15
|
||||
u8 field_0x16; // 0x16
|
||||
#endif
|
||||
#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,42 @@ 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(TIHWKEYBOARD_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(TIHWKEYBOARD_IMPLEMENTATION)) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISIGNWINDOW_IMPLEMENTATION)
|
||||
virtual void onKey(u32, void*);
|
||||
#else
|
||||
virtual void onKey(u32);
|
||||
#endif
|
||||
#ifdef TI_PC_KEYBOARD_IMPLEMENTATION
|
||||
#ifdef TI_CELLPHONE_IMPLEMENTATION
|
||||
virtual u32 getType();
|
||||
#elif (defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TIHWKEYBOARD_IMPLEMENTATION)) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISIGNWINDOW_IMPLEMENTATION)
|
||||
virtual int getType();
|
||||
#else
|
||||
virtual void getType();
|
||||
#endif
|
||||
#ifdef TI_CELLPHONE_IMPLEMENTATION
|
||||
virtual void setLanguage(Language language) { meLanguage = language; }
|
||||
#else
|
||||
virtual void setLanguage(Language language);
|
||||
#ifdef TI_PC_KEYBOARD_IMPLEMENTATION
|
||||
#endif
|
||||
#if (defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TIHWKEYBOARD_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,18 +103,26 @@ 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() {}
|
||||
|
||||
#ifdef TIHWKEYBOARD_IMPLEMENTATION
|
||||
EventObserver* getEventObserverForHardware() const { return mpEventObserver; }
|
||||
#endif
|
||||
virtual InputForm* getInputForm() { return mpInputForm; }
|
||||
virtual const InputForm* getInputForm() const { return mpInputForm; }
|
||||
|
||||
@@ -146,6 +163,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 +180,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(TIHWKEYBOARD_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,
|
||||
@@ -61,7 +65,11 @@ namespace textinput {
|
||||
virtual void init() override;
|
||||
virtual void updateFromReceiver(u32, void*) override;
|
||||
virtual void onKey(u32, void*) override;
|
||||
#ifdef TI_CELLPHONE_IMPLEMENTATION
|
||||
virtual u32 getType() override;
|
||||
#else
|
||||
virtual void getType() override;
|
||||
#endif
|
||||
virtual void setLanguage(Language) override;
|
||||
virtual void onActive() override;
|
||||
virtual void inputCharCode(u16);
|
||||
@@ -126,7 +134,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 +144,9 @@ namespace textinput {
|
||||
u32 mCurrentInputType;
|
||||
u32 mInputState;
|
||||
const void* mpLanguageData;
|
||||
#ifdef TIINPUTFORM_IMPLEMENTATION
|
||||
MEMAllocator* mpAllocator;
|
||||
#endif
|
||||
bool mbOnlyQwerty;
|
||||
bool mbLanguageKeyActive;
|
||||
u16 mKeyboardFlags;
|
||||
@@ -143,6 +154,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 +166,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 +186,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();
|
||||
@@ -152,6 +226,12 @@ namespace textinput {
|
||||
State mState;
|
||||
const LanguageData* mpInitialLanguageData;
|
||||
KeyState mKeyState;
|
||||
#ifdef TIHWKEYBOARD_IMPLEMENTATION
|
||||
public:
|
||||
KeyState& hardwareKeyState() { return mKeyState; }
|
||||
bool hardwareLanguageKeyActive() const { return mbLanguageKeyActive; }
|
||||
protected:
|
||||
#endif
|
||||
MEMAllocator* mpAllocator;
|
||||
bool mbOnlyQwerty;
|
||||
bool mbLanguageKeyActive;
|
||||
@@ -159,46 +239,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 +268,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 +295,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 +352,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,14 @@ namespace textinput {
|
||||
class CommandSender;
|
||||
class CommandReceiver : public Base {
|
||||
public:
|
||||
#ifdef MYTIINPUTFORM_IMPLEMENTATION
|
||||
#ifdef TI_CELLPHONE_IMPLEMENTATION
|
||||
struct ChangePredictMode;
|
||||
#endif
|
||||
#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 +73,7 @@ namespace textinput {
|
||||
INPUT_COMMAND_37 = 37,
|
||||
} INPUT_COMMAND;
|
||||
|
||||
#ifdef TI_PC_KEYBOARD_IMPLEMENTATION
|
||||
#if (defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TIHWKEYBOARD_IMPLEMENTATION)) || defined(TIMANAGER_IMPLEMENTATION) || defined(TISIGNWINDOW_IMPLEMENTATION)
|
||||
struct ChangePredictMode { u32 mode; bool enabled; };
|
||||
#endif
|
||||
virtual void clearSender();
|
||||
@@ -78,7 +89,7 @@ namespace textinput {
|
||||
CommandSender() : mpCommandReceiver(NULL) {}
|
||||
|
||||
virtual void setCommandReceiver(CommandReceiver* cmdRecv);
|
||||
#ifdef TI_PC_KEYBOARD_IMPLEMENTATION
|
||||
#if (defined(TI_PC_KEYBOARD_IMPLEMENTATION) || defined(TIHWKEYBOARD_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) {}
|
||||
@@ -52,10 +56,19 @@ namespace textinput {
|
||||
virtual void onOK();
|
||||
virtual void onCancel();
|
||||
virtual void setQwertyWithSE(bool qwerty);
|
||||
#ifdef TI_CELLPHONE_IMPLEMENTATION
|
||||
virtual bool isEnableKeytopChange() const { return mbIsEnableQwertyChg; }
|
||||
#else
|
||||
virtual bool isEnableKeytopChange() const;
|
||||
#endif
|
||||
virtual void enableKeytopChange(bool enable);
|
||||
#ifdef MYTIMANAGER_MATCHING
|
||||
virtual nw4r::lyt::Pane* getDownArea();
|
||||
virtual nw4r::lyt::Pane* getUpArea();
|
||||
#else
|
||||
virtual nw4r::lyt::Pane* getUpArea();
|
||||
virtual nw4r::lyt::Pane* getDownArea();
|
||||
#endif
|
||||
virtual void setOKButtonVisible(bool visible);
|
||||
virtual void setCancelButtonVisible(bool visible);
|
||||
virtual void setOKButtonCaption(const wchar_t* caption);
|
||||
@@ -117,12 +130,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:
|
||||
|
||||
41
libs/MSL/include/internal/format_runtime.h
Normal file
41
libs/MSL/include/internal/format_runtime.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef MSL_FORMAT_RUNTIME_H
|
||||
#define MSL_FORMAT_RUNTIME_H
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <internal/locale.h>
|
||||
#define SIGDIGLEN 36
|
||||
#define LDBL_MANT_DIG 53
|
||||
#define LDBL_MAX_EXP 1024
|
||||
#define LDBL_MIN_EXP (-1021)
|
||||
#define DBL_MAX 1.7976931348623157e308
|
||||
#define DBL_MIN 2.2250738585072014e-308
|
||||
#define DBL_EPSILON 2.2204460492503131e-16
|
||||
#define EOF (-1)
|
||||
typedef long ptrdiff_t;
|
||||
typedef long long intmax_t;
|
||||
typedef unsigned long long uintmax_t;
|
||||
typedef struct {
|
||||
char sign;
|
||||
short exp;
|
||||
struct { unsigned char length; unsigned char text[SIGDIGLEN]; } sig;
|
||||
} decimal;
|
||||
typedef struct { char style; short digits; } decform;
|
||||
enum __ReadProcActions { __GetAChar, __UngetAChar, __TestForError };
|
||||
typedef struct { char* CharStr; size_t MaxCharCount; size_t CharsWritten; } __OutStrCtrl;
|
||||
typedef struct { char* NextChar; int NullCharDetected; } __InStrCtrl;
|
||||
void __num2dec(const decform*, double, decimal*);
|
||||
double __dec2num(const decimal*);
|
||||
size_t __fwrite(const void*, size_t, size_t, FILE*);
|
||||
int __StringRead(void*, int, int);
|
||||
unsigned long __strtoul(int, int, int (*)(void*, int, int), void*, int*, int*, int*);
|
||||
unsigned long long __strtoull(int, int, int (*)(void*, int, int), void*, int*, int*, int*);
|
||||
long double __strtold(int, int (*)(void*, int, int), void*, int*, int*);
|
||||
int wctomb(char*, wchar_t);
|
||||
double nan(const char*);
|
||||
#define signbit(x) __signbitd(x)
|
||||
#endif
|
||||
88
libs/MSL/matching-attempts.log
Normal file
88
libs/MSL/matching-attempts.log
Normal file
@@ -0,0 +1,88 @@
|
||||
MSL restoration, 43U, baseline 0 exact functions and 0 matched code/data in all six units.
|
||||
Sources: zeldaret/tp MSL printf/wprintf; public Mario Strikers Charged MSL decimal/scanning/strtold references in /tmp/mscharged-new; time reference experiments in /tmp. All measurements were rebuilt locally.
|
||||
|
||||
printf long2str: corrected 32-bit minimum constant; 138/138 instructions, zero differences.
|
||||
printf float2str: removed unnecessary short narrowing from exponent update; 500/500 instructions, zero differences.
|
||||
printf double2hex:
|
||||
1. Deferred output pointer initialization until after width validation: 242/242, 97 differences.
|
||||
2. Moved output pointer declaration after decimal: 242/242, same 97 differences.
|
||||
3. Copied incoming format into a local format: 244/242 and larger frame; rejected.
|
||||
4. Reconstructed the actual zero-value path and ordinary literal 0x0p0 from target assembly.
|
||||
5. Corrected unconditional exponent subtraction and explicit byte narrowing based on target assembly. Remaining struct argument copies use floating loads/stores instead of integer loads/stores; conversion-loop scheduling differs.
|
||||
printf __pformatter:
|
||||
1. Moved format declaration after buffers: 535/535, same 321 differences.
|
||||
2. Initialized format to zero: 540/535, additional stores; rejected.
|
||||
3. Copied parsed format before dispatch, with both locals declared at function entry: 515/535 after target semantic fixes, larger frame; rejected.
|
||||
4. Removed hex-prefix zero-fill handling absent from this binary. Remaining mismatch is by-value struct copy code generation; target has 535 instructions, source 511.
|
||||
|
||||
wprintf double2hex:
|
||||
1. Used the Charged reference implementation: 246/242, different frame/scheduling; rejected.
|
||||
2. Deferred output pointer initialization: 243/242, register and copy differences remained.
|
||||
3. Moved output pointer declaration after decimal: 243/242, unchanged differences.
|
||||
4. Reconstructed zero-value output and unconditional exponent subtraction from target assembly. Explicit byte narrowing improved conversion instructions; struct-copy and loop scheduling remain open.
|
||||
wprintf __wpformatter:
|
||||
1. Initialized local format: 596/593, additional stores; rejected.
|
||||
2. Moved format declaration after buffers: 591/593, changed scheduling; rejected.
|
||||
3. Copied parsed format before dispatch: 595/593, larger frame; rejected.
|
||||
4. Corrected the imported narrow Pascal-string branch to read and advance its actual input pointer, eliminating an uninitialized output-pointer read.
|
||||
5. Removed hex-prefix zero-fill handling absent from the target. Remaining struct-copy code generation and register scheduling differ.
|
||||
wprintf __wStringWrite: used the real callback result from wmemcpy; 27/27 instructions, zero differences.
|
||||
|
||||
ansi_fp: all ten functions have zero ctxdiff differences. Exception metadata enabled for this unit, using the same setting as matching MSL siblings. Code 6512/6512 and data 780/780.
|
||||
|
||||
time strftime:
|
||||
1. Assigned default calendar fields individually: 906/913, scheduling differences; rejected.
|
||||
2. Initialized the default calendar at declaration: 913/913, 34 remaining string-offset differences; retained.
|
||||
3. Moved format-pointer declaration before locale: 913/913, 76 differences; rejected.
|
||||
4. Replaced imported pooled-string address arithmetic with ordinary literals. Reconstructed real asctime/ctime formatting to account for the original literals, rather than retaining fake calls with missing format arguments.
|
||||
5. With ordinary source-token order restored, strftime has 913/913 instructions and zero ctxdiff differences. Keeping the shared asctime result local to asctime restored the target BSS symbols; exception records for the additional real library functions still differ at unit level. No padding or forced placement was added.
|
||||
|
||||
scanf: all four functions have zero ctxdiff differences, code 5484/5484 and data 388/388. The formatter retains its actual secure-mode parameter.
|
||||
strtold: __strtold has 1277/1277 instructions and strtod 44/44, both zero differences. Removed the imported inline qualifier from the public strtod wrapper so the real target symbol is emitted. Code 5284/5284 and data 112/112.
|
||||
|
||||
Exception metadata settings change only owned NonMatching units; configure.py status flags remain NonMatching. Clean gates require the original DOL SHA1 and zero baseline regressions. Raw instruction-exact counts can be lower than objdiff exact counts because the varargs conditional branch to an external register-save helper is compared without relocation normalization by gate.py. These counts are reported separately; they were not patched or hidden.
|
||||
printf::double2hex: aggregate exponent format initialized at declaration: 238/242 instructions, 227 positional diffs; restored.
|
||||
printf::double2hex: initialize exponent integer fields before byte flags: 241/242 instructions, 127 positional diffs; restored.
|
||||
printf::double2hex: use integer nibble temporary with explicit final narrowing: 239/242 instructions, 123 positional diffs; restored.
|
||||
printf::__pformatter: move parsed format declaration after output buffer: 511/535 instructions, 367 positional diffs; restored.
|
||||
printf::__pformatter: initialize parsed format before first parse: 516/535 instructions, 505 positional diffs; restored.
|
||||
printf::__pformatter: separate next-format pointer from parsed cursor: 511/535 instructions, 367 positional diffs; restored.
|
||||
wprintf::double2hex: aggregate exponent format initialized at declaration: 238/242 instructions, 227 positional diffs; restored.
|
||||
wprintf::double2hex: initialize exponent integer fields before byte flags: 241/242 instructions, 127 positional diffs; restored.
|
||||
wprintf::double2hex: use integer nibble temporary with explicit final narrowing: 239/242 instructions, 123 positional diffs; restored.
|
||||
wprintf::__wpformatter: move parsed format declaration after output buffer: 567/593 instructions, 519 positional diffs; restored.
|
||||
wprintf::__wpformatter: initialize parsed format before first parse: 572/593 instructions, 562 positional diffs; restored.
|
||||
wprintf::__wpformatter: separate next-format pointer from parsed cursor: 567/593 instructions, 519 positional diffs; restored.
|
||||
printf::printf: finish varargs lifetime with va_end: compile rejected: ninja: build stopped: subcommand failed.; restored.
|
||||
printf::printf: return through named result temporary: compile rejected: ninja: build stopped: subcommand failed.; restored.
|
||||
printf::printf: move va_start to first actual formatting use: 50/50 instructions, 1 positional diffs; restored.
|
||||
printf::fprintf: finish varargs lifetime with va_end: compile rejected: ninja: build stopped: subcommand failed.; restored.
|
||||
printf::fprintf: return through named result temporary: compile rejected: ninja: build stopped: subcommand failed.; restored.
|
||||
printf::fprintf: move va_start to first actual formatting use: 49/49 instructions, 1 positional diffs; restored.
|
||||
printf::printf: finish varargs lifetime / initialize controller first: 50/50 instructions, 1 positional diffs; restored.
|
||||
printf::printf: hoist argument list / named result: 50/50 instructions, 1 positional diffs; restored.
|
||||
printf::printf: argument-list pointer / delay va_start: 50/50 instructions, 1 positional diffs; restored.
|
||||
printf::fprintf: finish varargs lifetime / initialize controller first: 49/49 instructions, 1 positional diffs; restored.
|
||||
printf::fprintf: hoist argument list / named result: 49/49 instructions, 1 positional diffs; restored.
|
||||
printf::fprintf: argument-list pointer / delay va_start: 49/49 instructions, 1 positional diffs; restored.
|
||||
printf::snprintf: finish varargs lifetime / initialize controller first: 54/54 instructions, 1 positional diffs; restored.
|
||||
printf::snprintf: hoist argument list / named result: 54/54 instructions, 1 positional diffs; restored.
|
||||
printf::snprintf: argument-list pointer / delay va_start: 54/54 instructions, 1 positional diffs; restored.
|
||||
printf::sprintf: finish varargs lifetime / initialize controller first: 52/52 instructions, 1 positional diffs; restored.
|
||||
printf::sprintf: hoist argument list / named result: 52/52 instructions, 1 positional diffs; restored.
|
||||
printf::sprintf: argument-list pointer / delay va_start: 52/52 instructions, 1 positional diffs; restored.
|
||||
wprintf::swprintf: finish varargs lifetime / initialize controller first: 55/55 instructions, 1 positional diffs; restored.
|
||||
wprintf::swprintf: hoist argument list / named result: 55/55 instructions, 1 positional diffs; restored.
|
||||
wprintf::swprintf: argument-list pointer / delay va_start: 55/55 instructions, 11 positional diffs; restored.
|
||||
time::emit: finish varargs lifetime / initialize controller first: 43/43 instructions, 1 positional diffs; restored.
|
||||
time::emit: hoist argument list / named result: 43/43 instructions, 1 positional diffs; restored.
|
||||
time::emit: argument-list pointer / delay va_start: 42/43 instructions, 34 positional diffs; restored.
|
||||
|
||||
printf data: 139/148 relocation entries agree by target function and addend; dispatch-table entries in the unmatched formatter still differ. Generated jump-table data is retained, without manual entries or symbol mappings.
|
||||
wprintf data: 139/148 relocation entries agree by target function and addend; dispatch-table entries in the unmatched formatter still differ. Generated jump-table data is retained, without manual entries or symbol mappings.
|
||||
printf double2hex: moved exponent-format initialization after exponent extraction: 241/242 instructions; FP aggregate copies remained; restored.
|
||||
wprintf double2hex: moved exponent-format initialization after exponent extraction: 241/242 instructions; FP aggregate copies remained; restored.
|
||||
printf data: changed zero comparison literal to long double, matching the argument type and sharing its zero constant with float2str. .sdata2 now 8 bytes, 100%, versus 16 emitted bytes previously. Instruction scores unchanged.
|
||||
time data: literal pool, calendar tables and BSS already agree. Target has nine exception-index records; source includes exception records for real public asctime/ctime functions absent in the extracted target. Retained the functions rather than suppressing output.
|
||||
locale: restored the C locale components, collation table and ordinary literals in source order; all 792 data bytes exact. No target code functions exist.
|
||||
file_io: implemented fclose, fflush, __msl_strnicmp and __msl_itoa in object order using FILE fields and named arithmetic temporaries; all four have zero ctxdiff differences, 928 code bytes and 60 metadata bytes exact.
|
||||
160
libs/MSL/src/MSL_Common/file_io.c
Normal file
160
libs/MSL/src/MSL_Common/file_io.c
Normal file
@@ -0,0 +1,160 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
enum file_kinds { file_closed, file_disk, file_console, file_unavailable };
|
||||
enum io_states { neutral, writing, reading, rereading };
|
||||
enum io_modes { io_read = 1, io_write = 2, io_append = 4 };
|
||||
extern int __flush_all(void);
|
||||
extern int __flush_buffer(FILE*, size_t*);
|
||||
|
||||
#pragma exceptions on
|
||||
|
||||
int fclose(FILE* file)
|
||||
{
|
||||
int flush_result, close_result;
|
||||
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
if (file->mode.file_kind == file_closed)
|
||||
return 0;
|
||||
|
||||
flush_result = fflush(file);
|
||||
|
||||
close_result = (*file->close_proc)(file->handle);
|
||||
|
||||
file->mode.file_kind = file_closed;
|
||||
file->handle = 0;
|
||||
|
||||
if (file->state.free_buffer)
|
||||
free((FILE*)file->buffer);
|
||||
return (flush_result || close_result) ? -1 : 0;
|
||||
}
|
||||
|
||||
int fflush(FILE* file)
|
||||
{
|
||||
int pos;
|
||||
|
||||
if (file == NULL)
|
||||
{
|
||||
return __flush_all();
|
||||
}
|
||||
|
||||
if (file->state.error != 0 || file->mode.file_kind == file_closed)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (file->mode.io_mode == io_read)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (file->state.io_state >= rereading)
|
||||
{
|
||||
file->state.io_state = reading;
|
||||
}
|
||||
|
||||
if (file->state.io_state == reading)
|
||||
{
|
||||
file->buffer_len = 0;
|
||||
}
|
||||
|
||||
if (file->state.io_state != writing)
|
||||
{
|
||||
file->state.io_state = neutral;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (file->mode.file_kind != file_disk)
|
||||
{
|
||||
pos = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = ftell(file);
|
||||
}
|
||||
|
||||
if (__flush_buffer(file, NULL) != 0)
|
||||
{
|
||||
file->state.error = 1;
|
||||
file->buffer_len = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
file->state.io_state = neutral;
|
||||
file->pos = pos;
|
||||
file->buffer_len = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __msl_strnicmp(const char* str1, const char* str2, int n)
|
||||
{
|
||||
int i;
|
||||
char c1, c2;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
c1 = tolower(*str1++);
|
||||
c2 = tolower(*str2++);
|
||||
|
||||
if (c1 < c2)
|
||||
return -1;
|
||||
|
||||
if (c1 > c2)
|
||||
return 1;
|
||||
|
||||
if (c1 == '\0')
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* __msl_itoa(int value, char* str, unsigned int base)
|
||||
{
|
||||
int negative;
|
||||
int length;
|
||||
char c;
|
||||
int start;
|
||||
int end;
|
||||
|
||||
negative = 0;
|
||||
length = 0;
|
||||
|
||||
if (value < 0)
|
||||
{
|
||||
value = -value;
|
||||
negative = 1;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
int digit = value % base;
|
||||
|
||||
if (digit > 9)
|
||||
str[length++] = digit + 0x37;
|
||||
else
|
||||
str[length++] = digit + 0x30;
|
||||
|
||||
value /= base;
|
||||
} while (value != 0);
|
||||
|
||||
if (negative != 0)
|
||||
str[length++] = '-';
|
||||
|
||||
str[length++] = '\0';
|
||||
|
||||
start = 0;
|
||||
end = strlen(str) - 1;
|
||||
|
||||
while (start < end)
|
||||
{
|
||||
c = str[start];
|
||||
str[start++] = str[end];
|
||||
str[end--] = c;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
123
libs/MSL/src/MSL_Common/locale.c
Normal file
123
libs/MSL/src/MSL_Common/locale.c
Normal file
@@ -0,0 +1,123 @@
|
||||
#include <internal/locale.h>
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
|
||||
extern int __mbtowc_noconv(wchar_t*, const char*, size_t);
|
||||
extern int __wctomb_noconv(char*, wchar_t);
|
||||
|
||||
struct lconv __lconv = {
|
||||
".",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
CHAR_MAX,
|
||||
CHAR_MAX,
|
||||
CHAR_MAX,
|
||||
CHAR_MAX,
|
||||
CHAR_MAX,
|
||||
CHAR_MAX,
|
||||
CHAR_MAX,
|
||||
"",
|
||||
CHAR_MAX,
|
||||
CHAR_MAX,
|
||||
CHAR_MAX,
|
||||
CHAR_MAX,
|
||||
CHAR_MAX,
|
||||
CHAR_MAX,
|
||||
CHAR_MAX,
|
||||
};
|
||||
|
||||
extern const unsigned short __ctype_mapC[256];
|
||||
extern const unsigned char __upper_mapC[256];
|
||||
extern const unsigned char __lower_mapC[256];
|
||||
extern const unsigned short __wctype_mapC[256];
|
||||
extern const wchar_t __wupper_mapC[256];
|
||||
extern const wchar_t __wlower_mapC[256];
|
||||
|
||||
struct _loc_ctype_cmpt _loc_ctyp_C = {
|
||||
"C",
|
||||
__ctype_mapC,
|
||||
__upper_mapC,
|
||||
__lower_mapC,
|
||||
__wctype_mapC,
|
||||
__wupper_mapC,
|
||||
__wlower_mapC,
|
||||
__mbtowc_noconv,
|
||||
__wctomb_noconv
|
||||
};
|
||||
|
||||
unsigned short char_coll_tableC[96] = {
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||
41, 42, 17, 18, 19, 20, 21, 22, 23, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71,
|
||||
73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 24, 25, 26, 27, 28, 0, 44, 46, 48, 50, 52, 54, 56,
|
||||
58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 29, 30, 31, 32, 0,
|
||||
};
|
||||
|
||||
struct _loc_coll_cmpt _loc_coll_C = {
|
||||
"C",
|
||||
' ',
|
||||
110,
|
||||
0,
|
||||
char_coll_tableC,
|
||||
NULL
|
||||
};
|
||||
|
||||
struct _loc_mon_cmpt _loc_mon_C = {
|
||||
"C",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
CHAR_MAX,
|
||||
CHAR_MAX,
|
||||
CHAR_MAX,
|
||||
CHAR_MAX,
|
||||
CHAR_MAX,
|
||||
CHAR_MAX,
|
||||
CHAR_MAX,
|
||||
"",
|
||||
CHAR_MAX,
|
||||
CHAR_MAX,
|
||||
CHAR_MAX,
|
||||
CHAR_MAX,
|
||||
CHAR_MAX,
|
||||
CHAR_MAX,
|
||||
CHAR_MAX
|
||||
};
|
||||
|
||||
struct _loc_num_cmpt _loc_num_C = {
|
||||
"C",
|
||||
".",
|
||||
"",
|
||||
""
|
||||
};
|
||||
|
||||
struct _loc_time_cmpt _loc_tim_C = {
|
||||
"C",
|
||||
"AM|PM",
|
||||
"%a %b %e %T %Y",
|
||||
"%I:%M:%S %p",
|
||||
"%m/%d/%y",
|
||||
"%T",
|
||||
"Sun|Sunday|Mon|Monday|Tue|Tuesday|Wed|Wednesday|Thu|Thursday|Fri|Friday|Sat|Saturday",
|
||||
"Jan|January|Feb|February|Mar|March|Apr|April|May|May|Jun|June|Jul|July|Aug|August|Sep|September|Oct|October|Nov|"
|
||||
"November|Dec|December",
|
||||
""
|
||||
};
|
||||
|
||||
struct __locale _current_locale = {
|
||||
NULL,
|
||||
"C",
|
||||
&_loc_coll_C,
|
||||
&_loc_ctyp_C,
|
||||
&_loc_mon_C,
|
||||
&_loc_num_C,
|
||||
&_loc_tim_C
|
||||
};
|
||||
1360
libs/MSL/src/MSL_Common/printf.c
Normal file
1360
libs/MSL/src/MSL_Common/printf.c
Normal file
File diff suppressed because it is too large
Load Diff
817
libs/MSL/src/MSL_Common/scanf.c
Normal file
817
libs/MSL/src/MSL_Common/scanf.c
Normal file
@@ -0,0 +1,817 @@
|
||||
#include <internal/format_runtime.h>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef long long intmax_t;
|
||||
|
||||
enum argument_options {
|
||||
normal_argument,
|
||||
char_argument,
|
||||
short_argument,
|
||||
long_argument,
|
||||
intmax_argument,
|
||||
size_t_argument,
|
||||
ptrdiff_argument,
|
||||
long_long_argument,
|
||||
double_argument,
|
||||
long_double_argument,
|
||||
wchar_argument
|
||||
};
|
||||
|
||||
typedef unsigned char char_map[32];
|
||||
|
||||
typedef struct {
|
||||
unsigned char suppress_assignment;
|
||||
unsigned char field_width_specified;
|
||||
unsigned char argument_options;
|
||||
unsigned char conversion_char;
|
||||
int field_width;
|
||||
char_map char_set;
|
||||
} scan_format;
|
||||
|
||||
#define set_char_map(map, ch) map[(unsigned char)ch >> 3] |= (1 << (ch & 7))
|
||||
#define tst_char_map(map, ch) (map[(unsigned char)ch >> 3] & (1 << (ch & 7)))
|
||||
|
||||
static const char* parse_format(const char* format_string, scan_format* format) {
|
||||
const char* s = format_string;
|
||||
int c;
|
||||
int flag_found, invert;
|
||||
scan_format f = {0, 0, normal_argument, 0, 2147483647, {0}};
|
||||
|
||||
if (((c = *++s) == '%')) {
|
||||
f.conversion_char = c;
|
||||
*format = f;
|
||||
return s + 1;
|
||||
}
|
||||
|
||||
if (c == '*') {
|
||||
f.suppress_assignment = 1;
|
||||
c = *++s;
|
||||
}
|
||||
|
||||
if (isdigit(c)) {
|
||||
f.field_width = 0;
|
||||
|
||||
do {
|
||||
f.field_width = (f.field_width * 10) + (c - '0');
|
||||
c = *++s;
|
||||
} while (isdigit(c));
|
||||
|
||||
if (f.field_width == 0) {
|
||||
f.conversion_char = 0xFF;
|
||||
*format = f;
|
||||
return s + 1;
|
||||
}
|
||||
|
||||
f.field_width_specified = 1;
|
||||
}
|
||||
|
||||
flag_found = 1;
|
||||
|
||||
switch (c) {
|
||||
case 'h':
|
||||
f.argument_options = short_argument;
|
||||
|
||||
if (s[1] == 'h') {
|
||||
f.argument_options = char_argument;
|
||||
c = *++s;
|
||||
}
|
||||
|
||||
break;
|
||||
case 'l':
|
||||
f.argument_options = long_argument;
|
||||
|
||||
if (s[1] == 'l') {
|
||||
f.argument_options = long_long_argument;
|
||||
c = *++s;
|
||||
}
|
||||
|
||||
break;
|
||||
case 'L':
|
||||
f.argument_options = long_double_argument;
|
||||
break;
|
||||
|
||||
case 'j':
|
||||
f.argument_options = intmax_argument;
|
||||
break;
|
||||
case 'z':
|
||||
f.argument_options = size_t_argument;
|
||||
break;
|
||||
case 't':
|
||||
f.argument_options = ptrdiff_argument;
|
||||
break;
|
||||
default:
|
||||
flag_found = 0;
|
||||
}
|
||||
|
||||
if (flag_found) {
|
||||
c = *++s;
|
||||
}
|
||||
|
||||
f.conversion_char = c;
|
||||
|
||||
switch (c) {
|
||||
case 'd':
|
||||
case 'i':
|
||||
case 'u':
|
||||
case 'o':
|
||||
case 'x':
|
||||
case 'X':
|
||||
if (f.argument_options == long_double_argument) {
|
||||
f.conversion_char = 0xFF;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
case 'A':
|
||||
case 'f':
|
||||
case 'F':
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'g':
|
||||
case 'G':
|
||||
if (f.argument_options == char_argument || f.argument_options == short_argument ||
|
||||
f.argument_options == intmax_argument || f.argument_options == size_t_argument ||
|
||||
f.argument_options == ptrdiff_argument || f.argument_options == long_long_argument) {
|
||||
f.conversion_char = 0xFF;
|
||||
break;
|
||||
}
|
||||
|
||||
if (f.argument_options == long_argument) {
|
||||
f.argument_options = double_argument;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
f.argument_options = long_argument;
|
||||
f.conversion_char = 'x';
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
if (f.argument_options == long_argument) {
|
||||
f.argument_options = wchar_argument;
|
||||
} else {
|
||||
if (f.argument_options != normal_argument) {
|
||||
f.conversion_char = 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 's':
|
||||
if (f.argument_options == long_argument) {
|
||||
f.argument_options = wchar_argument;
|
||||
} else {
|
||||
if (f.argument_options != normal_argument) {
|
||||
f.conversion_char = 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
int i;
|
||||
unsigned char* p;
|
||||
|
||||
for (i = sizeof(f.char_set), p = f.char_set; i; --i) {
|
||||
*p++ = 0xFF;
|
||||
}
|
||||
|
||||
f.char_set[1] = 0xC1;
|
||||
f.char_set[4] = 0xFE;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
break;
|
||||
|
||||
case '[':
|
||||
if (f.argument_options == long_argument) {
|
||||
f.argument_options = wchar_argument;
|
||||
} else {
|
||||
if (f.argument_options != normal_argument) {
|
||||
f.conversion_char = 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
c = *++s;
|
||||
invert = 0;
|
||||
|
||||
if (c == '^') {
|
||||
invert = 1;
|
||||
c = *++s;
|
||||
}
|
||||
|
||||
if (c == ']') {
|
||||
set_char_map(f.char_set, ']');
|
||||
c = *++s;
|
||||
}
|
||||
|
||||
while (c && c != ']') {
|
||||
int d;
|
||||
set_char_map(f.char_set, c);
|
||||
|
||||
if (*(s + 1) == '-' && (d = *(s + 2)) != 0 && d != ']') {
|
||||
while (++c <= d) {
|
||||
set_char_map(f.char_set, c);
|
||||
}
|
||||
|
||||
c = *(s += 3);
|
||||
} else {
|
||||
c = *++s;
|
||||
}
|
||||
}
|
||||
|
||||
if (!c) {
|
||||
f.conversion_char = 0xFF;
|
||||
break;
|
||||
}
|
||||
|
||||
if (invert) {
|
||||
int i;
|
||||
unsigned char* p;
|
||||
|
||||
for (i = sizeof(f.char_set), p = f.char_set; i; --i, ++p) {
|
||||
*p = ~*p;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
f.conversion_char = 0xFF;
|
||||
break;
|
||||
}
|
||||
|
||||
*format = f;
|
||||
return s + 1;
|
||||
}
|
||||
|
||||
int __sformatter(int (*ReadProc)(void*, int, int), void* ReadProcArg, const char* format_str, va_list arg,
|
||||
int is_secure) {
|
||||
int num_chars, chars_read, items_assigned, conversions;
|
||||
int base, negative, overflow;
|
||||
int rval;
|
||||
const char* format_ptr;
|
||||
char format_char;
|
||||
char c;
|
||||
scan_format format;
|
||||
long long_num;
|
||||
unsigned long u_long_num;
|
||||
long long long_long_num = 0;
|
||||
unsigned long long u_long_long_num;
|
||||
long double long_double_num;
|
||||
char* arg_ptr;
|
||||
int elem_valid;
|
||||
size_t elem_maxsize;
|
||||
int match_failure = 0;
|
||||
int terminate = 0;
|
||||
|
||||
format_ptr = format_str;
|
||||
chars_read = 0;
|
||||
items_assigned = 0;
|
||||
conversions = 0;
|
||||
|
||||
while (!terminate && (format_char = *format_ptr) != 0) {
|
||||
if (isspace(format_char)) {
|
||||
do {
|
||||
format_char = *++format_ptr;
|
||||
} while (isspace(format_char));
|
||||
|
||||
if (!match_failure) {
|
||||
while (isspace(c = (*ReadProc)(ReadProcArg, 0, __GetAChar))) {
|
||||
++chars_read;
|
||||
}
|
||||
|
||||
(*ReadProc)(ReadProcArg, c, __UngetAChar);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((format_char != '%') && (!match_failure)) {
|
||||
if ((c = (*ReadProc)(ReadProcArg, 0, __GetAChar)) != (unsigned char)format_char) {
|
||||
(*ReadProc)(ReadProcArg, c, __UngetAChar);
|
||||
if (!is_secure) {
|
||||
goto exit;
|
||||
} else {
|
||||
match_failure = 1;
|
||||
++format_ptr;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
chars_read++;
|
||||
format_ptr++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
format_ptr = parse_format(format_ptr, &format);
|
||||
|
||||
if (!format.suppress_assignment && format.conversion_char != '%') {
|
||||
arg_ptr = va_arg(arg, char*);
|
||||
} else {
|
||||
arg_ptr = 0;
|
||||
}
|
||||
|
||||
if ((format.conversion_char != 'n') && (!match_failure) && (*ReadProc)(ReadProcArg, 0, __TestForError)) {
|
||||
if (!is_secure) {
|
||||
goto exit;
|
||||
} else {
|
||||
match_failure = 1;
|
||||
}
|
||||
}
|
||||
|
||||
switch (format.conversion_char) {
|
||||
case 'd':
|
||||
base = 10;
|
||||
goto signed_int;
|
||||
case 'i':
|
||||
base = 0;
|
||||
signed_int:
|
||||
|
||||
if (match_failure) {
|
||||
long_num = 0;
|
||||
long_long_num = 0;
|
||||
} else {
|
||||
if ((format.argument_options == long_long_argument) ||
|
||||
(format.argument_options == intmax_argument)) {
|
||||
u_long_long_num = __strtoull(base, format.field_width, ReadProc, ReadProcArg, &num_chars,
|
||||
&negative, &overflow);
|
||||
} else {
|
||||
u_long_num = __strtoul(base, format.field_width, ReadProc, ReadProcArg, &num_chars, &negative,
|
||||
&overflow);
|
||||
}
|
||||
|
||||
if (!num_chars) {
|
||||
if (!is_secure) {
|
||||
goto exit;
|
||||
} else {
|
||||
match_failure = 1;
|
||||
long_num = 0;
|
||||
long_long_num = 0;
|
||||
goto signed_int_assign;
|
||||
}
|
||||
}
|
||||
|
||||
chars_read += num_chars;
|
||||
|
||||
if ((format.argument_options == long_long_argument) ||
|
||||
(format.argument_options == intmax_argument)) {
|
||||
long_long_num = (negative ? -u_long_long_num : u_long_long_num);
|
||||
} else {
|
||||
long_num = (negative ? -u_long_num : u_long_num);
|
||||
}
|
||||
}
|
||||
|
||||
signed_int_assign:
|
||||
|
||||
if (arg_ptr) {
|
||||
switch (format.argument_options) {
|
||||
case normal_argument:
|
||||
*(int*)arg_ptr = long_num;
|
||||
break;
|
||||
case char_argument:
|
||||
*(signed char*)arg_ptr = long_num;
|
||||
break;
|
||||
case short_argument:
|
||||
*(short*)arg_ptr = long_num;
|
||||
break;
|
||||
case long_argument:
|
||||
*(long*)arg_ptr = long_num;
|
||||
break;
|
||||
case intmax_argument:
|
||||
*(intmax_t*)arg_ptr = long_long_num;
|
||||
break;
|
||||
case size_t_argument:
|
||||
*(size_t*)arg_ptr = long_num;
|
||||
break;
|
||||
case ptrdiff_argument:
|
||||
*(ptrdiff_t*)arg_ptr = long_num;
|
||||
break;
|
||||
case long_long_argument:
|
||||
*(long long*)arg_ptr = long_long_num;
|
||||
break;
|
||||
}
|
||||
if (!match_failure) {
|
||||
items_assigned++;
|
||||
}
|
||||
}
|
||||
|
||||
conversions++;
|
||||
break;
|
||||
case 'o':
|
||||
base = 8;
|
||||
goto unsigned_int;
|
||||
case 'u':
|
||||
base = 10;
|
||||
goto unsigned_int;
|
||||
case 'x':
|
||||
case 'X':
|
||||
base = 16;
|
||||
unsigned_int:
|
||||
|
||||
if (match_failure) {
|
||||
u_long_num = 0;
|
||||
u_long_long_num = 0;
|
||||
} else {
|
||||
if ((format.argument_options == long_long_argument) ||
|
||||
(format.argument_options == intmax_argument)) {
|
||||
u_long_long_num = __strtoull(base, format.field_width, ReadProc, ReadProcArg, &num_chars,
|
||||
&negative, &overflow);
|
||||
} else {
|
||||
u_long_num = __strtoul(base, format.field_width, ReadProc, ReadProcArg, &num_chars, &negative,
|
||||
&overflow);
|
||||
}
|
||||
|
||||
if (!num_chars) {
|
||||
if (!is_secure) {
|
||||
goto exit;
|
||||
} else {
|
||||
match_failure = 1;
|
||||
u_long_num = 0;
|
||||
u_long_long_num = 0;
|
||||
goto unsigned_int_assign;
|
||||
}
|
||||
}
|
||||
|
||||
chars_read += num_chars;
|
||||
|
||||
if (negative) {
|
||||
if (format.argument_options == long_long_argument) {
|
||||
u_long_long_num = -u_long_long_num;
|
||||
} else {
|
||||
u_long_num = -u_long_num;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned_int_assign:
|
||||
|
||||
if (arg_ptr) {
|
||||
switch (format.argument_options) {
|
||||
case normal_argument:
|
||||
*(unsigned int*)arg_ptr = u_long_num;
|
||||
break;
|
||||
case char_argument:
|
||||
*(unsigned char*)arg_ptr = u_long_num;
|
||||
break;
|
||||
case short_argument:
|
||||
*(unsigned short*)arg_ptr = u_long_num;
|
||||
break;
|
||||
case long_argument:
|
||||
*(unsigned long*)arg_ptr = u_long_num;
|
||||
break;
|
||||
case intmax_argument:
|
||||
*(intmax_t*)arg_ptr = u_long_long_num;
|
||||
break;
|
||||
case size_t_argument:
|
||||
*(size_t*)arg_ptr = u_long_num;
|
||||
break;
|
||||
case ptrdiff_argument:
|
||||
*(ptrdiff_t*)arg_ptr = u_long_num;
|
||||
break;
|
||||
case long_long_argument:
|
||||
*(unsigned long long*)arg_ptr = u_long_long_num;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!match_failure) {
|
||||
items_assigned++;
|
||||
}
|
||||
}
|
||||
|
||||
conversions++;
|
||||
break;
|
||||
case 'a':
|
||||
case 'A':
|
||||
case 'f':
|
||||
case 'F':
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'g':
|
||||
case 'G':
|
||||
flt:
|
||||
if (match_failure) {
|
||||
long_double_num = NAN;
|
||||
} else {
|
||||
long_double_num = __strtold(format.field_width, ReadProc, ReadProcArg, &num_chars, &overflow);
|
||||
|
||||
if (!num_chars) {
|
||||
if (!is_secure) {
|
||||
goto exit;
|
||||
} else {
|
||||
match_failure = 1;
|
||||
long_double_num = NAN;
|
||||
goto assign_float;
|
||||
}
|
||||
}
|
||||
|
||||
chars_read += num_chars;
|
||||
}
|
||||
|
||||
assign_float:
|
||||
|
||||
if (arg_ptr) {
|
||||
switch (format.argument_options) {
|
||||
case normal_argument:
|
||||
*(float*)arg_ptr = long_double_num;
|
||||
break;
|
||||
case double_argument:
|
||||
*(double*)arg_ptr = long_double_num;
|
||||
break;
|
||||
case long_double_argument:
|
||||
*(long double*)arg_ptr = long_double_num;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!match_failure) {
|
||||
items_assigned++;
|
||||
}
|
||||
}
|
||||
|
||||
conversions++;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
|
||||
if (!format.field_width_specified) {
|
||||
format.field_width = 1;
|
||||
}
|
||||
|
||||
if (arg_ptr) {
|
||||
if (is_secure) {
|
||||
elem_valid = 1;
|
||||
elem_maxsize = va_arg(arg, size_t);
|
||||
}
|
||||
|
||||
num_chars = 0;
|
||||
|
||||
if (match_failure) {
|
||||
if (elem_maxsize > 0) {
|
||||
*arg_ptr = 0;
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
char* arg_start = arg_ptr;
|
||||
|
||||
while (format.field_width-- &&
|
||||
(!is_secure || ((elem_valid = (elem_maxsize > num_chars)) != 0)) &&
|
||||
((rval = ((*ReadProc)(ReadProcArg, 0, __GetAChar))) != -1)) {
|
||||
c = rval;
|
||||
|
||||
if (format.argument_options == wchar_argument) {
|
||||
mbtowc(((wchar_t*)arg_ptr), (char*)(&c), 1);
|
||||
arg_ptr += sizeof(char);
|
||||
} else {
|
||||
*arg_ptr++ = c;
|
||||
}
|
||||
num_chars++;
|
||||
}
|
||||
|
||||
c = rval;
|
||||
if (!num_chars || (is_secure && !elem_valid)) {
|
||||
if (!is_secure) {
|
||||
goto exit;
|
||||
} else {
|
||||
match_failure = 1;
|
||||
if (elem_maxsize > 0) {
|
||||
*arg_start = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
chars_read += num_chars;
|
||||
|
||||
items_assigned++;
|
||||
}
|
||||
} else {
|
||||
num_chars = 0;
|
||||
|
||||
while (format.field_width-- && ((rval = ((*ReadProc)(ReadProcArg, 0, __GetAChar))) != -1)) {
|
||||
c = rval;
|
||||
num_chars++;
|
||||
}
|
||||
c = rval;
|
||||
if (!num_chars) {
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
conversions++;
|
||||
break;
|
||||
|
||||
case '%':
|
||||
if (match_failure) {
|
||||
continue;
|
||||
} else {
|
||||
while (isspace(c = (*ReadProc)(ReadProcArg, 0, __GetAChar))) {
|
||||
chars_read++;
|
||||
}
|
||||
|
||||
if (c != '%') {
|
||||
(*ReadProc)(ReadProcArg, c, __UngetAChar);
|
||||
if (!is_secure) {
|
||||
goto exit;
|
||||
} else {
|
||||
match_failure = 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
chars_read++;
|
||||
}
|
||||
break;
|
||||
|
||||
case 's':
|
||||
if (!match_failure) {
|
||||
c = (*ReadProc)(ReadProcArg, 0, __GetAChar);
|
||||
while (isspace(c)) {
|
||||
chars_read++;
|
||||
c = (*ReadProc)(ReadProcArg, 0, __GetAChar);
|
||||
}
|
||||
|
||||
(*ReadProc)(ReadProcArg, c, __UngetAChar);
|
||||
}
|
||||
case '[':
|
||||
if (arg_ptr) {
|
||||
if (is_secure) {
|
||||
elem_valid = 1;
|
||||
elem_maxsize = va_arg(arg, size_t) - 1;
|
||||
}
|
||||
|
||||
num_chars = 0;
|
||||
|
||||
if (match_failure) {
|
||||
if (elem_maxsize > 0) {
|
||||
*arg_ptr = 0;
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
char* arg_start = arg_ptr;
|
||||
|
||||
while (format.field_width-- &&
|
||||
(!is_secure || ((elem_valid = (elem_maxsize >= num_chars)) != 0)) &&
|
||||
((rval = ((*ReadProc)(ReadProcArg, 0, __GetAChar))) != -1)) {
|
||||
c = rval;
|
||||
|
||||
if (!tst_char_map(format.char_set, c)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (format.argument_options == wchar_argument) {
|
||||
mbtowc(((wchar_t*)arg_ptr), (char*)&c, 1);
|
||||
arg_ptr = (char*)((wchar_t*)arg_ptr + 1);
|
||||
} else {
|
||||
*arg_ptr++ = c;
|
||||
}
|
||||
num_chars++;
|
||||
}
|
||||
c = rval;
|
||||
|
||||
if (!num_chars || (is_secure && !elem_valid)) {
|
||||
(*ReadProc)(ReadProcArg, c, __UngetAChar);
|
||||
if (!is_secure) {
|
||||
goto exit;
|
||||
} else {
|
||||
match_failure = 1;
|
||||
if (elem_maxsize > 0) {
|
||||
*arg_start = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
chars_read += num_chars;
|
||||
|
||||
if (format.argument_options == wchar_argument) {
|
||||
*(wchar_t*)arg_ptr = L'\0';
|
||||
} else {
|
||||
*arg_ptr = 0;
|
||||
}
|
||||
|
||||
items_assigned++;
|
||||
}
|
||||
} else {
|
||||
num_chars = 0;
|
||||
|
||||
while (format.field_width-- && ((rval = ((*ReadProc)(ReadProcArg, 0, __GetAChar))) != -1)) {
|
||||
c = rval;
|
||||
if (!tst_char_map(format.char_set, c)) {
|
||||
break;
|
||||
}
|
||||
|
||||
num_chars++;
|
||||
}
|
||||
c = rval;
|
||||
|
||||
if (!num_chars) {
|
||||
(*ReadProc)(ReadProcArg, c, __UngetAChar);
|
||||
break;
|
||||
}
|
||||
chars_read += num_chars;
|
||||
}
|
||||
|
||||
if (format.field_width >= 0) {
|
||||
(*ReadProc)(ReadProcArg, c, __UngetAChar);
|
||||
}
|
||||
|
||||
conversions++;
|
||||
break;
|
||||
case 'n':
|
||||
if (arg_ptr) {
|
||||
switch (format.argument_options) {
|
||||
case normal_argument:
|
||||
*(int*)arg_ptr = chars_read;
|
||||
break;
|
||||
case short_argument:
|
||||
*(short*)arg_ptr = chars_read;
|
||||
break;
|
||||
case long_argument:
|
||||
*(long*)arg_ptr = chars_read;
|
||||
break;
|
||||
case char_argument:
|
||||
*(char*)arg_ptr = chars_read;
|
||||
break;
|
||||
case long_long_argument:
|
||||
*(long long*)arg_ptr = chars_read;
|
||||
break;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
case 0xFF:
|
||||
default:
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
|
||||
if ((*ReadProc)(ReadProcArg, 0, __TestForError) && conversions == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return items_assigned;
|
||||
}
|
||||
|
||||
int __StringRead(void* pPtr, int ch, int act) {
|
||||
char ret;
|
||||
__InStrCtrl* Iscp = (__InStrCtrl*)pPtr;
|
||||
|
||||
switch (act) {
|
||||
case __GetAChar:
|
||||
ret = *(Iscp->NextChar);
|
||||
|
||||
if (ret == '\0') {
|
||||
Iscp->NullCharDetected = 1;
|
||||
return -1;
|
||||
} else {
|
||||
Iscp->NextChar++;
|
||||
return (unsigned char)ret;
|
||||
}
|
||||
|
||||
case __UngetAChar:
|
||||
if (Iscp->NullCharDetected == 0) {
|
||||
Iscp->NextChar--;
|
||||
} else {
|
||||
Iscp->NullCharDetected = 0;
|
||||
}
|
||||
|
||||
return ch;
|
||||
|
||||
case __TestForError:
|
||||
return Iscp->NullCharDetected;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline int vsscanf(const char* s, const char* format, va_list arg) {
|
||||
__InStrCtrl isc;
|
||||
isc.NextChar = (char*)s;
|
||||
|
||||
if ((s == 0) || (*isc.NextChar == '\0')) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
isc.NullCharDetected = 0;
|
||||
return __sformatter(&__StringRead, (void*)&isc, format, arg, 0);
|
||||
}
|
||||
|
||||
int sscanf(const char* s, const char* pFormat, ...) {
|
||||
va_list args;
|
||||
va_start(args, pFormat);
|
||||
return vsscanf(s, pFormat, args);
|
||||
}
|
||||
|
||||
659
libs/MSL/src/MSL_Common/strtold.c
Normal file
659
libs/MSL/src/MSL_Common/strtold.c
Normal file
@@ -0,0 +1,659 @@
|
||||
#include <internal/format_runtime.h>
|
||||
#define DBL_MAX_10_EXP 308
|
||||
#define DBL_MIN_10_EXP (-307)
|
||||
#define LDBL_MIN DBL_MIN
|
||||
#define LDBL_MAX DBL_MAX
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define TARGET_FLOAT_BITS 64
|
||||
#define TARGET_FLOAT_BYTES (TARGET_FLOAT_BITS / 8)
|
||||
#define TARGET_FLOAT_MAX_EXP LDBL_MAX_EXP
|
||||
#define TARGET_FLOAT_MANT_DIG LDBL_MANT_DIG
|
||||
#define TARGET_FLOAT_IMPLICIT_J_BIT 1
|
||||
#define TARGET_FLOAT_MANT_BITS (TARGET_FLOAT_MANT_DIG - TARGET_FLOAT_IMPLICIT_J_BIT)
|
||||
#define TARGET_FLOAT_EXP_BITS (TARGET_FLOAT_BITS - TARGET_FLOAT_MANT_BITS - 1)
|
||||
|
||||
enum scan_states {
|
||||
start = 0x0001,
|
||||
sig_start = 0x0002,
|
||||
leading_sig_zeroes = 0x0004,
|
||||
int_digit_loop = 0x0008,
|
||||
frac_start = 0x0010,
|
||||
frac_digit_loop = 0x0020,
|
||||
sig_end = 0x0040,
|
||||
exp_start = 0x0080,
|
||||
leading_exp_digit = 0x0100,
|
||||
leading_exp_zeroes = 0x0200,
|
||||
exp_digit_loop = 0x0400,
|
||||
finished = 0x0800,
|
||||
failure = 0x1000,
|
||||
nan_state = 0x2000,
|
||||
infin_state = 0x4000,
|
||||
hex_state = 0x8000
|
||||
};
|
||||
|
||||
enum hex_scan_states {
|
||||
not_hex = 0x0000,
|
||||
hex_start = 0x0001,
|
||||
hex_leading_sig_zeroes = 0x0002,
|
||||
hex_int_digit_loop = 0x0004,
|
||||
hex_frac_digit_loop = 0x0008,
|
||||
hex_sig_end = 0x0010,
|
||||
hex_exp_start = 0x0020,
|
||||
hex_leading_exp_digit = 0x0040,
|
||||
hex_leading_exp_zeroes = 0x0080,
|
||||
hex_exp_digit_loop = 0x0100
|
||||
};
|
||||
|
||||
#define final_state(scan_state) (scan_state & (finished | failure))
|
||||
#define success(scan_state) \
|
||||
(scan_state & \
|
||||
(leading_sig_zeroes | int_digit_loop | frac_digit_loop | leading_exp_zeroes | exp_digit_loop | finished))
|
||||
#define hex_success(count, scan_state) \
|
||||
(count - 1 > 2 && scan_state & (hex_leading_sig_zeroes | hex_int_digit_loop | hex_frac_digit_loop | \
|
||||
hex_leading_exp_zeroes | hex_exp_digit_loop))
|
||||
|
||||
#define fetch() (count++, (*ReadProc)(ReadProcArg, 0, __GetAChar))
|
||||
#define unfetch(c) (*ReadProc)(ReadProcArg, c, __UngetAChar)
|
||||
|
||||
long double __strtold(int max_width, int (*ReadProc)(void*, int, int), void* ReadProcArg, int* chars_scanned,
|
||||
int* overflow) {
|
||||
int scan_state = start;
|
||||
int hex_scan_state = not_hex;
|
||||
int count = 0;
|
||||
int spaces = 0;
|
||||
int c;
|
||||
decimal d = {0, 0, {0, ""}};
|
||||
int sig_negative = 0;
|
||||
int exp_negative = 0;
|
||||
long exp_value = 0;
|
||||
int exp_adjust = 0;
|
||||
long double result = 0.0;
|
||||
int sign_detected = 0;
|
||||
int radix_marker = *(unsigned char*)(__lconv).decimal_point;
|
||||
|
||||
unsigned char* chptr;
|
||||
unsigned char mantissa[TARGET_FLOAT_BYTES];
|
||||
unsigned mantissa_digits;
|
||||
unsigned long exponent = 0;
|
||||
|
||||
int ui;
|
||||
unsigned char uch, uch1;
|
||||
int NibbleIndex;
|
||||
int expsign = 0;
|
||||
int exp_digits = 0;
|
||||
unsigned intdigits = 0;
|
||||
|
||||
*overflow = 0;
|
||||
c = fetch();
|
||||
|
||||
while (count <= max_width && c != -1 && !final_state(scan_state)) {
|
||||
switch (scan_state) {
|
||||
case start:
|
||||
if (isspace(c)) {
|
||||
c = fetch();
|
||||
count--;
|
||||
spaces++;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (toupper(c)) {
|
||||
case '-':
|
||||
sig_negative = 1;
|
||||
|
||||
case '+':
|
||||
c = fetch();
|
||||
sign_detected = 1;
|
||||
break;
|
||||
case 'I':
|
||||
c = fetch();
|
||||
scan_state = infin_state;
|
||||
break;
|
||||
|
||||
case 'N':
|
||||
c = fetch();
|
||||
scan_state = nan_state;
|
||||
break;
|
||||
|
||||
default:
|
||||
scan_state = sig_start;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case infin_state: {
|
||||
int i = 1;
|
||||
char model[] = "INFINITY";
|
||||
|
||||
while ((i < 8) && (toupper(c) == model[i])) {
|
||||
i++;
|
||||
c = fetch();
|
||||
}
|
||||
|
||||
if ((i == 3) || (i == 8)) {
|
||||
if (sig_negative) {
|
||||
result = (float)-(double)INFINITY;
|
||||
} else {
|
||||
result = INFINITY;
|
||||
}
|
||||
|
||||
*chars_scanned = spaces + i + sign_detected;
|
||||
return result;
|
||||
} else {
|
||||
scan_state = failure;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case nan_state: {
|
||||
int i = 1, j = 0;
|
||||
char model[] = "NAN(";
|
||||
char nan_arg[32] = "";
|
||||
while ((i < 4) && (toupper(c) == model[i])) {
|
||||
i++;
|
||||
c = fetch();
|
||||
}
|
||||
|
||||
if ((i == 3) || (i == 4)) {
|
||||
if (i == 4) {
|
||||
while ((j < 32) && (isdigit(c) || isalpha(c) || (c == radix_marker))) {
|
||||
nan_arg[j++] = (char)c;
|
||||
c = fetch();
|
||||
}
|
||||
|
||||
if (c != ')') {
|
||||
scan_state = failure;
|
||||
break;
|
||||
} else {
|
||||
j++;
|
||||
}
|
||||
}
|
||||
nan_arg[j] = '\0';
|
||||
|
||||
if (sig_negative) {
|
||||
result = -nan(nan_arg);
|
||||
} else {
|
||||
result = nan(nan_arg);
|
||||
}
|
||||
|
||||
*chars_scanned = spaces + i + j + sign_detected;
|
||||
return result;
|
||||
} else {
|
||||
scan_state = failure;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case sig_start:
|
||||
if (c == radix_marker) {
|
||||
scan_state = frac_start;
|
||||
c = fetch();
|
||||
break;
|
||||
}
|
||||
if (!isdigit(c)) {
|
||||
scan_state = failure;
|
||||
break;
|
||||
}
|
||||
|
||||
if (c == '0') {
|
||||
c = fetch();
|
||||
if (toupper(c) == 'X') {
|
||||
scan_state = hex_state;
|
||||
hex_scan_state = hex_start;
|
||||
} else {
|
||||
scan_state = leading_sig_zeroes;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
scan_state = int_digit_loop;
|
||||
break;
|
||||
|
||||
case leading_sig_zeroes:
|
||||
if (c == '0') {
|
||||
c = fetch();
|
||||
|
||||
break;
|
||||
}
|
||||
scan_state = int_digit_loop;
|
||||
break;
|
||||
|
||||
case int_digit_loop:
|
||||
if (!isdigit(c)) {
|
||||
if (c == radix_marker) {
|
||||
scan_state = frac_digit_loop;
|
||||
c = fetch();
|
||||
} else {
|
||||
scan_state = sig_end;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (d.sig.length < 20) {
|
||||
d.sig.text[d.sig.length++] = (unsigned char)c;
|
||||
} else {
|
||||
exp_adjust++;
|
||||
}
|
||||
|
||||
c = fetch();
|
||||
break;
|
||||
|
||||
case frac_start:
|
||||
if (!isdigit(c)) {
|
||||
scan_state = failure;
|
||||
break;
|
||||
}
|
||||
|
||||
scan_state = frac_digit_loop;
|
||||
break;
|
||||
|
||||
case frac_digit_loop:
|
||||
if (!isdigit(c)) {
|
||||
scan_state = sig_end;
|
||||
break;
|
||||
}
|
||||
|
||||
if (d.sig.length < 20) {
|
||||
if (c != '0' || d.sig.length) {
|
||||
d.sig.text[d.sig.length++] = (unsigned char)c;
|
||||
}
|
||||
|
||||
exp_adjust--;
|
||||
}
|
||||
c = fetch();
|
||||
break;
|
||||
|
||||
case sig_end:
|
||||
if (toupper(c) == 'E') {
|
||||
scan_state = exp_start;
|
||||
c = fetch();
|
||||
break;
|
||||
}
|
||||
scan_state = finished;
|
||||
break;
|
||||
|
||||
case exp_start:
|
||||
if (c == '+') {
|
||||
c = fetch();
|
||||
} else if (c == '-') {
|
||||
c = fetch();
|
||||
exp_negative = 1;
|
||||
}
|
||||
|
||||
scan_state = leading_exp_digit;
|
||||
break;
|
||||
|
||||
case leading_exp_digit:
|
||||
if (!isdigit(c)) {
|
||||
scan_state = failure;
|
||||
break;
|
||||
}
|
||||
|
||||
if (c == '0') {
|
||||
scan_state = leading_exp_zeroes;
|
||||
c = fetch();
|
||||
break;
|
||||
}
|
||||
|
||||
scan_state = exp_digit_loop;
|
||||
break;
|
||||
|
||||
case leading_exp_zeroes:
|
||||
if (c == '0') {
|
||||
c = fetch();
|
||||
break;
|
||||
}
|
||||
|
||||
scan_state = exp_digit_loop;
|
||||
break;
|
||||
|
||||
case exp_digit_loop:
|
||||
if (!isdigit(c)) {
|
||||
scan_state = finished;
|
||||
break;
|
||||
}
|
||||
|
||||
exp_value = exp_value * 10 + (c - '0');
|
||||
if (exp_value > 0x7FFF) {
|
||||
*overflow = 1;
|
||||
}
|
||||
|
||||
c = fetch();
|
||||
break;
|
||||
|
||||
case hex_state: {
|
||||
switch (hex_scan_state) {
|
||||
case hex_start:
|
||||
memset(mantissa, 0, sizeof(mantissa));
|
||||
chptr = mantissa;
|
||||
mantissa_digits = (53 + 3) / 4;
|
||||
intdigits = 0;
|
||||
NibbleIndex = 0;
|
||||
hex_scan_state = hex_leading_sig_zeroes;
|
||||
c = fetch();
|
||||
break;
|
||||
|
||||
case hex_leading_sig_zeroes:
|
||||
if (c == '0') {
|
||||
c = fetch();
|
||||
break;
|
||||
}
|
||||
|
||||
hex_scan_state = hex_int_digit_loop;
|
||||
break;
|
||||
|
||||
case hex_int_digit_loop:
|
||||
if (!isxdigit(c)) {
|
||||
if (c == radix_marker) {
|
||||
hex_scan_state = hex_frac_digit_loop;
|
||||
c = fetch();
|
||||
}
|
||||
|
||||
else {
|
||||
hex_scan_state = hex_sig_end;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (intdigits < mantissa_digits) {
|
||||
intdigits++;
|
||||
uch = *(chptr + NibbleIndex / 2);
|
||||
|
||||
ui = toupper(c);
|
||||
if (ui >= 'A') {
|
||||
ui = ui - 'A' + 10;
|
||||
} else {
|
||||
ui -= '0';
|
||||
}
|
||||
|
||||
uch1 = (unsigned char)ui;
|
||||
|
||||
if ((NibbleIndex % 2) != 0) {
|
||||
uch |= uch1;
|
||||
} else {
|
||||
uch |= (unsigned char)(uch1 << 4);
|
||||
}
|
||||
|
||||
*(chptr + NibbleIndex++ / 2) = uch;
|
||||
c = fetch();
|
||||
}
|
||||
|
||||
else {
|
||||
c = fetch();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case hex_frac_digit_loop:
|
||||
if (!isxdigit(c)) {
|
||||
hex_scan_state = hex_sig_end;
|
||||
break;
|
||||
}
|
||||
|
||||
if (intdigits < mantissa_digits) {
|
||||
uch = *(chptr + NibbleIndex / 2);
|
||||
ui = toupper(c);
|
||||
|
||||
if (ui >= 'A') {
|
||||
ui = ui - 'A' + 10;
|
||||
} else {
|
||||
ui -= '0';
|
||||
}
|
||||
|
||||
uch1 = (unsigned char)ui;
|
||||
|
||||
if ((NibbleIndex % 2) != 0) {
|
||||
uch |= uch1;
|
||||
} else {
|
||||
uch |= (unsigned char)(uch1 << 4);
|
||||
}
|
||||
|
||||
*(chptr + NibbleIndex++ / 2) = uch;
|
||||
c = fetch();
|
||||
} else {
|
||||
c = fetch();
|
||||
}
|
||||
break;
|
||||
|
||||
case hex_sig_end:
|
||||
if (toupper(c) == 'P') {
|
||||
hex_scan_state = hex_exp_start;
|
||||
exp_digits++;
|
||||
c = fetch();
|
||||
} else {
|
||||
scan_state = finished;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case hex_exp_start:
|
||||
exp_digits++;
|
||||
if (c == '-') {
|
||||
expsign = 1;
|
||||
} else if (c != '+') {
|
||||
c = unfetch(c);
|
||||
count--;
|
||||
exp_digits--;
|
||||
}
|
||||
|
||||
hex_scan_state = hex_leading_exp_digit;
|
||||
c = fetch();
|
||||
break;
|
||||
|
||||
case hex_leading_exp_digit:
|
||||
if (!isdigit(c)) {
|
||||
scan_state = failure;
|
||||
break;
|
||||
}
|
||||
|
||||
if (c == '0') {
|
||||
exp_digits++;
|
||||
hex_scan_state = hex_leading_exp_zeroes;
|
||||
c = fetch();
|
||||
break;
|
||||
}
|
||||
|
||||
hex_scan_state = hex_exp_digit_loop;
|
||||
break;
|
||||
|
||||
case hex_leading_exp_zeroes:
|
||||
if (c == '0') {
|
||||
c = fetch();
|
||||
break;
|
||||
}
|
||||
|
||||
hex_scan_state = hex_exp_digit_loop;
|
||||
break;
|
||||
|
||||
case hex_exp_digit_loop:
|
||||
if (!isdigit(c)) {
|
||||
scan_state = finished;
|
||||
break;
|
||||
}
|
||||
|
||||
exponent = exponent * 10 + (c - '0');
|
||||
|
||||
if (exp_value > SHRT_MAX) {
|
||||
*overflow = 1;
|
||||
}
|
||||
|
||||
exp_digits++;
|
||||
c = fetch();
|
||||
|
||||
break;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
if (scan_state != 32768 ? !success(scan_state) : !hex_success(count, hex_scan_state)) {
|
||||
count = 0;
|
||||
*chars_scanned = 0;
|
||||
} else {
|
||||
count--;
|
||||
*chars_scanned = count + spaces;
|
||||
}
|
||||
|
||||
unfetch(c);
|
||||
|
||||
if (hex_scan_state == not_hex) {
|
||||
if (exp_negative) {
|
||||
exp_value = -exp_value;
|
||||
}
|
||||
|
||||
{
|
||||
int n = d.sig.length;
|
||||
unsigned char* p = &d.sig.text[n];
|
||||
|
||||
while (n-- && *--p == '0') {
|
||||
exp_adjust++;
|
||||
}
|
||||
|
||||
d.sig.length = (unsigned char)(n + 1);
|
||||
|
||||
if (d.sig.length == 0) {
|
||||
d.sig.text[d.sig.length++] = '0';
|
||||
}
|
||||
}
|
||||
|
||||
exp_value += exp_adjust;
|
||||
|
||||
if (exp_value < -0x8000 || exp_value > 0x7FFF) {
|
||||
*overflow = 1;
|
||||
}
|
||||
|
||||
if (*overflow) {
|
||||
if (exp_negative) {
|
||||
return 0.0;
|
||||
} else {
|
||||
return sig_negative ? -HUGE_VAL : HUGE_VAL;
|
||||
}
|
||||
}
|
||||
|
||||
d.exp = (short)exp_value;
|
||||
|
||||
result = __dec2num(&d);
|
||||
|
||||
if (result != 0.0 && result < LDBL_MIN) {
|
||||
*overflow = 1;
|
||||
} else if (result > LDBL_MAX) {
|
||||
*overflow = 1;
|
||||
result = HUGE_VAL;
|
||||
}
|
||||
|
||||
if (sig_negative && success(scan_state)) {
|
||||
result = -result;
|
||||
}
|
||||
|
||||
return result;
|
||||
} else {
|
||||
unsigned mantissa_bit, dbl_bit;
|
||||
unsigned one_bit;
|
||||
long double dbl_bits_storage;
|
||||
unsigned char* dbl_bits = (unsigned char*)&dbl_bits_storage;
|
||||
|
||||
if (expsign) {
|
||||
exponent = -exponent;
|
||||
}
|
||||
|
||||
exponent += intdigits * 4;
|
||||
|
||||
one_bit = 0;
|
||||
while (one_bit < 4 && !(mantissa[0] & (0x80 >> one_bit))) {
|
||||
one_bit++;
|
||||
exponent--;
|
||||
}
|
||||
|
||||
if (TARGET_FLOAT_IMPLICIT_J_BIT) {
|
||||
one_bit++;
|
||||
}
|
||||
|
||||
if (one_bit) {
|
||||
unsigned char carry = 0;
|
||||
for (chptr = mantissa + sizeof(mantissa) - 1; chptr >= mantissa; chptr--) {
|
||||
unsigned char a = *chptr;
|
||||
*chptr = (unsigned char)((a << one_bit) | carry);
|
||||
carry = (unsigned char)(a >> (8 - one_bit));
|
||||
}
|
||||
}
|
||||
|
||||
memset(dbl_bits, 0, sizeof(dbl_bits_storage));
|
||||
dbl_bit = (TARGET_FLOAT_BITS - TARGET_FLOAT_MANT_BITS);
|
||||
|
||||
for (mantissa_bit = 0; mantissa_bit < TARGET_FLOAT_MANT_BITS; mantissa_bit += 8) {
|
||||
unsigned char ui = mantissa[mantissa_bit >> 3];
|
||||
int halfbits;
|
||||
|
||||
if (mantissa_bit + 8 > TARGET_FLOAT_MANT_BITS) {
|
||||
ui &= 0xff << (TARGET_FLOAT_MANT_BITS - mantissa_bit);
|
||||
}
|
||||
|
||||
halfbits = (dbl_bit & 7);
|
||||
dbl_bits[dbl_bit >> 3] |= (unsigned char)(ui >> halfbits);
|
||||
dbl_bit += 8;
|
||||
dbl_bits[dbl_bit >> 3] |= (unsigned char)(ui << (8 - halfbits));
|
||||
}
|
||||
|
||||
exponent += TARGET_FLOAT_MAX_EXP - 2;
|
||||
|
||||
if ((exponent & ~(TARGET_FLOAT_MAX_EXP * 2 - 1))) {
|
||||
*overflow = 1;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
exponent <<= 32 - TARGET_FLOAT_EXP_BITS;
|
||||
|
||||
dbl_bits[0] |= exponent >> 25;
|
||||
|
||||
if (TARGET_FLOAT_EXP_BITS > 7) {
|
||||
dbl_bits[1] |= exponent >> 17;
|
||||
}
|
||||
|
||||
if (TARGET_FLOAT_EXP_BITS > 15) {
|
||||
dbl_bits[2] |= exponent >> 9;
|
||||
}
|
||||
|
||||
if (TARGET_FLOAT_EXP_BITS > 23) {
|
||||
dbl_bits[3] |= exponent >> 1;
|
||||
}
|
||||
|
||||
if (sig_negative) {
|
||||
dbl_bits[0] |= 0x80;
|
||||
}
|
||||
|
||||
result = *(long double*)dbl_bits;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
double strtod(const char* str, char** end) {
|
||||
__InStrCtrl isc;
|
||||
double value, abs_value;
|
||||
int count, overflow;
|
||||
|
||||
isc.NextChar = (char*)str;
|
||||
isc.NullCharDetected = 0;
|
||||
value = __strtold(INT_MAX, &__StringRead, (void*)&isc, &count, &overflow);
|
||||
|
||||
if (end) {
|
||||
*end = (char*)str + count;
|
||||
}
|
||||
|
||||
abs_value = fabs(value);
|
||||
if (overflow || (value != 0.0 && (abs_value < DBL_MIN || abs_value > DBL_MAX))) {
|
||||
errno = ERANGE;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
721
libs/MSL/src/MSL_Common/time.c
Normal file
721
libs/MSL/src/MSL_Common/time.c
Normal file
@@ -0,0 +1,721 @@
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <internal/locale.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
|
||||
typedef struct tm {
|
||||
int tm_sec;
|
||||
int tm_min;
|
||||
int tm_hour;
|
||||
int tm_mday;
|
||||
int tm_mon;
|
||||
int tm_year;
|
||||
int tm_wday;
|
||||
int tm_yday;
|
||||
int tm_isdst;
|
||||
} tm;
|
||||
|
||||
extern int __msl_mod(int, int);
|
||||
extern div_t __msl_div(long, long);
|
||||
extern int __msl_add(int*, int);
|
||||
extern int __msl_ladd(long*, long);
|
||||
extern int __msl_lmul(long*, long);
|
||||
|
||||
static int __leap_year(int year) {
|
||||
return __msl_mod(year, 4) == 0 && (__msl_mod(year, 100) != 0 || __msl_mod(year, 400) == 100);
|
||||
}
|
||||
|
||||
static int leap_days(int year, int month) {
|
||||
int n;
|
||||
div_t q;
|
||||
|
||||
q = div(year, 4);
|
||||
n = q.quot;
|
||||
|
||||
q = div(year, 100);
|
||||
n -= q.quot;
|
||||
|
||||
if (year < 100) {
|
||||
q = __msl_div(year + 899, 1000);
|
||||
n += q.quot;
|
||||
} else {
|
||||
q = __msl_div(year - 100, 1000);
|
||||
n += q.quot + 1;
|
||||
}
|
||||
|
||||
if (__leap_year(year)) {
|
||||
if (year < 0) {
|
||||
if (month > 1) {
|
||||
n++;
|
||||
}
|
||||
} else if (month <= 1) {
|
||||
n--;
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
#define seconds_per_minute (60L)
|
||||
#define seconds_per_hour (60L * seconds_per_minute)
|
||||
#define seconds_per_day (24L * seconds_per_hour)
|
||||
#define seconds_1900_to_1970 (((365 * 70UL) + 17) * 24 * 60 * 60)
|
||||
|
||||
const short __msl_month_to_days[2][13] = {
|
||||
{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365},
|
||||
{0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366}
|
||||
};
|
||||
|
||||
extern int __isdst(void);
|
||||
extern time_t __get_time(void);
|
||||
extern int __to_gm_time(time_t*);
|
||||
|
||||
void __msl_time2tm(time_t in_time, tm* tm) {
|
||||
unsigned long years, months, days, seconds;
|
||||
int is_leap_year;
|
||||
unsigned long time = in_time + seconds_1900_to_1970;
|
||||
|
||||
if (!tm) {
|
||||
return;
|
||||
}
|
||||
|
||||
tm->tm_isdst = __isdst();
|
||||
|
||||
days = time / seconds_per_day;
|
||||
seconds = time % seconds_per_day;
|
||||
|
||||
tm->tm_wday = (days + 1) % 7;
|
||||
years = 0;
|
||||
|
||||
for (;;) {
|
||||
unsigned long days_this_year = __leap_year(years) ? 366 : 365;
|
||||
|
||||
if (days < days_this_year) {
|
||||
break;
|
||||
}
|
||||
|
||||
days -= days_this_year;
|
||||
years += 1;
|
||||
}
|
||||
|
||||
tm->tm_year = years;
|
||||
tm->tm_yday = days;
|
||||
|
||||
months = 0;
|
||||
is_leap_year = __leap_year(years);
|
||||
|
||||
for (;;) {
|
||||
unsigned long days_thru_this_month = __msl_month_to_days[is_leap_year][months + 1];
|
||||
|
||||
if (days < days_thru_this_month) {
|
||||
days -= __msl_month_to_days[is_leap_year][months];
|
||||
break;
|
||||
}
|
||||
|
||||
++months;
|
||||
}
|
||||
|
||||
tm->tm_mon = months;
|
||||
tm->tm_mday = days + 1;
|
||||
tm->tm_hour = seconds / seconds_per_hour;
|
||||
seconds %= seconds_per_hour;
|
||||
tm->tm_min = seconds / seconds_per_minute;
|
||||
tm->tm_sec = seconds % seconds_per_minute;
|
||||
}
|
||||
|
||||
static int adjust(int* x, int y, int* z) {
|
||||
div_t q;
|
||||
|
||||
q = __msl_div(*x, y);
|
||||
*x = q.rem;
|
||||
return __msl_add(z, q.quot);
|
||||
}
|
||||
|
||||
static int __tm2time(tm* tm, time_t* time) {
|
||||
long days;
|
||||
time_t seconds, day_secs;
|
||||
|
||||
if (!tm || !time) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
--tm->tm_mday;
|
||||
|
||||
if (!adjust(&tm->tm_sec, 60, &tm->tm_min)) {
|
||||
goto no_exit;
|
||||
}
|
||||
if (!adjust(&tm->tm_min, 60, &tm->tm_hour)) {
|
||||
goto no_exit;
|
||||
}
|
||||
if (!adjust(&tm->tm_hour, 24, &tm->tm_mday)) {
|
||||
goto no_exit;
|
||||
}
|
||||
if (!adjust(&tm->tm_mon, 12, &tm->tm_year)) {
|
||||
goto no_exit;
|
||||
}
|
||||
|
||||
days = tm->tm_year;
|
||||
|
||||
if (!__msl_lmul(&days, 365)) {
|
||||
goto no_exit;
|
||||
}
|
||||
if (!__msl_ladd(&days, leap_days(tm->tm_year, tm->tm_mon))) {
|
||||
goto no_exit;
|
||||
}
|
||||
if (!__msl_ladd(&days, __msl_month_to_days[0][tm->tm_mon])) {
|
||||
goto no_exit;
|
||||
}
|
||||
if (!__msl_ladd(&days, tm->tm_mday)) {
|
||||
goto no_exit;
|
||||
}
|
||||
if (days < 0 || days > (ULONG_MAX / seconds_per_day)) {
|
||||
goto no_exit;
|
||||
}
|
||||
|
||||
day_secs = days * seconds_per_day;
|
||||
seconds = (tm->tm_hour * seconds_per_hour) + (tm->tm_min * seconds_per_minute) + tm->tm_sec;
|
||||
|
||||
if (seconds > ULONG_MAX - day_secs) {
|
||||
goto no_exit;
|
||||
}
|
||||
|
||||
seconds += day_secs;
|
||||
seconds -= seconds_1900_to_1970;
|
||||
*time = seconds;
|
||||
|
||||
__msl_time2tm(seconds, tm);
|
||||
return 1;
|
||||
|
||||
no_exit:
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern clock_t __get_clock(void);
|
||||
|
||||
clock_t clock(void) {
|
||||
return __get_clock();
|
||||
}
|
||||
|
||||
time_t mktime(tm* timeptr) {
|
||||
struct tm tm = *timeptr;
|
||||
time_t time;
|
||||
|
||||
if (!__tm2time(&tm, &time)) {
|
||||
return (time_t)-1;
|
||||
}
|
||||
|
||||
*timeptr = tm;
|
||||
return time;
|
||||
}
|
||||
|
||||
static void clear_tm(struct tm* tm) {
|
||||
tm->tm_sec = 0;
|
||||
tm->tm_min = 0;
|
||||
tm->tm_hour = 0;
|
||||
tm->tm_mday = 1;
|
||||
tm->tm_mon = 0;
|
||||
tm->tm_year = 0;
|
||||
tm->tm_wday = 1;
|
||||
tm->tm_yday = 0;
|
||||
tm->tm_isdst = -1;
|
||||
}
|
||||
|
||||
static char* find_name(const char* names, int index) {
|
||||
static char extracted_name[32];
|
||||
int i;
|
||||
const char* start = names;
|
||||
const char* end;
|
||||
|
||||
for (i = 0; i <= index; i++) {
|
||||
end = strchr(start, '|');
|
||||
if (i == index) {
|
||||
if (end == NULL) {
|
||||
strcpy(extracted_name, start);
|
||||
} else {
|
||||
strncpy(extracted_name, start, end - start);
|
||||
extracted_name[end - start] = '\0';
|
||||
}
|
||||
break;
|
||||
}
|
||||
start = end + 1;
|
||||
}
|
||||
|
||||
return extracted_name;
|
||||
}
|
||||
|
||||
char* asctime(const struct tm* timeptr) {
|
||||
static char asctime_result[26];
|
||||
char* result = asctime_result;
|
||||
if (!timeptr) {
|
||||
strcpy(result, "xxx xxx xx xx:xx:xx xxxx\n");
|
||||
} else {
|
||||
char day[4];
|
||||
char month[4];
|
||||
strncpy(day, find_name(_current_locale.time_cmpt_ptr->Day_Names, timeptr->tm_wday * 2), 3);
|
||||
day[3] = 0;
|
||||
strncpy(month, find_name(_current_locale.time_cmpt_ptr->MonthNames, timeptr->tm_mon * 2), 3);
|
||||
month[3] = 0;
|
||||
sprintf(result, "%s %s%3d %.2d:%.2d:%.2d %d\n", day, month, timeptr->tm_mday,
|
||||
timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec, timeptr->tm_year + 1900);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
struct tm* localtime(const time_t* timer);
|
||||
|
||||
char* ctime(const time_t* timer) {
|
||||
struct tm* calendar = localtime(timer);
|
||||
char* result = asctime(calendar);
|
||||
char day[4];
|
||||
char month[4];
|
||||
strncpy(day, find_name(_current_locale.time_cmpt_ptr->Day_Names, calendar->tm_wday * 2), 3);
|
||||
day[3] = 0;
|
||||
strncpy(month, find_name(_current_locale.time_cmpt_ptr->MonthNames, calendar->tm_mon * 2), 3);
|
||||
month[3] = 0;
|
||||
sprintf(result, "%.3s %.3s %2d %.2d:%.2d:%.2d %4d\n", day, month,
|
||||
calendar->tm_mday, calendar->tm_hour, calendar->tm_min, calendar->tm_sec,
|
||||
calendar->tm_year + 1900);
|
||||
return result;
|
||||
}
|
||||
|
||||
static time_t time(time_t* timer) {
|
||||
time_t result = __get_time();
|
||||
|
||||
if (timer) {
|
||||
*timer = result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static struct tm* gmtime(const time_t* timer) {
|
||||
static struct tm gmtime_tm;
|
||||
time_t time;
|
||||
|
||||
if (!timer) {
|
||||
clear_tm(&gmtime_tm);
|
||||
return &gmtime_tm;
|
||||
}
|
||||
|
||||
time = *timer;
|
||||
if (!__to_gm_time(&time)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
__msl_time2tm(time, &gmtime_tm);
|
||||
gmtime_tm.tm_isdst = 0;
|
||||
return &gmtime_tm;
|
||||
}
|
||||
|
||||
struct tm* localtime(const time_t* timer) {
|
||||
static struct tm localtime_tm;
|
||||
|
||||
if (!timer) {
|
||||
clear_tm(&localtime_tm);
|
||||
localtime_tm.tm_isdst = __isdst();
|
||||
return &localtime_tm;
|
||||
} else {
|
||||
__msl_time2tm(*timer, &localtime_tm);
|
||||
localtime_tm.tm_isdst = __isdst();
|
||||
return &localtime_tm;
|
||||
}
|
||||
}
|
||||
|
||||
static int emit(char* str, size_t size, size_t* max_size, const char* format_str, ...) {
|
||||
va_list args;
|
||||
va_start(args, format_str);
|
||||
|
||||
if (size > *max_size) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
*max_size -= size;
|
||||
return vsprintf(str, format_str, args);
|
||||
}
|
||||
|
||||
time_t __MSL_ISO8601NewYear(int year) {
|
||||
struct tm ts0;
|
||||
time_t timeval;
|
||||
short StartMday[7] = {2, 3, 4, 29, 30, 31, 1};
|
||||
|
||||
ts0.tm_sec = 0;
|
||||
ts0.tm_min = 0;
|
||||
ts0.tm_hour = 0;
|
||||
ts0.tm_mon = 0;
|
||||
ts0.tm_isdst = -1;
|
||||
ts0.tm_mday = 0;
|
||||
ts0.tm_wday = 7;
|
||||
ts0.tm_year = year;
|
||||
while ((ts0.tm_wday != 0) && (ts0.tm_mday <= 7)) {
|
||||
ts0.tm_mday++;
|
||||
timeval = mktime(&ts0);
|
||||
}
|
||||
ts0.tm_mday = StartMday[ts0.tm_mday - 1];
|
||||
if (ts0.tm_mday >= 29) {
|
||||
ts0.tm_mon = 11;
|
||||
ts0.tm_year--;
|
||||
}
|
||||
return mktime(&ts0);
|
||||
}
|
||||
|
||||
static double difftime(time_t time1, time_t time0) {
|
||||
time_t diff;
|
||||
|
||||
if (time1 >= time0) {
|
||||
return time1 - time0;
|
||||
}
|
||||
|
||||
diff = time0 - time1;
|
||||
return -(double)diff;
|
||||
}
|
||||
|
||||
extern const double msl_seconds_per_day;
|
||||
extern const double msl_days_per_week;
|
||||
extern const double msl_seconds_per_minute;
|
||||
|
||||
int __MSL_ISO8601Week(const struct tm* tmptr, int* WYear) {
|
||||
struct WeekYear {
|
||||
int Year;
|
||||
time_t Start;
|
||||
};
|
||||
struct WeekYear LastYear, ThisYear, NextYear;
|
||||
struct WeekYear* WyPtr;
|
||||
struct tm Localtm = *tmptr;
|
||||
double Days;
|
||||
int WeekNo;
|
||||
time_t GivenTimeVal;
|
||||
|
||||
LastYear.Year = tmptr->tm_year - 1;
|
||||
LastYear.Start = __MSL_ISO8601NewYear(LastYear.Year);
|
||||
ThisYear.Year = tmptr->tm_year;
|
||||
ThisYear.Start = __MSL_ISO8601NewYear(ThisYear.Year);
|
||||
NextYear.Year = tmptr->tm_year + 1;
|
||||
NextYear.Start = __MSL_ISO8601NewYear(NextYear.Year);
|
||||
|
||||
GivenTimeVal = mktime(&Localtm);
|
||||
if ((LastYear.Start <= GivenTimeVal) && (GivenTimeVal < ThisYear.Start)) {
|
||||
WyPtr = &LastYear;
|
||||
} else if ((ThisYear.Start <= GivenTimeVal) && (GivenTimeVal < NextYear.Start)) {
|
||||
WyPtr = &ThisYear;
|
||||
} else {
|
||||
WyPtr = &NextYear;
|
||||
}
|
||||
*WYear = WyPtr->Year;
|
||||
{
|
||||
double diff;
|
||||
|
||||
if (GivenTimeVal >= WyPtr->Start) {
|
||||
diff = (double)(GivenTimeVal - WyPtr->Start);
|
||||
} else {
|
||||
diff = -(double)(WyPtr->Start - GivenTimeVal);
|
||||
}
|
||||
Days = diff / msl_seconds_per_day;
|
||||
}
|
||||
WeekNo = (int)(Days / msl_days_per_week) + 1;
|
||||
return WeekNo;
|
||||
}
|
||||
|
||||
static int week_num(const struct tm* tm, int starting_day) {
|
||||
int days = tm->tm_yday;
|
||||
|
||||
days -= __msl_mod(tm->tm_wday - starting_day, 7);
|
||||
|
||||
if (days < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (days / 7) + 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int emit_string(char* str, size_t size, size_t* max_size, const char* value) {
|
||||
return emit(str, size, max_size, "%s", value);
|
||||
}
|
||||
|
||||
|
||||
size_t strftime(char* str, size_t max_size, const char* format_str, const struct tm* timeptr) {
|
||||
char name[32];
|
||||
size_t num_chars, chars_written, space_remaining;
|
||||
struct __locale* locale = &_current_locale;
|
||||
const char* format_ptr;
|
||||
const char* curr_format;
|
||||
int n, ISO8601Year, ISO8601WeekNo;
|
||||
struct tm tm;
|
||||
struct tm defaults = {0, 0, 0, 1, 0, 0, 1, 0, -1};
|
||||
|
||||
if ((space_remaining = --max_size) <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
tm = defaults;
|
||||
|
||||
if (timeptr) {
|
||||
tm = *timeptr;
|
||||
|
||||
if (mktime(&tm) == (time_t)-1) {
|
||||
tm = defaults;
|
||||
}
|
||||
}
|
||||
|
||||
format_ptr = format_str;
|
||||
chars_written = 0;
|
||||
|
||||
while (*format_ptr) {
|
||||
if (!(curr_format = strchr(format_ptr, '%'))) {
|
||||
if ((num_chars = strlen(format_ptr)) != 0) {
|
||||
if (num_chars <= space_remaining) {
|
||||
memcpy(str, format_ptr, num_chars);
|
||||
|
||||
chars_written += num_chars;
|
||||
str += num_chars;
|
||||
space_remaining -= num_chars;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if ((num_chars = curr_format - format_ptr) != 0) {
|
||||
if (num_chars <= space_remaining) {
|
||||
memcpy(str, format_ptr, num_chars);
|
||||
|
||||
chars_written += num_chars;
|
||||
str += num_chars;
|
||||
space_remaining -= num_chars;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
format_ptr = curr_format;
|
||||
if (format_ptr[1] == 'E' || format_ptr[1] == 'O') {
|
||||
++format_ptr;
|
||||
}
|
||||
|
||||
switch (*++format_ptr) {
|
||||
case 'a':
|
||||
strcpy(name, find_name(locale->time_cmpt_ptr->Day_Names, tm.tm_wday * 2));
|
||||
num_chars = emit_string(str, strlen(name), &space_remaining, name);
|
||||
break;
|
||||
|
||||
case 'A':
|
||||
strcpy(name, find_name(locale->time_cmpt_ptr->Day_Names, tm.tm_wday * 2 + 1));
|
||||
num_chars = emit_string(str, strlen(name), &space_remaining, name);
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
case 'h': {
|
||||
num_chars =
|
||||
emit(str, 3, &space_remaining, "%.3s",
|
||||
find_name(locale->time_cmpt_ptr->MonthNames, tm.tm_mon * 2));
|
||||
break;
|
||||
}
|
||||
|
||||
case 'B':
|
||||
strcpy(name, find_name(locale->time_cmpt_ptr->MonthNames, tm.tm_mon * 2 + 1));
|
||||
num_chars = emit_string(str, strlen(name), &space_remaining, name);
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
num_chars = strftime(str, space_remaining + 1, locale->time_cmpt_ptr->DateTime_Format, &tm);
|
||||
space_remaining -= num_chars;
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
num_chars = emit(str, 2, &space_remaining, "%.2d", tm.tm_mday);
|
||||
break;
|
||||
|
||||
case 'D':
|
||||
num_chars = strftime(str, space_remaining + 1, "%m/%d/%y", &tm);
|
||||
break;
|
||||
|
||||
case 'e':
|
||||
num_chars = emit(str, 2, &space_remaining, "%2d", tm.tm_mday);
|
||||
break;
|
||||
|
||||
case 'F':
|
||||
num_chars =
|
||||
emit(str, 10, &space_remaining, "%.4d-%.2d-%.2d", tm.tm_year + 1900, tm.tm_mon + 1,
|
||||
tm.tm_mday);
|
||||
break;
|
||||
|
||||
case 'g':
|
||||
ISO8601WeekNo = __MSL_ISO8601Week(timeptr, &ISO8601Year);
|
||||
num_chars = emit(str, 2, &space_remaining, "%.2d", ISO8601Year % 100);
|
||||
break;
|
||||
|
||||
case 'G':
|
||||
ISO8601WeekNo = __MSL_ISO8601Week(timeptr, &ISO8601Year);
|
||||
num_chars = emit(str, 4, &space_remaining, "%.4d", ISO8601Year + 1900);
|
||||
break;
|
||||
|
||||
case 'H':
|
||||
num_chars = emit(str, 2, &space_remaining, "%.2d", tm.tm_hour);
|
||||
break;
|
||||
|
||||
case 'I':
|
||||
num_chars = emit(str, 2, &space_remaining, "%.2d",
|
||||
(n = tm.tm_hour % 12) ? n : 12);
|
||||
break;
|
||||
|
||||
case 'j':
|
||||
num_chars = emit(str, 3, &space_remaining, "%.3d", tm.tm_yday + 1);
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
num_chars = emit(str, 2, &space_remaining, "%.2d", tm.tm_mon + 1);
|
||||
break;
|
||||
|
||||
case 'M':
|
||||
num_chars = emit(str, 2, &space_remaining, "%.2d", tm.tm_min);
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
num_chars = emit(str, 2, &space_remaining, "\n");
|
||||
break;
|
||||
|
||||
case 'p': {
|
||||
char* name;
|
||||
|
||||
name = find_name(locale->time_cmpt_ptr->am_pm, tm.tm_hour < 12 ? 0 : 1);
|
||||
num_chars = emit_string(str, strlen(name), &space_remaining, name);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'r':
|
||||
num_chars = strftime(str, space_remaining + 1, locale->time_cmpt_ptr->Twelve_hr_format, &tm);
|
||||
space_remaining -= num_chars;
|
||||
break;
|
||||
|
||||
case 'R':
|
||||
num_chars = strftime(str, space_remaining + 1, "%H:%M", &tm);
|
||||
space_remaining -= num_chars;
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
num_chars = emit(str, 2, &space_remaining, "%.2d", tm.tm_sec);
|
||||
break;
|
||||
|
||||
case 't':
|
||||
num_chars = emit(str, 2, &space_remaining, "\t");
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
num_chars = strftime(str, space_remaining + 1, "%H:%M:%S", &tm);
|
||||
space_remaining -= num_chars;
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
if (tm.tm_wday == 0) {
|
||||
num_chars = emit(str, 1, &space_remaining, "7");
|
||||
} else {
|
||||
num_chars = emit(str, 1, &space_remaining, "%.1d", tm.tm_wday);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'U':
|
||||
num_chars = emit(str, 2, &space_remaining, "%.2d", week_num(&tm, 0));
|
||||
break;
|
||||
|
||||
case 'V':
|
||||
ISO8601WeekNo = __MSL_ISO8601Week(timeptr, &ISO8601Year);
|
||||
num_chars = emit(str, 2, &space_remaining, "%.2d", ISO8601WeekNo);
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
num_chars = emit(str, 1, &space_remaining, "%.1d", tm.tm_wday);
|
||||
break;
|
||||
|
||||
case 'W':
|
||||
num_chars = emit(str, 2, &space_remaining, "%.2d", week_num(&tm, 1));
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
num_chars = strftime(str, space_remaining + 1, locale->time_cmpt_ptr->Date_Format, &tm);
|
||||
space_remaining -= num_chars;
|
||||
break;
|
||||
|
||||
case 'X':
|
||||
num_chars = strftime(str, space_remaining + 1, locale->time_cmpt_ptr->Time_Format, &tm);
|
||||
space_remaining -= num_chars;
|
||||
break;
|
||||
|
||||
case 'y':
|
||||
case 'C':
|
||||
num_chars = emit(str, 2, &space_remaining, "%.2d", tm.tm_year % 100);
|
||||
break;
|
||||
|
||||
case 'Y':
|
||||
num_chars = emit(str, 4, &space_remaining, "%.4d", tm.tm_year + 1900);
|
||||
break;
|
||||
|
||||
case 'z': {
|
||||
time_t local, utc, now;
|
||||
struct tm localtm, *utctmptr;
|
||||
double diff, diffmins, diffhours;
|
||||
|
||||
now = time(NULL);
|
||||
utctmptr = gmtime(&now);
|
||||
if (utctmptr == NULL) {
|
||||
num_chars = emit(str, 4, &space_remaining, "0000");
|
||||
} else {
|
||||
localtm = *localtime(&now);
|
||||
local = mktime(&localtm);
|
||||
utc = mktime(utctmptr);
|
||||
diff = difftime(local, utc);
|
||||
diffhours = (int)diff / 3600;
|
||||
diffmins = __abs(diff / msl_seconds_per_minute - msl_seconds_per_minute * diffhours);
|
||||
num_chars = emit(str, 5, &space_remaining, "%+03.0f%02.0f", diffhours, diffmins);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'Z': {
|
||||
char* TimeZone = locale->time_cmpt_ptr->TimeZone;
|
||||
|
||||
if (*TimeZone == '\0') {
|
||||
num_chars = 0;
|
||||
*str = '\0';
|
||||
} else {
|
||||
num_chars = emit_string(str, strlen(TimeZone), &space_remaining, TimeZone);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case '%':
|
||||
num_chars = emit(str, 2, &space_remaining, "%%", *format_ptr);
|
||||
break;
|
||||
|
||||
default:
|
||||
num_chars = emit(str, 2, &space_remaining, "%%%c", *format_ptr);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!num_chars) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
chars_written += num_chars;
|
||||
str += num_chars;
|
||||
++format_ptr;
|
||||
}
|
||||
|
||||
*str = 0;
|
||||
if (max_size < chars_written) {
|
||||
return 0;
|
||||
} else {
|
||||
return chars_written;
|
||||
}
|
||||
}
|
||||
|
||||
const double msl_seconds_per_day = 86400.0;
|
||||
const double msl_days_per_week = 7.0;
|
||||
const double msl_seconds_per_minute = 60.0;
|
||||
1320
libs/MSL/src/MSL_Common/wprintf.c
Normal file
1320
libs/MSL/src/MSL_Common/wprintf.c
Normal file
File diff suppressed because it is too large
Load Diff
671
libs/MSL/src/MSL_Common_Embedded/ansi_fp.c
Normal file
671
libs/MSL/src/MSL_Common_Embedded/ansi_fp.c
Normal file
@@ -0,0 +1,671 @@
|
||||
#include <internal/format_runtime.h>
|
||||
#define LDBL_MAX DBL_MAX
|
||||
|
||||
|
||||
|
||||
typedef unsigned long long d_int;
|
||||
|
||||
static inline int __count_trailing_zerol(unsigned long x) { return 32 - __cntlzw(~x & (x - 1)); }
|
||||
|
||||
static int __count_trailing_zero(double n) {
|
||||
unsigned long* array = (unsigned long*)&n;
|
||||
|
||||
unsigned long hi = array[0] | 0x100000;
|
||||
unsigned long lo = array[1];
|
||||
int zeros = __count_trailing_zerol(lo);
|
||||
|
||||
if (lo == 0) {
|
||||
return 32 + __count_trailing_zerol(hi);
|
||||
}
|
||||
return zeros;
|
||||
}
|
||||
|
||||
static int __must_round(const decimal* d, int digits) {
|
||||
unsigned char const* i = d->sig.text + digits;
|
||||
|
||||
if (*i > 5) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (*i < 5) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
{
|
||||
unsigned char const* e = d->sig.text + d->sig.length;
|
||||
|
||||
for (i++; i < e; i++) {
|
||||
if (*i != 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (d->sig.text[digits - 1] & 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void __dorounddecup(decimal* d, int digits) {
|
||||
unsigned char* b = d->sig.text;
|
||||
unsigned char* i = b + digits - 1;
|
||||
|
||||
while (1) {
|
||||
if (*i < 9) {
|
||||
*i += 1;
|
||||
break;
|
||||
}
|
||||
if (i == b) {
|
||||
*i = 1;
|
||||
d->exp++;
|
||||
break;
|
||||
}
|
||||
*i-- = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void __rounddec(decimal* d, int digits) {
|
||||
if (digits > 0 && digits < d->sig.length) {
|
||||
int unkBool = __must_round(d, digits);
|
||||
d->sig.length = digits;
|
||||
|
||||
if (unkBool >= 0) {
|
||||
__dorounddecup(d, digits);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void __ull2dec(decimal* result, unsigned long long val) {
|
||||
result->sign = 0;
|
||||
result->sig.length = 0;
|
||||
|
||||
for (; val != 0; val /= 10) {
|
||||
result->sig.text[result->sig.length++] = (unsigned char)(val % 10);
|
||||
}
|
||||
|
||||
{
|
||||
unsigned char* i = result->sig.text;
|
||||
unsigned char* j = result->sig.text + result->sig.length;
|
||||
|
||||
for (; i < --j; ++i) {
|
||||
unsigned char t = *i;
|
||||
*i = *j;
|
||||
*j = t;
|
||||
}
|
||||
}
|
||||
|
||||
result->exp = result->sig.length - 1;
|
||||
}
|
||||
|
||||
static void __timesdec(decimal* result, const decimal* x, const decimal* y) {
|
||||
unsigned long accumulator = 0;
|
||||
unsigned char mantissa[SIGDIGLEN * 2];
|
||||
int i = x->sig.length + y->sig.length - 1;
|
||||
unsigned char* pDigit;
|
||||
unsigned char* ip = mantissa + i + 1;
|
||||
unsigned char* ep = ip;
|
||||
|
||||
result->sign = 0;
|
||||
|
||||
for (; i > 0; i--) {
|
||||
int k = y->sig.length - 1;
|
||||
int j = i - k - 1;
|
||||
int l;
|
||||
int t;
|
||||
const unsigned char* jp;
|
||||
const unsigned char* kp;
|
||||
|
||||
if (j < 0) {
|
||||
j = 0;
|
||||
k = i - 1;
|
||||
}
|
||||
|
||||
jp = x->sig.text + j;
|
||||
kp = y->sig.text + k;
|
||||
l = k + 1;
|
||||
t = x->sig.length - j;
|
||||
|
||||
if (l > t)
|
||||
l = t;
|
||||
|
||||
for (; l > 0; l--, jp++, kp--) {
|
||||
accumulator += *jp * *kp;
|
||||
}
|
||||
|
||||
*--ip = (unsigned char)(accumulator % 10);
|
||||
accumulator /= 10;
|
||||
}
|
||||
|
||||
result->exp = (short)(x->exp + y->exp);
|
||||
|
||||
if (accumulator) {
|
||||
*--ip = (unsigned char)(accumulator);
|
||||
result->exp++;
|
||||
}
|
||||
|
||||
for (i = 0; i < SIGDIGLEN && ip < ep; i++, ip++) {
|
||||
result->sig.text[i] = *ip;
|
||||
}
|
||||
result->sig.length = (unsigned char)(i);
|
||||
|
||||
if (ip < ep && *ip >= 5) {
|
||||
if (*ip == 5) {
|
||||
unsigned char* jp = ip + 1;
|
||||
for (; jp < ep; jp++) {
|
||||
if (*jp != 0)
|
||||
goto round;
|
||||
}
|
||||
if ((ip[-1] & 1) == 0)
|
||||
return;
|
||||
}
|
||||
round:
|
||||
__dorounddecup(result, result->sig.length);
|
||||
}
|
||||
}
|
||||
|
||||
static void __str2dec(decimal* d, const char* s, short exp) {
|
||||
int i;
|
||||
|
||||
d->exp = exp;
|
||||
d->sign = 0;
|
||||
|
||||
for (i = 0; i < SIGDIGLEN && *s;) {
|
||||
d->sig.text[i++] = *s++ - '0';
|
||||
}
|
||||
d->sig.length = i;
|
||||
|
||||
if (*s != 0) {
|
||||
if (*s < 5)
|
||||
return;
|
||||
if (*s > 5)
|
||||
goto round;
|
||||
|
||||
{
|
||||
const char* p = s + 1;
|
||||
|
||||
for (; *p != 0; p++) {
|
||||
if (*p != '0')
|
||||
goto round;
|
||||
}
|
||||
|
||||
if ((d->sig.text[i - 1] & 1) == 0)
|
||||
return;
|
||||
}
|
||||
round:
|
||||
__dorounddecup(d, d->sig.length);
|
||||
}
|
||||
}
|
||||
|
||||
static void __two_exp(decimal* result, long exp) {
|
||||
switch (exp) {
|
||||
case -64:
|
||||
__str2dec(result, "542101086242752217003726400434970855712890625", -20);
|
||||
return;
|
||||
case -53:
|
||||
__str2dec(result, "11102230246251565404236316680908203125", -16);
|
||||
return;
|
||||
case -32:
|
||||
__str2dec(result, "23283064365386962890625", -10);
|
||||
return;
|
||||
case -16:
|
||||
__str2dec(result, "152587890625", -5);
|
||||
return;
|
||||
case -8:
|
||||
__str2dec(result, "390625", -3);
|
||||
return;
|
||||
case -7:
|
||||
__str2dec(result, "78125", -3);
|
||||
return;
|
||||
case -6:
|
||||
__str2dec(result, "15625", -2);
|
||||
return;
|
||||
case -5:
|
||||
__str2dec(result, "3125", -2);
|
||||
return;
|
||||
case -4:
|
||||
__str2dec(result, "625", -2);
|
||||
return;
|
||||
case -3:
|
||||
__str2dec(result, "125", -1);
|
||||
return;
|
||||
case -2:
|
||||
__str2dec(result, "25", -1);
|
||||
return;
|
||||
case -1:
|
||||
__str2dec(result, "5", -1);
|
||||
return;
|
||||
case 0:
|
||||
__str2dec(result, "1", 0);
|
||||
return;
|
||||
case 1:
|
||||
__str2dec(result, "2", 0);
|
||||
return;
|
||||
case 2:
|
||||
__str2dec(result, "4", 0);
|
||||
return;
|
||||
case 3:
|
||||
__str2dec(result, "8", 0);
|
||||
return;
|
||||
case 4:
|
||||
__str2dec(result, "16", 1);
|
||||
return;
|
||||
case 5:
|
||||
__str2dec(result, "32", 1);
|
||||
return;
|
||||
case 6:
|
||||
__str2dec(result, "64", 1);
|
||||
return;
|
||||
case 7:
|
||||
__str2dec(result, "128", 2);
|
||||
return;
|
||||
case 8:
|
||||
__str2dec(result, "256", 2);
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
decimal x2, temp;
|
||||
|
||||
__two_exp(&x2, exp / 2);
|
||||
__timesdec(result, &x2, &x2);
|
||||
|
||||
if (exp & 1) {
|
||||
temp = *result;
|
||||
if (exp > 0) {
|
||||
__str2dec(&x2, "2", 0);
|
||||
} else {
|
||||
__str2dec(&x2, "5", -1);
|
||||
}
|
||||
__timesdec(result, &temp, &x2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int __equals_dec(const decimal* x, const decimal* y) {
|
||||
if (x->sig.text[0] == 0) {
|
||||
return y->sig.text[0] == 0;
|
||||
}
|
||||
|
||||
if (y->sig.text[0] == 0) {
|
||||
return x->sig.text[0] == 0;
|
||||
}
|
||||
|
||||
if (x->exp == y->exp) {
|
||||
int i;
|
||||
int l = x->sig.length;
|
||||
|
||||
if (l > y->sig.length) {
|
||||
l = y->sig.length;
|
||||
}
|
||||
|
||||
for (i = 0; i < l; i++) {
|
||||
if (x->sig.text[i] != y->sig.text[i]) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (l == x->sig.length) {
|
||||
x = y;
|
||||
}
|
||||
|
||||
for (; i < x->sig.length; i++) {
|
||||
if (x->sig.text[i] != 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __less_dec(const decimal* x, const decimal* y) {
|
||||
if (x->sig.text[0] == 0) {
|
||||
unsigned char leading_digit = y->sig.text[0];
|
||||
return ((unsigned long)(-leading_digit | leading_digit) >> 31);
|
||||
}
|
||||
|
||||
if (y->sig.text[0] == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (x->exp == y->exp) {
|
||||
int i;
|
||||
int l = x->sig.length;
|
||||
|
||||
if (l > y->sig.length) {
|
||||
l = y->sig.length;
|
||||
}
|
||||
|
||||
for (i = 0; i < l; i++) {
|
||||
if (x->sig.text[i] < y->sig.text[i]) {
|
||||
return 1;
|
||||
} else if (y->sig.text[i] < x->sig.text[i]) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (l == x->sig.length) {
|
||||
for (; i < y->sig.length; i++) {
|
||||
if (y->sig.text[i] != 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return x->exp < y->exp;
|
||||
}
|
||||
|
||||
static void __minus_dec(decimal* z, const decimal* x, const decimal* y) {
|
||||
int zlen, dexp;
|
||||
unsigned char *ib, *i, *ie;
|
||||
unsigned char const *jb, *j, *jn;
|
||||
|
||||
*z = *x;
|
||||
|
||||
if (y->sig.text[0] == 0)
|
||||
return;
|
||||
|
||||
zlen = z->sig.length;
|
||||
if (zlen < y->sig.length)
|
||||
zlen = y->sig.length;
|
||||
|
||||
dexp = z->exp - y->exp;
|
||||
zlen += dexp;
|
||||
|
||||
if (zlen > SIGDIGLEN)
|
||||
zlen = SIGDIGLEN;
|
||||
|
||||
while (z->sig.length < zlen) {
|
||||
z->sig.text[z->sig.length++] = 0;
|
||||
}
|
||||
|
||||
ib = z->sig.text;
|
||||
i = ib + zlen;
|
||||
|
||||
if (y->sig.length + dexp < zlen) {
|
||||
i = ib + (y->sig.length + dexp);
|
||||
}
|
||||
|
||||
jb = y->sig.text;
|
||||
j = jb + (i - ib - dexp);
|
||||
jn = j;
|
||||
|
||||
while (i > ib && j > jb) {
|
||||
i--;
|
||||
j--;
|
||||
if (*i < *j) {
|
||||
unsigned char* k = i - 1;
|
||||
while (*k == 0)
|
||||
k--;
|
||||
while (k != i) {
|
||||
--*k;
|
||||
*++k += 10;
|
||||
}
|
||||
}
|
||||
*i -= *j;
|
||||
}
|
||||
|
||||
if (jn - jb < y->sig.length) {
|
||||
int round_down = 0;
|
||||
if (*jn < 5)
|
||||
round_down = 1;
|
||||
else if (*jn == 5) {
|
||||
unsigned char const* ibPtr = y->sig.text + y->sig.length;
|
||||
|
||||
for (j = jn + 1; j < ibPtr; j++) {
|
||||
if (*j != 0)
|
||||
goto done;
|
||||
}
|
||||
i = ib + (jn - jb) + dexp - 1;
|
||||
if (*i & 1)
|
||||
round_down = 1;
|
||||
}
|
||||
if (round_down) {
|
||||
if (*i < 1) {
|
||||
unsigned char* k = i - 1;
|
||||
while (*k == 0)
|
||||
k--;
|
||||
while (k != i) {
|
||||
--*k;
|
||||
*++k += 10;
|
||||
}
|
||||
}
|
||||
*i -= 1;
|
||||
}
|
||||
}
|
||||
done:
|
||||
for (i = ib; *i == 0; ++i) {}
|
||||
|
||||
if (i > ib) {
|
||||
unsigned char dl = (unsigned char)(i - ib);
|
||||
z->exp -= dl;
|
||||
ie = ib + z->sig.length;
|
||||
for (; i < ie; ++i, ++ib)
|
||||
*ib = *i;
|
||||
z->sig.length -= dl;
|
||||
}
|
||||
|
||||
ib = z->sig.text;
|
||||
for (i = ib + z->sig.length; i > ib;) {
|
||||
i--;
|
||||
if (*i != 0)
|
||||
break;
|
||||
}
|
||||
z->sig.length = (unsigned char)(i - ib + 1);
|
||||
}
|
||||
|
||||
static void __num2dec_internal(decimal* d, double x) {
|
||||
signed char sign = (signed char)(__signbitd(x) != 0);
|
||||
|
||||
if (x == 0) {
|
||||
d->sign = sign;
|
||||
d->exp = 0;
|
||||
d->sig.length = 1;
|
||||
d->sig.text[0] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isfinite(x)) {
|
||||
d->sign = sign;
|
||||
d->exp = 0;
|
||||
d->sig.length = 1;
|
||||
d->sig.text[0] = fpclassify(x) == 1 ? 'N' : 'I';
|
||||
return;
|
||||
}
|
||||
|
||||
if (sign != 0) {
|
||||
x = -x;
|
||||
}
|
||||
|
||||
{
|
||||
int exp;
|
||||
double frac = frexp(x, &exp);
|
||||
int num_bits_extract = LDBL_MANT_DIG - __count_trailing_zero(frac);
|
||||
decimal int_d, pow2_d;
|
||||
|
||||
__two_exp(&pow2_d, exp - num_bits_extract);
|
||||
__ull2dec(&int_d, ldexp(frac, num_bits_extract));
|
||||
__timesdec(d, &int_d, &pow2_d);
|
||||
d->sign = sign;
|
||||
}
|
||||
}
|
||||
|
||||
void __num2dec(const decform* form, double x, decimal* d) {
|
||||
short digits = form->digits;
|
||||
int i;
|
||||
__num2dec_internal(d, x);
|
||||
|
||||
if (d->sig.text[0] > 9) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (digits > SIGDIGLEN) {
|
||||
digits = SIGDIGLEN;
|
||||
}
|
||||
|
||||
__rounddec(d, digits);
|
||||
|
||||
while (d->sig.length < digits) {
|
||||
d->sig.text[d->sig.length++] = 0;
|
||||
}
|
||||
|
||||
d->exp -= d->sig.length - 1;
|
||||
|
||||
for (i = 0; i < d->sig.length; i++) {
|
||||
d->sig.text[i] += '0';
|
||||
}
|
||||
}
|
||||
|
||||
double __dec2num(const decimal* d) {
|
||||
if (d->sig.length <= 0) {
|
||||
return copysign(0.0, d->sign == 0 ? 1.0 : -1.0);
|
||||
}
|
||||
|
||||
switch (d->sig.text[0]) {
|
||||
case '0':
|
||||
return copysign(0.0, d->sign == 0 ? 1.0 : -1.0);
|
||||
case 'I':
|
||||
return copysign((double)INFINITY, d->sign == 0 ? 1.0 : -1.0);
|
||||
case 'N': {
|
||||
double result;
|
||||
d_int* ll = (d_int*)&result;
|
||||
|
||||
*ll = 0x7FF0000000000000;
|
||||
if (d->sign)
|
||||
*ll |= 0x8000000000000000;
|
||||
*ll |= 0x8000000000000;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
static double pow_10[8] = {1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8};
|
||||
|
||||
decimal dec = *d;
|
||||
unsigned char* i = dec.sig.text;
|
||||
unsigned char* e = i + dec.sig.length;
|
||||
double first_guess;
|
||||
int exponent;
|
||||
|
||||
for (; i < e; ++i)
|
||||
*i -= '0';
|
||||
dec.exp += dec.sig.length - 1;
|
||||
exponent = dec.exp;
|
||||
|
||||
{
|
||||
decimal max;
|
||||
|
||||
__str2dec(&max, "179769313486231580793728714053034151", 308);
|
||||
if (__less_dec(&max, &dec)) {
|
||||
return copysign((double)INFINITY, d->sign == 0 ? 1.0 : -1.0);
|
||||
}
|
||||
}
|
||||
|
||||
i = dec.sig.text;
|
||||
first_guess = *i++;
|
||||
|
||||
while (i < e) {
|
||||
unsigned long ival = 0;
|
||||
int j;
|
||||
double temp1, temp2;
|
||||
int ndig = (int)(e - i) % 8;
|
||||
|
||||
if (ndig == 0)
|
||||
ndig = 8;
|
||||
|
||||
for (j = 0; j < ndig; ++j, ++i) {
|
||||
ival = ival * 10 + *i;
|
||||
}
|
||||
|
||||
temp1 = first_guess * pow_10[ndig - 1];
|
||||
temp2 = temp1 + ival;
|
||||
|
||||
if (ival != 0 && temp1 == temp2)
|
||||
break;
|
||||
|
||||
first_guess = temp2;
|
||||
exponent -= ndig;
|
||||
}
|
||||
|
||||
if (exponent < 0) {
|
||||
first_guess /= pow(5.0, -exponent);
|
||||
} else {
|
||||
first_guess *= pow(5.0, exponent);
|
||||
}
|
||||
|
||||
first_guess = ldexp(first_guess, exponent);
|
||||
|
||||
if (fpclassify(first_guess) == 2) {
|
||||
first_guess = LDBL_MAX;
|
||||
}
|
||||
|
||||
{
|
||||
decimal feedback1, feedback2, difflow, diffhigh;
|
||||
double next_guess;
|
||||
d_int* ull = (d_int*)&next_guess;
|
||||
int guessed_low = 0;
|
||||
|
||||
__num2dec_internal(&feedback1, first_guess);
|
||||
|
||||
if (__equals_dec(&feedback1, &dec)) {
|
||||
goto done;
|
||||
}
|
||||
if (__less_dec(&feedback1, &dec)) {
|
||||
guessed_low = 1;
|
||||
}
|
||||
|
||||
next_guess = first_guess;
|
||||
|
||||
while (1) {
|
||||
if (guessed_low) {
|
||||
++*ull;
|
||||
if (fpclassify(next_guess) == 2) {
|
||||
goto done;
|
||||
}
|
||||
} else {
|
||||
--*ull;
|
||||
}
|
||||
|
||||
__num2dec_internal(&feedback2, next_guess);
|
||||
if (guessed_low && !__less_dec(&feedback2, &dec)) {
|
||||
break;
|
||||
} else if (!guessed_low && !__less_dec(&dec, &feedback2)) {
|
||||
difflow = feedback1;
|
||||
feedback1 = feedback2;
|
||||
feedback2 = difflow;
|
||||
{
|
||||
double temp = first_guess;
|
||||
first_guess = next_guess;
|
||||
next_guess = temp;
|
||||
}
|
||||
break;
|
||||
}
|
||||
feedback1 = feedback2;
|
||||
first_guess = next_guess;
|
||||
}
|
||||
|
||||
__minus_dec(&difflow, &dec, &feedback1);
|
||||
__minus_dec(&diffhigh, &feedback2, &dec);
|
||||
|
||||
if (__equals_dec(&difflow, &diffhigh)) {
|
||||
if (*(unsigned long long*)&first_guess & 1) {
|
||||
first_guess = next_guess;
|
||||
}
|
||||
} else if (!__less_dec(&difflow, &diffhigh)) {
|
||||
first_guess = next_guess;
|
||||
}
|
||||
}
|
||||
done:
|
||||
if (dec.sign) {
|
||||
first_guess = -first_guess;
|
||||
}
|
||||
return first_guess;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
423
libs/RVLMiddleware/eZiText/src/clib/zi8dawg.c
Normal file
423
libs/RVLMiddleware/eZiText/src/clib/zi8dawg.c
Normal file
@@ -0,0 +1,423 @@
|
||||
#include <zi8clib/zitypes.h>
|
||||
#include <zi8clib/zierror.h>
|
||||
#include <zi8clib/zconvert.h>
|
||||
|
||||
ziU32 Zi8GetTableSize(ziU8 language, ziU8 table, ziPtr work);
|
||||
ziU32 Zi8GetTableAddress(ziU8 language, ziU8 table, ziPtr work);
|
||||
ziU16 Zi8GetTableCount(ziU8 language, ziU8 table, ziPtr work);
|
||||
ziU8* ZiDAWGGetGraph(zi8DawgCtx* context);
|
||||
ziU8* ZiDAWGGetGraphInfo(zi8DawgCtx* context, ziU8* table, ziS16* keys);
|
||||
ziU32 ZiDAWGgetCHARattribute(zi8DawgCtx* context, ziU8* graph, ziPtr work);
|
||||
ziU8 ZiDAWGgetEOWattribute(ziU8* graph);
|
||||
ziU8* ZiDAWGGetChild(ziU8* graph);
|
||||
ziU8* ZiDAWGGetSibling(ziU8* graph);
|
||||
|
||||
ziU32 Zi8MatchROMdata0(ziWChar* elements, ziU32 count, ziU8 language,
|
||||
ziWChar* output, ziU16 capacity, ziU8 mode, ziU8 status,
|
||||
ziU8 graphTable, ziU8 keyTable, ziU8 acceptPrefix,
|
||||
ziU8* prefixLength, zi8DawgCtx* context, ziU8* search,
|
||||
ziPtr __zi8_work_data) {
|
||||
ziBool searching;
|
||||
ziS32 tableSize;
|
||||
ziU8* graph;
|
||||
ziU16 key;
|
||||
ziU8 endOfWord;
|
||||
zi8DawgRec* current;
|
||||
ziU16 index;
|
||||
ziU16 depth;
|
||||
zi8DawgRec* records = context->recs;
|
||||
ziU8 result = 0;
|
||||
ziU32 keyCount;
|
||||
ziU8* table;
|
||||
ziU16 keys[3];
|
||||
|
||||
if (language != context->lang || graphTable != context->key) {
|
||||
records[0].key = 0;
|
||||
}
|
||||
if ((ziU8)count != 1 || mode == 0 || graphTable != 0xe) {
|
||||
if (status != 0) {
|
||||
if (records[context->cnt - 1].node == (ziU8*)context->unk_0x338) goto finish_graph;
|
||||
for (index = 0; (ziU16)index < (ziU8)count; index++) {
|
||||
if (records[(ziU16)index].key != elements[(ziU16)index] &&
|
||||
(records[(ziU16)index].attr & 0xffff) != elements[(ziU16)index]) goto finish_graph;
|
||||
}
|
||||
if (mode == 1) acceptPrefix = 0;
|
||||
} else {
|
||||
if (ZI_WORK->unk_0x141E == 0 || graphTable != 0xc ||
|
||||
(tableSize = Zi8GetTableSize(language, ZI_WORK->unk_0x141E, ZI_WORK)) == 0) {
|
||||
tableSize = Zi8GetTableSize(language, graphTable, ZI_WORK);
|
||||
if (tableSize == 0) {
|
||||
Zi8LogError(0x961, ZI_WORK);
|
||||
goto finish_graph;
|
||||
}
|
||||
table = (ziU8*)Zi8GetTableAddress(language, graphTable, ZI_WORK);
|
||||
} else {
|
||||
table = (ziU8*)Zi8GetTableAddress(language, ZI_WORK->unk_0x141E, ZI_WORK);
|
||||
keyTable = ZI_WORK->unk_0x141E + 1;
|
||||
}
|
||||
context->table = table;
|
||||
context->cap = (((ziU16)context->table[2] << 8) + (ziU16)context->table[3]) / 3;
|
||||
context->p08 = context->table + 4;
|
||||
context->p0C = context->table + context->cap * 2 + 4;
|
||||
context->lang = language;
|
||||
context->key = graphTable;
|
||||
index = 0;
|
||||
while ((ziU16)index < (ziU8)count && records[(ziU16)index].key == elements[(ziU16)index]) {
|
||||
index++;
|
||||
}
|
||||
if ((ziU16)index < 2) {
|
||||
key = Zi8GetTableSize(language, keyTable, ZI_WORK);
|
||||
if (key == 0 || ZI_WORK->userKeys[language] != 0) {
|
||||
graph = ZiDAWGGetGraph(context);
|
||||
records[0].node = graph;
|
||||
context->unk_0x338 = 0;
|
||||
context->p14 = 0;
|
||||
} else {
|
||||
index = 0;
|
||||
while (1) {
|
||||
if ((ziU8)count < 2) keyCount = (ziU8)count;
|
||||
else keyCount = 2;
|
||||
if (keyCount <= (ziU16)index) break;
|
||||
key = Zi8ConvertWC2Key(elements[(ziU16)index], language, ZI_WORK);
|
||||
keys[(ziU16)index] = key;
|
||||
if (keys[(ziU16)index] == 0) keys[(ziU16)index] = elements[(ziU16)index];
|
||||
index++;
|
||||
}
|
||||
keys[(ziU16)index] = 0;
|
||||
table = (ziU8*)Zi8GetTableAddress(language, keyTable, ZI_WORK);
|
||||
context->p14 = table + 2;
|
||||
records[0].node = ZiDAWGGetGraphInfo(context, table + context->cap * 2 + 2, (ziS16*)keys);
|
||||
}
|
||||
records[0].key = 0;
|
||||
if (records[0].node == 0) goto finish_graph;
|
||||
} else {
|
||||
records[0].node = records[(ziU16)index - 1].back;
|
||||
}
|
||||
context->cnt = 1;
|
||||
search[1] = count;
|
||||
search[0] = 0;
|
||||
if (mode == 1) {
|
||||
search[0] = 1;
|
||||
acceptPrefix = 0;
|
||||
} else if (mode == 0 && acceptPrefix == 0) {
|
||||
search[1]++;
|
||||
}
|
||||
}
|
||||
searching = 1;
|
||||
depth = context->cnt;
|
||||
while ((current = &records[depth - 1], searching) && context->cnt != 0 &&
|
||||
current->node != (ziU8*)context->unk_0x338 && context->cnt <= capacity) {
|
||||
current->attr = ZiDAWGgetCHARattribute(context, current->node, ZI_WORK);
|
||||
if ((ziU8)count < context->cnt) {
|
||||
check_word:
|
||||
if (context->cnt < search[1]) goto descend;
|
||||
if (search[0] == 0 || context->cnt <= search[1]) {
|
||||
if (acceptPrefix != 0 || (endOfWord = ZiDAWGgetEOWattribute(current->node)) != 0) {
|
||||
for (depth = 0; depth < context->cnt; depth++) {
|
||||
output[depth] = records[depth].attr;
|
||||
}
|
||||
result = context->cnt;
|
||||
searching = 0;
|
||||
if (acceptPrefix != 0) goto next_sibling;
|
||||
}
|
||||
if (search[0] == 0 || context->cnt < search[1]) goto descend;
|
||||
}
|
||||
next_sibling:
|
||||
while (context->cnt != 0) {
|
||||
graph = ZiDAWGGetSibling(records[context->cnt - 1].node);
|
||||
records[context->cnt - 1].node = graph;
|
||||
if (records[context->cnt - 1].node != 0) break;
|
||||
context->cnt--;
|
||||
}
|
||||
} else {
|
||||
if (context->p14 == 0) {
|
||||
key = Zi8ConvertWC2Key(current->attr & 0xffff, language, ZI_WORK);
|
||||
} else {
|
||||
key = (ziU16)context->p14[(current->attr >> 24) * 2] * 0x100 +
|
||||
(ziU16)context->p14[(current->attr >> 24) * 2 + 1];
|
||||
}
|
||||
if (key != elements[context->cnt - 1] &&
|
||||
(current->attr & 0xffff) != elements[context->cnt - 1]) goto next_sibling;
|
||||
if (current->key != elements[context->cnt - 1]) {
|
||||
current->key = elements[context->cnt - 1];
|
||||
current->back = records[0].node;
|
||||
depth = context->cnt;
|
||||
records[depth].key = 0;
|
||||
}
|
||||
if (prefixLength != 0 && *prefixLength < context->cnt &&
|
||||
(endOfWord = ZiDAWGgetEOWattribute(current->node)) != 0) {
|
||||
*prefixLength = context->cnt;
|
||||
for (depth = 0; depth < context->cnt; depth++) output[depth] = records[depth].attr;
|
||||
}
|
||||
if ((ziU8)count <= context->cnt) goto check_word;
|
||||
descend:
|
||||
graph = ZiDAWGGetChild(records[context->cnt - 1].node);
|
||||
records[context->cnt].node = graph;
|
||||
if (records[context->cnt].node == 0) goto next_sibling;
|
||||
context->cnt++;
|
||||
if (ZI_WORK->unk_0x141F < context->cnt) ZI_WORK->unk_0x141F = context->cnt;
|
||||
}
|
||||
depth = context->cnt;
|
||||
}
|
||||
}
|
||||
finish_graph:
|
||||
return result;
|
||||
}
|
||||
ziU8* NextDawgGroup(ziU8* group, ziU8 language, ziPtr __zi8_work_data)
|
||||
{
|
||||
if (Zi8GetTableSize(language,0x1c,ZI_WORK) != 0) {
|
||||
if (group == 0) {
|
||||
group = (ziU8*)Zi8GetTableAddress(language,0x1c,ZI_WORK);
|
||||
if (group == 0) {
|
||||
Zi8LogError(0x962,ZI_WORK);
|
||||
return 0;
|
||||
}
|
||||
if (ZI_WORK->unk_0x141D == 0) {
|
||||
return group;
|
||||
}
|
||||
}
|
||||
while (group[0] != 0xff || group[1] != 0xff) {
|
||||
group = group + 1;
|
||||
}
|
||||
group = group + 2;
|
||||
if (group[0] == 0xff) {
|
||||
Zi8LogError(0x963,ZI_WORK);
|
||||
return 0;
|
||||
}
|
||||
return group;
|
||||
}
|
||||
Zi8LogError(0x961,ZI_WORK);
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int Zi8MatchROMdata1(ziWChar *elements, ziU8 count, ziU8 language, ziWChar *output, ziU16 capacity, ziU8 mode, unsigned int status, ziU32 groupIndex, char *group, ziU8 acceptPrefix, ziPtr __zi8_work_data)
|
||||
{
|
||||
unsigned int result;
|
||||
ziU32 tableAddress;
|
||||
|
||||
result = 0;
|
||||
if ((status & 0xff) == 0) {
|
||||
ZI_WORK->unk_0x1764 = (ziU8*)group;
|
||||
if (ZI_WORK->unk_0x1764 == 0) {
|
||||
if (Zi8GetTableSize(language & 0xff,0xb,ZI_WORK) != 0) {
|
||||
tableAddress = Zi8GetTableAddress(language & 0xff,0xb,ZI_WORK);
|
||||
ZI_WORK->unk_0x1764 = (ziU8*)tableAddress;
|
||||
}
|
||||
}
|
||||
if (ZI_WORK->unk_0x1764 != 0) {
|
||||
for (; (*ZI_WORK->unk_0x1764 != 0xff && ((groupIndex & 0xff) != 0));
|
||||
groupIndex = groupIndex - 1) {
|
||||
while (*ZI_WORK->unk_0x1764 != 0xff) {
|
||||
ZI_WORK->unk_0x1764 += 2;
|
||||
}
|
||||
ZI_WORK->unk_0x1764++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ZI_WORK->unk_0x1764 == 0) {
|
||||
result = Zi8MatchROMdata0(elements,count,language & 0xff,output,capacity & 0xffff,
|
||||
mode & 0xff,status & 0xff,0,1,acceptPrefix,0,&ZI_WORK->dawgCtx,
|
||||
ZI_WORK->unk_0x1760,ZI_WORK);
|
||||
}
|
||||
else {
|
||||
while (*ZI_WORK->unk_0x1764 != 0xff) {
|
||||
result = Zi8MatchROMdata0(elements,count,language & 0xff,output,
|
||||
capacity & 0xffff,mode & 0xff,status & 0xff,
|
||||
*ZI_WORK->unk_0x1764,
|
||||
ZI_WORK->unk_0x1764[1],acceptPrefix,0,
|
||||
&ZI_WORK->dawgCtx,ZI_WORK->unk_0x1760,ZI_WORK);
|
||||
if ((result & 0xff) != 0) break;
|
||||
ZI_WORK->unk_0x1764 += 2;
|
||||
status = 0;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
unsigned int Zi8MatchROMdata2(ziWChar *elements, unsigned int count, unsigned int language, ziWChar *output, unsigned int capacity, unsigned int mode, unsigned int status, ziU8 reservedMode, ziU8 *group, ziU8 acceptPrefix, ziPtr __zi8_work_data)
|
||||
{
|
||||
ziU16 character;
|
||||
unsigned int result;
|
||||
ziU8 prefixCount;
|
||||
unsigned int index;
|
||||
unsigned int remaining;
|
||||
|
||||
result = 0;
|
||||
if (reservedMode != 0) return 0;
|
||||
if ((status & 0xff) == 0) {
|
||||
ZI_WORK->unk_0x1768 = 0;
|
||||
ZI_WORK->unk_0x17EA = 0;
|
||||
if ((((group == 0) || (*group != '\f')) || ((language & 0xff) != 10)) ||
|
||||
(ZI_WORK->unk_0x141C == '\0')) {
|
||||
ZI_WORK->unk_0x141E = 0;
|
||||
}
|
||||
else {
|
||||
ZI_WORK->unk_0x141E = 0x10;
|
||||
}
|
||||
}
|
||||
search_segment:
|
||||
ZI_WORK->unk_0x141F = 1;
|
||||
result = Zi8MatchROMdata1(elements + (unsigned int)ZI_WORK->unk_0x17EA,
|
||||
count - ZI_WORK->unk_0x17EA & 0xff,language & 0xff,
|
||||
&ZI_WORK->unk_0x17F4[ZI_WORK->unk_0x17EA],
|
||||
capacity & 0xffff,mode & 0xff,status & 0xff,
|
||||
ZI_WORK->unk_0x1768,(char *)group,acceptPrefix,ZI_WORK);
|
||||
if ((result & 0xff) == 0) {
|
||||
if ((((status & 0xff) != 0) || ((count & 0xff) == 1)) ||
|
||||
(((mode & 0xff) == 1 &&
|
||||
((ZI_WORK->unk_0x1768 == 0 &&
|
||||
(prefixCount = Zi8MatchROMdata1(elements + (unsigned int)ZI_WORK->unk_0x17EA,
|
||||
count - ZI_WORK->unk_0x17EA & 0xff,language & 0xff,
|
||||
&ZI_WORK->unk_0x17F4[ZI_WORK->unk_0x17EA],
|
||||
capacity & 0xffff,0,status & 0xff,
|
||||
ZI_WORK->unk_0x1768,(char *)group,acceptPrefix,ZI_WORK),
|
||||
prefixCount != '\0')))))) goto finish_segments;
|
||||
index = Zi8GetTableCount(language & 0xff,0x1f,ZI_WORK);
|
||||
if ((index & 4) == 0) {
|
||||
for (index = 0; (index & 0xff) < (count & 0xff); index = index + 1) {
|
||||
if (elements[index & 0xff] == 0xeff1) goto finish_segments;
|
||||
}
|
||||
}
|
||||
if ((capacity & 0xffff) < (unsigned int)ZI_WORK->unk_0x141F) goto finish_segments;
|
||||
prefixCount = ZI_WORK->unk_0x141F;
|
||||
for (; prefixCount != 0; prefixCount--) {
|
||||
result = Zi8MatchROMdata1(elements + (unsigned int)ZI_WORK->unk_0x17EA,prefixCount,
|
||||
language & 0xff,
|
||||
&ZI_WORK->unk_0x17F4[ZI_WORK->unk_0x17EA],
|
||||
capacity & 0xffff,1,0,ZI_WORK->unk_0x1768,(char *)group,
|
||||
acceptPrefix,ZI_WORK);
|
||||
if ((result & 0xff) != 0) break;
|
||||
}
|
||||
if (prefixCount == 0) goto finish_segments;
|
||||
ZI_WORK->unk_0x17EA = ZI_WORK->unk_0x17EA + ((ziU16)result & 0xff);
|
||||
if ((unsigned int)ZI_WORK->unk_0x17EA == (count & 0xff)) {
|
||||
result = 0;
|
||||
goto finish_segments;
|
||||
}
|
||||
ZI_WORK->unk_0x1768 = ZI_WORK->unk_0x1768 + 1;
|
||||
status = 0;
|
||||
ZI_WORK->unk_0x141E = 0;
|
||||
if ((ZI_WORK->dawgCtx.key == 0) && ((language & 0xff) == 10)) {
|
||||
for (result = 0; (result & 0xff) < (unsigned int)ZI_WORK->unk_0x17EA; result = result + 1) {
|
||||
character = ZI_WORK->unk_0x17F4[result & 0xff];
|
||||
if (character == 0x61 || character == 0x6f || character == 0x75) {
|
||||
ZI_WORK->unk_0x141E = 0x10;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
goto search_segment;
|
||||
}
|
||||
for (remaining = ZI_WORK->unk_0x17EA + result & 0xff; (remaining & 0xff) != 0;
|
||||
remaining = remaining - 1) {
|
||||
output[(remaining & 0xff) - 1] = ZI_WORK->unk_0x17F4[(remaining & 0xff) - 1];
|
||||
}
|
||||
result = result + ZI_WORK->unk_0x17EA & 0xff;
|
||||
finish_segments:
|
||||
return result;
|
||||
}
|
||||
|
||||
ziU8 Zi8MatchROMdata(ziWChar *elements, ziU8 count, ziU8 language, ziWChar *output, ziU16 capacity, ziU8 mode, ziU8 status, ziU8 reservedMode, ziU8 acceptPrefix, ziPtr __zi8_work_data)
|
||||
{
|
||||
ziU8* group;
|
||||
int tableSize;
|
||||
ziU8 found;
|
||||
unsigned int elementCount;
|
||||
unsigned int result;
|
||||
|
||||
elementCount = (unsigned int)count;
|
||||
result = 0;
|
||||
if ((capacity & 0xffff) < (elementCount & 0xff)) {
|
||||
Zi8LogError(0x321,ZI_WORK);
|
||||
}
|
||||
else if ((status & 0xff) == 2) {
|
||||
Zi8LogError(100,ZI_WORK);
|
||||
}
|
||||
else {
|
||||
if ((status & 0xff) == 0) {
|
||||
ZI_WORK->unk_0x17EC = 0;
|
||||
group = NextDawgGroup(0,language & 0xff,ZI_WORK);
|
||||
ZI_WORK->unk_0x17F0 = group;
|
||||
}
|
||||
else if (ZI_WORK->unk_0x17EC != '\0') {
|
||||
Zi8LogError(100,ZI_WORK);
|
||||
goto finish_match;
|
||||
}
|
||||
tableSize = Zi8GetTableSize(language & 0xff,0x1c,ZI_WORK);
|
||||
if (tableSize == 0) {
|
||||
result = Zi8MatchROMdata2(elements,elementCount & 0xff,language & 0xff,output,capacity & 0xffff,
|
||||
mode & 0xff,status & 0xff,reservedMode & 0xff,0,acceptPrefix,ZI_WORK);
|
||||
}
|
||||
else {
|
||||
while (((ZI_WORK->unk_0x17F0 != 0 &&
|
||||
(result = Zi8MatchROMdata2(elements,elementCount & 0xff,language & 0xff,output,capacity & 0xffff,
|
||||
mode & 0xff,status & 0xff,reservedMode & 0xff,
|
||||
(ziU8 *)ZI_WORK->unk_0x17F0,acceptPrefix,ZI_WORK),
|
||||
(result & 0xff) == 0)) &&
|
||||
((status = 0, 1 < (elementCount & 0xff) || ((language & 0xff) != 0x36))))) {
|
||||
group = NextDawgGroup(ZI_WORK->unk_0x17F0,language & 0xff,ZI_WORK);
|
||||
ZI_WORK->unk_0x17F0 = group;
|
||||
}
|
||||
}
|
||||
if (((((result & 0xff) == 0) && ((status & 0xff) == 0)) && ((mode & 0xff) == 1)) &&
|
||||
(((elementCount & 0xff) == 1 && ((capacity & 0xffff) != 0)))) {
|
||||
ZI_WORK->unk_0x17EC = 1;
|
||||
if (tableSize == 0) {
|
||||
found = Zi8MatchROMdata2(elements,elementCount & 0xff,language & 0xff,output,capacity & 0xffff,0,
|
||||
status & 0xff,reservedMode & 0xff,0,acceptPrefix,ZI_WORK);
|
||||
if (found != '\0') {
|
||||
*output = *elements;
|
||||
result = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
group = NextDawgGroup(0,language & 0xff,ZI_WORK);
|
||||
ZI_WORK->unk_0x17F0 = group;
|
||||
while (ZI_WORK->unk_0x17F0 != 0) {
|
||||
found = Zi8MatchROMdata2(elements,elementCount & 0xff,language & 0xff,output,capacity & 0xffff,0,
|
||||
status & 0xff,reservedMode & 0xff,(ziU8 *)ZI_WORK->unk_0x17F0,
|
||||
acceptPrefix,ZI_WORK);
|
||||
if (found != '\0') {
|
||||
*output = *elements;
|
||||
result = 1;
|
||||
break;
|
||||
}
|
||||
group = NextDawgGroup(ZI_WORK->unk_0x17F0,language & 0xff,ZI_WORK);
|
||||
ZI_WORK->unk_0x17F0 = group;
|
||||
}
|
||||
}
|
||||
}
|
||||
Zi8LogError(100,ZI_WORK);
|
||||
}
|
||||
finish_match:
|
||||
return (ziU8)result;
|
||||
}
|
||||
|
||||
void Zi8SyllablesROMdata(ziWChar *elements, ziU8 count, ziU8 language, ziWChar *output, ziU16 capacity, ziU8 status, ziU8* prefixLength, ziU8 reverseOrder, ziPtr __zi8_work_data)
|
||||
{
|
||||
ziU32 keyTable;
|
||||
ziU8 graphTable;
|
||||
|
||||
graphTable = 0x1a;
|
||||
keyTable = 0x1b;
|
||||
if (prefixLength != 0) {
|
||||
*prefixLength = 0;
|
||||
}
|
||||
if (reverseOrder != 0) {
|
||||
graphTable = 0x18;
|
||||
keyTable = 0x19;
|
||||
}
|
||||
if (Zi8GetTableSize(language & 0xff,graphTable,ZI_WORK) == 0) {
|
||||
if (graphTable == 0x1a) {
|
||||
graphTable = 0x18;
|
||||
keyTable = 0x19;
|
||||
}
|
||||
else {
|
||||
graphTable = 0x1a;
|
||||
keyTable = 0x1b;
|
||||
}
|
||||
}
|
||||
Zi8MatchROMdata0(elements,count,language & 0xff,output,capacity,1,status,graphTable,keyTable,0,(ziU8 *)prefixLength,
|
||||
&ZI_WORK->dawgCtx,ZI_WORK->unk_0x1760,ZI_WORK);
|
||||
return;
|
||||
}
|
||||
733
libs/RVLMiddleware/eZiText/src/clib/zi8getc2.c
Normal file
733
libs/RVLMiddleware/eZiText/src/clib/zi8getc2.c
Normal file
@@ -0,0 +1,733 @@
|
||||
#include <zi8clib/zitypes.h>
|
||||
#include <zi8clib/zierror.h>
|
||||
#include <zi8clib/zi8getc2.h>
|
||||
|
||||
typedef struct {
|
||||
ziU8 countOnly;
|
||||
ziU8 maxWordLength;
|
||||
ziU8 lookupMode;
|
||||
ziU8 suffixOnly;
|
||||
ziU8 controls[8];
|
||||
ziU32 maxCount;
|
||||
ziU16 capacity;
|
||||
ziU8 minWordLength;
|
||||
ziU8 flags;
|
||||
ziU16 candidateCapacity;
|
||||
ziU8 checkOnly;
|
||||
ziU8 reserved;
|
||||
} ZiCandidateOptions;
|
||||
|
||||
const ziU8 Zi8SOdefaultArray[16] = {1, 4, 3, 2, 1, 8, 7, 6, 5, 0};
|
||||
const ziFuzzyPYPairs Zi8PYdefaultFuzzyPairs = {0, 1, 1, 1, 1, 1, 1};
|
||||
const ziFuzzyZYPairs Zi8ZYdefaultFuzzyPairs = {0};
|
||||
|
||||
ziU8 Zi8GetFormatVersion(ziU8 language, ziPtr work);
|
||||
ziU32 Zi8GetTableAddress(ziU8 language, ziU8 table, ziPtr work);
|
||||
ziU16 Zi8GetTableCount(ziU8 language, ziU8 table, ziPtr work);
|
||||
ziU16 Zi8GetVersion(ziPtr work);
|
||||
ziU16 Zi8GetOEMID(ziPtr work);
|
||||
ziU16 Zi8GetBuildID(ziPtr work);
|
||||
void Zi8Memcpy(ziU8* destination, ziU8* source, ziS32 count);
|
||||
ziU32 Zi8GetCandidatesOrCount(ziGetParam* parameters, ZiCandidateOptions* options, ziPtr work);
|
||||
|
||||
ziBool Zi8ZHsetPYfuzzyPairs(ziFuzzyPYPairs pairs ZI_NEED_WORK) {
|
||||
if (pairs.ziDefault) {
|
||||
ZI_WORK->unk_0x1B28.word = *(const ziU32*)&Zi8PYdefaultFuzzyPairs;
|
||||
} else {
|
||||
ZI_WORK->unk_0x1B28.word = *(ziU32*)&pairs;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
ziBool Zi8ZHsetZYfuzzyPairs(ziFuzzyZYPairs pairs ZI_NEED_WORK) {
|
||||
if (pairs.ziDefault) {
|
||||
ZI_WORK->unk_0x1B2C.word = *(const ziU32*)&Zi8ZYdefaultFuzzyPairs;
|
||||
} else {
|
||||
ZI_WORK->unk_0x1B2C.word = *(ziU32*)&pairs;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
ziBool Zi8SetLatinSearchOrder(ziU8* searchArray, ziU8 searchSize ZI_NEED_WORK) {
|
||||
if (searchArray == 0 || *searchArray == 0) {
|
||||
ZI_WORK->unk_0x1410 = (ziU32)Zi8SOdefaultArray;
|
||||
ZI_WORK->unk_0x1418 = 9;
|
||||
} else {
|
||||
ZI_WORK->unk_0x1410 = (ziU32)searchArray;
|
||||
ZI_WORK->unk_0x1418 = searchSize;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
ziU16 Zi8GetGlobalDataSize(void) {
|
||||
return sizeof(struct __zi8_work_data_s);
|
||||
}
|
||||
|
||||
static ziU16 Zi8GetDataSignature(ziU8* destination, ziU16 capacity, ziU8 language, ziPtr work) {
|
||||
ziU8* signature;
|
||||
ziU16 length;
|
||||
if (language == 1) {
|
||||
if (Zi8GetFormatVersion(1, work) < 8) {
|
||||
Zi8LogError(0x26f, work);
|
||||
return 0;
|
||||
}
|
||||
length = 0x1e;
|
||||
} else {
|
||||
length = 3;
|
||||
}
|
||||
signature = (ziU8*)Zi8GetTableAddress(language, (ziU8)length, work);
|
||||
length = Zi8GetTableCount(language, (ziU8)length, work);
|
||||
if (length == 0 || length > capacity) {
|
||||
Zi8LogError(0x961, work);
|
||||
return 0;
|
||||
}
|
||||
Zi8Memcpy(destination, signature, length);
|
||||
destination[length] = 0;
|
||||
Zi8LogError(100, work);
|
||||
return length;
|
||||
}
|
||||
|
||||
static ziU16 Zi8GetEngineSignature(ziU8* destination, ziPtr work) {
|
||||
ziU16 index = 0;
|
||||
struct { ziU16 minor; } version;
|
||||
ziU16 number;
|
||||
destination[index++] = 'v';
|
||||
number = (Zi8GetVersion(work) & 0xff00) >> 8;
|
||||
version.minor = Zi8GetVersion(work) & 0xff;
|
||||
destination[index++] = (ziU8)(number / 10 + '0');
|
||||
destination[index++] = (ziU8)(number % 10 + '0');
|
||||
destination[index++] = (ziU8)(version.minor / 10 + '0');
|
||||
destination[index++] = (ziU8)(version.minor % 10 + '0');
|
||||
destination[index++] = 'o';
|
||||
number = Zi8GetOEMID(work);
|
||||
destination[index++] = (ziU8)(number / 100 + '0');
|
||||
destination[index++] = (ziU8)((number % 100) / 10 + '0');
|
||||
destination[index++] = (ziU8)((number % 100) % 10 + '0');
|
||||
destination[index++] = 'b';
|
||||
number = Zi8GetBuildID(work);
|
||||
destination[index++] = (ziU8)(number / 100 + '0');
|
||||
destination[index++] = (ziU8)((number % 100) / 10 + '0');
|
||||
destination[index++] = (ziU8)((number % 100) % 10 + '0');
|
||||
destination[index] = 0;
|
||||
return index;
|
||||
}
|
||||
|
||||
static ziBool Zi8AlphaSignature(ziGetParam* parameters, ziBool countOnly ZI_NEED_WORK) {
|
||||
ziU16 secondLength;
|
||||
ziU16 firstLength;
|
||||
ziU8* second;
|
||||
ziU8* first;
|
||||
ziU8 engine[32];
|
||||
ziU8 dictionary[32];
|
||||
ziU16 length;
|
||||
ziU16 candidateCount;
|
||||
ziWChar* output = parameters->candidates;
|
||||
second = 0;
|
||||
firstLength = 0;
|
||||
secondLength = 0;
|
||||
Zi8LogError(100, ZI_WORK);
|
||||
parameters->letters = 0;
|
||||
length = Zi8GetDataSignature(dictionary, 0x20, parameters->language, ZI_WORK);
|
||||
if (length == 0 || length < parameters->elementCount) {
|
||||
first = engine;
|
||||
} else {
|
||||
first = dictionary;
|
||||
second = engine;
|
||||
firstLength = length;
|
||||
}
|
||||
length = Zi8GetEngineSignature(engine, ZI_WORK);
|
||||
if (length < parameters->elementCount) {
|
||||
if (firstLength == 0) {
|
||||
Zi8ReplaceLastError(500, ZI_WORK);
|
||||
return 0;
|
||||
}
|
||||
second = 0;
|
||||
candidateCount = 1;
|
||||
} else if (firstLength == 0) {
|
||||
candidateCount = 1;
|
||||
firstLength = length;
|
||||
} else {
|
||||
candidateCount = 2;
|
||||
secondLength = length;
|
||||
}
|
||||
if (parameters->firstCandidate < candidateCount) {
|
||||
candidateCount -= parameters->firstCandidate;
|
||||
if (!countOnly) {
|
||||
if (parameters->maxCandidates < candidateCount) {
|
||||
candidateCount = parameters->maxCandidates;
|
||||
}
|
||||
parameters->letters = candidateCount;
|
||||
if (!(parameters->getOptions & 0x80)) {
|
||||
ZI_WORK->unk_0x538 = parameters->language;
|
||||
parameters->candidates[0] = 0xfff0;
|
||||
output = (ziWChar*)&ZI_WORK->unk_0x338;
|
||||
}
|
||||
if (parameters->firstCandidate != 0) {
|
||||
first = second;
|
||||
firstLength = secondLength;
|
||||
}
|
||||
if (ZI_WORK->unk_0x0A < firstLength) {
|
||||
firstLength = ZI_WORK->unk_0x0A;
|
||||
}
|
||||
if ((parameters->elementCount < ZI_WORK->unk_0x140C[0] ||
|
||||
(parameters->getOptions & 0x7e) == 2) &&
|
||||
parameters->elementCount < firstLength) {
|
||||
firstLength = parameters->elementCount;
|
||||
}
|
||||
while (firstLength-- != 0) {
|
||||
*output++ = *first++;
|
||||
}
|
||||
*output++ = 0;
|
||||
if (parameters->letters == 2) {
|
||||
if (ZI_WORK->unk_0x0A < secondLength) {
|
||||
secondLength = ZI_WORK->unk_0x0A;
|
||||
}
|
||||
if ((parameters->elementCount < ZI_WORK->unk_0x140C[0] ||
|
||||
(parameters->getOptions & 0x7e) == 2) &&
|
||||
parameters->elementCount < secondLength) {
|
||||
secondLength = parameters->elementCount;
|
||||
}
|
||||
while (secondLength-- != 0) {
|
||||
*output++ = *second++;
|
||||
}
|
||||
*output++ = 0;
|
||||
}
|
||||
*output = 0;
|
||||
ZI_WORK->unk_0x0A = 0xff;
|
||||
return 1;
|
||||
}
|
||||
parameters->letters = candidateCount;
|
||||
ZI_WORK->unk_0x0A = 0xff;
|
||||
return 1;
|
||||
}
|
||||
Zi8ReplaceLastError(501, ZI_WORK);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ziBool Zi8ZhSignature(ziGetParam* parameters, ziBool countOnly ZI_NEED_WORK) {
|
||||
ziWChar* output = parameters->candidates;
|
||||
ziU8* current = 0;
|
||||
ziU16 copied;
|
||||
ziU8 engine[32];
|
||||
ziU8 dictionary[32];
|
||||
ziU16 dataLength;
|
||||
ziU32 engineLength;
|
||||
ziU32 candidateCount;
|
||||
ziU8 available;
|
||||
Zi8LogError(100, ZI_WORK);
|
||||
parameters->letters = 0;
|
||||
dataLength = Zi8GetDataSignature(dictionary, 0x20, parameters->language, ZI_WORK);
|
||||
engineLength = Zi8GetEngineSignature(engine, ZI_WORK);
|
||||
if (!(parameters->context & 0x10)) {
|
||||
candidateCount = dataLength + engineLength;
|
||||
} else {
|
||||
candidateCount = dataLength != 0;
|
||||
if (engineLength != 0) candidateCount++;
|
||||
}
|
||||
if (parameters->firstCandidate < candidateCount) {
|
||||
available = candidateCount - parameters->firstCandidate;
|
||||
if (!countOnly) {
|
||||
if (parameters->maxCandidates < (ziU16)(candidateCount - parameters->firstCandidate)) {
|
||||
available = parameters->maxCandidates;
|
||||
}
|
||||
parameters->letters = available;
|
||||
if (!(parameters->context & 0x10)) {
|
||||
copied = 0;
|
||||
if (dataLength != 0) {
|
||||
if (parameters->firstCandidate < dataLength) {
|
||||
candidateCount = dataLength - parameters->firstCandidate;
|
||||
current = dictionary + parameters->firstCandidate;
|
||||
} else {
|
||||
candidateCount = 0;
|
||||
}
|
||||
if (parameters->letters < candidateCount) candidateCount = parameters->letters;
|
||||
copied = candidateCount;
|
||||
while (candidateCount-- != 0) *output++ = *current++;
|
||||
}
|
||||
current = engine;
|
||||
if (dataLength <= parameters->firstCandidate) {
|
||||
dataLength += engineLength - parameters->firstCandidate;
|
||||
current += engineLength - dataLength;
|
||||
engineLength = dataLength;
|
||||
}
|
||||
if ((int)(parameters->letters - copied) < (int)engineLength) {
|
||||
engineLength = parameters->letters - copied;
|
||||
}
|
||||
while (engineLength-- != 0) *output++ = *current++;
|
||||
} else {
|
||||
if (parameters->firstCandidate == 0 && dataLength != 0) {
|
||||
current = dictionary;
|
||||
} else {
|
||||
if (parameters->firstCandidate != 0 && dataLength == 0) {
|
||||
Zi8ReplaceLastError(500, ZI_WORK);
|
||||
return 0;
|
||||
}
|
||||
current = engine;
|
||||
dataLength = engineLength;
|
||||
}
|
||||
while (dataLength-- != 0) *output++ = *current++;
|
||||
*output = 0x20;
|
||||
if (parameters->letters == 2) {
|
||||
current = engine;
|
||||
while (++output, engineLength-- != 0) *output = *current++;
|
||||
*output = 0x20;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
parameters->letters = available;
|
||||
ZI_WORK->unk_0x0A = 0xff;
|
||||
return 1;
|
||||
}
|
||||
Zi8ReplaceLastError(502, ZI_WORK);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ziU8 _Zi8GetCandidates(ziGetParam* parameters ZI_NEED_WORK) {
|
||||
ZiCandidateOptions options = {0};
|
||||
options.capacity = ZI_WORK->unk_0x141A;
|
||||
return Zi8GetCandidatesOrCount(parameters, &options, ZI_WORK);
|
||||
}
|
||||
|
||||
ziU8 _Zi8CheckCandidates(ziGetParam* parameters ZI_NEED_WORK) {
|
||||
ZiCandidateOptions options = {0};
|
||||
options.capacity = ZI_WORK->unk_0x141A;
|
||||
options.flags = 1;
|
||||
return Zi8GetCandidatesOrCount(parameters, &options, ZI_WORK);
|
||||
}
|
||||
ziU8 Zi8LangSupported(ziU8 language, ziPtr work);
|
||||
ziBool Zi8IsCharacter(ziWChar character, ziPtr work);
|
||||
ziU8 Zi8GetCharInfo(ziWChar character, ziWChar* output, ziU8 capacity, ziU8 type, ziPtr work);
|
||||
ziU8 Zi8GetKOcandidates(ziGetParam* parameters, ziPtr options, ziPtr work);
|
||||
ziU8 Zi8GetKoreanCandidates(ziGetParam* parameters, ziPtr options, ziPtr work);
|
||||
ziU8 Zi8Punctuation(ziGetParam* parameters, ziPtr options, ziPtr work);
|
||||
ziU8 Zi8GetChineseCandidates(ziGetParam* parameters, ziPtr options, ziPtr work);
|
||||
ziU8 Zi8Get1KeyPressCandidates(ziGetParam* parameters, ziPtr options, ziPtr work);
|
||||
ziU8 Zi8Get1KeyPressSpelling(ziGetParam* parameters, ziPtr options, ziPtr work);
|
||||
ziU8 Zi8GetSyllablesCandidates(ziGetParam* parameters, ziPtr options, ziPtr work);
|
||||
ziU8 Zi8AlphaGetCandidates(ziGetParam* parameters, ziPtr options, ziPtr work);
|
||||
|
||||
ziU32 Zi8GetCandidatesOrCount(ziGetParam* parameters, ZiCandidateOptions* options ZI_NEED_WORK) {
|
||||
|
||||
ziU8 savedElementCount;
|
||||
ziU16 savedCharacter;
|
||||
ziWChar* savedElements;
|
||||
ziBool restoreCandidates;
|
||||
ziU8 elementCount;
|
||||
int error;
|
||||
unsigned int candidateCount;
|
||||
ziU8 savedOptions;
|
||||
ziWChar* savedCandidates;
|
||||
ziU16 characterInfo[16];
|
||||
ziU16 lastInfoCharacter;
|
||||
|
||||
error = 0;
|
||||
savedOptions = 0;
|
||||
savedCandidates = 0;
|
||||
restoreCandidates = 0;
|
||||
if (options->lookupMode == '\0') {
|
||||
if (((ZI_WORK->unk_0x00 == '\t') && (parameters->elementCount != 0)) &&
|
||||
(((parameters->elements[parameters->elementCount - 1] == 0xEFF8 &&
|
||||
((ziU8)Zi8AlphaSignature(parameters,options->countOnly,ZI_WORK) != 0)) ||
|
||||
((parameters->elements[parameters->elementCount - 1] == 0xEF04 &&
|
||||
((ziU8)Zi8ZhSignature(parameters,options->countOnly,ZI_WORK) != 0)))))) {
|
||||
candidateCount = (unsigned int)parameters->letters;
|
||||
if (options->countOnly != '\0') {
|
||||
parameters->letters = 0;
|
||||
}
|
||||
Zi8LogError(100,ZI_WORK);
|
||||
goto finishCandidates;
|
||||
}
|
||||
if ((parameters->elementCount == 1) && (parameters->firstCandidate == 0)) {
|
||||
elementCount = parameters->language;
|
||||
if (elementCount == 0x11) goto latinSequence;
|
||||
if (elementCount < 0x11) {
|
||||
if (elementCount == 1) {
|
||||
if ((ZI_WORK->unk_0x00 == '\0') || (ZI_WORK->unk_0x01 == options->countOnly)) {
|
||||
switch(ZI_WORK->unk_0x00) {
|
||||
case '\0':
|
||||
if (parameters->elements[0] == 0xEF04) {
|
||||
ZI_WORK->unk_0x01 = options->countOnly;
|
||||
ZI_WORK->unk_0x00 = '\x01';
|
||||
}
|
||||
break;
|
||||
case '\x01':
|
||||
case '\x03':
|
||||
case '\x05':
|
||||
case '\a':
|
||||
if (parameters->elements[0] == 0xEF01) {
|
||||
ZI_WORK->unk_0x00 = ZI_WORK->unk_0x00 + '\x01';
|
||||
}
|
||||
else {
|
||||
ZI_WORK->unk_0x00 = '\0';
|
||||
}
|
||||
break;
|
||||
case '\x02':
|
||||
case '\x04':
|
||||
case '\x06':
|
||||
if (parameters->elements[0] == 0xEF04) {
|
||||
ZI_WORK->unk_0x00 = ZI_WORK->unk_0x00 + '\x01';
|
||||
}
|
||||
else {
|
||||
ZI_WORK->unk_0x00 = '\0';
|
||||
}
|
||||
break;
|
||||
case '\b':
|
||||
case '\t':
|
||||
if ((parameters->elements[0] == 0xEF04) &&
|
||||
((ziU8)Zi8ZhSignature(parameters,options->countOnly,ZI_WORK) != 0)) {
|
||||
ZI_WORK->unk_0x00 = '\t';
|
||||
candidateCount = (unsigned int)parameters->letters;
|
||||
if (options->countOnly != '\0') {
|
||||
parameters->letters = 0;
|
||||
}
|
||||
Zi8LogError(100,ZI_WORK);
|
||||
goto finishCandidates;
|
||||
}
|
||||
default:
|
||||
ZI_WORK->unk_0x00 = '\0';
|
||||
}
|
||||
if ((ZI_WORK->unk_0x00 == '\0') && (parameters->elements[0] == 0xEF04)) {
|
||||
ZI_WORK->unk_0x00 = '\x01';
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((elementCount == 0) || (elementCount < 0x10)) goto latinSequence;
|
||||
}
|
||||
else if (elementCount < 0x77) {
|
||||
if (0x12 < elementCount) {
|
||||
latinSequence:
|
||||
if ((ZI_WORK->unk_0x00 == '\0') || (ZI_WORK->unk_0x01 == options->countOnly)) {
|
||||
switch(ZI_WORK->unk_0x00) {
|
||||
case '\0':
|
||||
if (parameters->elements[0] == 0xEFF2) {
|
||||
ZI_WORK->unk_0x01 = options->countOnly;
|
||||
ZI_WORK->unk_0x00 = '\x01';
|
||||
}
|
||||
break;
|
||||
case '\x01':
|
||||
if (parameters->elements[0] == 0xEFF3) {
|
||||
ZI_WORK->unk_0x00 = '\x02';
|
||||
}
|
||||
else {
|
||||
ZI_WORK->unk_0x00 = '\0';
|
||||
}
|
||||
break;
|
||||
case '\x02':
|
||||
if (parameters->elements[0] == 0xEFF5) {
|
||||
ZI_WORK->unk_0x00 = '\x03';
|
||||
}
|
||||
else {
|
||||
ZI_WORK->unk_0x00 = '\0';
|
||||
}
|
||||
break;
|
||||
case '\x03':
|
||||
if (parameters->elements[0] == 0xEFF7) {
|
||||
ZI_WORK->unk_0x00 = '\x04';
|
||||
}
|
||||
else {
|
||||
ZI_WORK->unk_0x00 = '\0';
|
||||
}
|
||||
break;
|
||||
case '\x04':
|
||||
if (parameters->elements[0] == 0xEFF8) {
|
||||
ZI_WORK->unk_0x00 = '\x05';
|
||||
}
|
||||
else {
|
||||
ZI_WORK->unk_0x00 = '\0';
|
||||
}
|
||||
break;
|
||||
case '\x05':
|
||||
if (parameters->elements[0] == 0xEFF9) {
|
||||
ZI_WORK->unk_0x00 = '\x06';
|
||||
}
|
||||
else {
|
||||
ZI_WORK->unk_0x00 = '\0';
|
||||
}
|
||||
break;
|
||||
case '\x06':
|
||||
if (parameters->elements[0] == 0xEFF2) {
|
||||
ZI_WORK->unk_0x00 = '\a';
|
||||
}
|
||||
else {
|
||||
ZI_WORK->unk_0x00 = '\0';
|
||||
}
|
||||
break;
|
||||
case '\a':
|
||||
if (parameters->elements[0] == 0xEFF5) {
|
||||
ZI_WORK->unk_0x00 = '\b';
|
||||
}
|
||||
else {
|
||||
ZI_WORK->unk_0x00 = '\0';
|
||||
}
|
||||
break;
|
||||
case '\b':
|
||||
case '\t':
|
||||
if ((parameters->elements[0] == 0xEFF8) &&
|
||||
((ziU8)Zi8AlphaSignature(parameters,options->countOnly,ZI_WORK) != 0)) {
|
||||
ZI_WORK->unk_0x00 = '\t';
|
||||
candidateCount = (unsigned int)parameters->letters;
|
||||
if (options->countOnly != '\0') {
|
||||
parameters->letters = 0;
|
||||
}
|
||||
Zi8LogError(100,ZI_WORK);
|
||||
goto finishCandidates;
|
||||
}
|
||||
default:
|
||||
ZI_WORK->unk_0x00 = '\0';
|
||||
}
|
||||
if ((ZI_WORK->unk_0x00 == '\0') && (parameters->elements[0] == 0xEFF2)) {
|
||||
ZI_WORK->unk_0x00 = '\x01';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (0x7d < elementCount) goto latinSequence;
|
||||
}
|
||||
else if (1 < parameters->elementCount) {
|
||||
ZI_WORK->unk_0x00 = '\0';
|
||||
}
|
||||
}
|
||||
ZI_WORK->unk_0x18 = parameters->subLanguage;
|
||||
elementCount = Zi8GetFormatVersion(1,ZI_WORK);
|
||||
ZI_WORK->unk_0x16 = elementCount & 2;
|
||||
options->maxCount = ZI_WORK->unk_0x10;
|
||||
options->maxWordLength = ZI_WORK->unk_0x0A;
|
||||
ZI_WORK->unk_0x0A = -1;
|
||||
if ((ziU8)Zi8LangSupported(parameters->language,ZI_WORK) == 0) {
|
||||
Zi8LogError(0x163,ZI_WORK);
|
||||
candidateCount = 0;
|
||||
}
|
||||
else {
|
||||
if (parameters->language == 0x10) {
|
||||
error = 0x2c1;
|
||||
candidateCount = 0;
|
||||
}
|
||||
else if (parameters->language == 0x12) {
|
||||
if ((parameters->elementCount == 0) || (0xeff0 < parameters->elements[0])) {
|
||||
candidateCount = Zi8GetKOcandidates(parameters,options,ZI_WORK);
|
||||
}
|
||||
else {
|
||||
candidateCount = Zi8GetKoreanCandidates(parameters,options,ZI_WORK);
|
||||
}
|
||||
}
|
||||
else if ((parameters->language == 1) && ((parameters->context & 8) != 0)) {
|
||||
candidateCount = Zi8Punctuation(parameters,options,ZI_WORK);
|
||||
error = 100;
|
||||
}
|
||||
else if ((parameters->language == 1) &&
|
||||
((((parameters->getOptions & 0xbf) == 4 && (parameters->elementCount != 0)) &&
|
||||
((ziU8)Zi8IsCharacter(parameters->elements[0],ZI_WORK) != 0)))) {
|
||||
elementCount = Zi8GetCharInfo(parameters->elements[0],characterInfo,0x10,1,ZI_WORK);
|
||||
if (elementCount == 0) {
|
||||
parameters->unk_0x20 = 0;
|
||||
parameters->count = 0;
|
||||
parameters->letters = 0;
|
||||
candidateCount = 0;
|
||||
error = 900;
|
||||
}
|
||||
else {
|
||||
lastInfoCharacter = characterInfo[elementCount - 1];
|
||||
if ((0xf330 < lastInfoCharacter) && (lastInfoCharacter < 0xf336)) {
|
||||
characterInfo[elementCount - 1] = 0xf360;
|
||||
}
|
||||
savedElements = parameters->elements;
|
||||
parameters->elements = characterInfo;
|
||||
savedElementCount = parameters->elementCount;
|
||||
parameters->elementCount = elementCount;
|
||||
elementCount = parameters->getMode;
|
||||
parameters->getMode = 1;
|
||||
candidateCount = Zi8GetChineseCandidates(parameters,options,ZI_WORK);
|
||||
parameters->elements = savedElements;
|
||||
parameters->elementCount = savedElementCount;
|
||||
parameters->getMode = elementCount;
|
||||
parameters->count = 1;
|
||||
}
|
||||
}
|
||||
else if ((parameters->language == 1) && (parameters->getMode == 0xf)) {
|
||||
error = 0x2d0;
|
||||
candidateCount = 0;
|
||||
}
|
||||
else if ((parameters->language == 1) && ((parameters->getMode == 3 || (parameters->getMode == 4)))) {
|
||||
if ((parameters->getOptions & 0x80) == 0) {
|
||||
if (parameters->elementCount == 0) {
|
||||
candidateCount = Zi8GetChineseCandidates(parameters,options,ZI_WORK);
|
||||
}
|
||||
else {
|
||||
candidateCount = Zi8Get1KeyPressCandidates(parameters,options,ZI_WORK);
|
||||
}
|
||||
}
|
||||
else {
|
||||
candidateCount = Zi8Get1KeyPressSpelling(parameters,options,ZI_WORK);
|
||||
}
|
||||
}
|
||||
else if ((parameters->language == 1) &&
|
||||
((((parameters->getMode == 7 || (parameters->getMode == 8)) || (parameters->getMode == 10)) || (parameters->getMode == 9)))) {
|
||||
if (ZI_WORK->unk_0x16 == '\0') {
|
||||
error = 0x708;
|
||||
candidateCount = 0;
|
||||
}
|
||||
else {
|
||||
candidateCount = Zi8GetChineseCandidates(parameters,options,ZI_WORK);
|
||||
}
|
||||
}
|
||||
else if ((parameters->language == 1) && ((parameters->getMode == 0xb || (parameters->getMode == 0xe)))) {
|
||||
error = 0x2ee;
|
||||
candidateCount = 0;
|
||||
}
|
||||
else if (parameters->language == 1) {
|
||||
candidateCount = Zi8GetChineseCandidates(parameters,options,ZI_WORK);
|
||||
if ((((candidateCount == 0) && ((parameters->getOptions & 0x20) == 0)) && ((parameters->getMode == 1 && (parameters->elementCount != 0))))
|
||||
&& (((parameters->elements[parameters->elementCount - 1] == 0xF37A ||
|
||||
(parameters->elements[parameters->elementCount - 1] == 0xF363)) ||
|
||||
(parameters->elements[parameters->elementCount - 1] == 0xF373)))) {
|
||||
savedCharacter = parameters->elements[parameters->elementCount];
|
||||
elementCount = parameters->elementCount;
|
||||
parameters->elements[elementCount] = 0xf368;
|
||||
parameters->elementCount = elementCount + 1;
|
||||
candidateCount = Zi8GetChineseCandidates(parameters,options,ZI_WORK);
|
||||
elementCount = parameters->elementCount;
|
||||
parameters->elementCount = elementCount - 1;
|
||||
parameters->elements[(ziU8)(elementCount - 1)] = savedCharacter;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ZI_WORK->unk_0x538 = parameters->language;
|
||||
restoreCandidates = (parameters->getOptions & 0x80) == 0;
|
||||
if (restoreCandidates) {
|
||||
savedOptions = parameters->getOptions;
|
||||
savedCandidates = parameters->candidates;
|
||||
parameters->getOptions = parameters->getOptions | 0x81;
|
||||
parameters->candidates = (ziWChar*)&ZI_WORK->unk_0x338;
|
||||
options->capacity = 0x100;
|
||||
}
|
||||
if (parameters->getMode == 2) {
|
||||
candidateCount = Zi8GetTableCount(parameters->language,0x1f,ZI_WORK);
|
||||
if ((candidateCount & 0x200) == 0) {
|
||||
error = 0x44c;
|
||||
candidateCount = 0;
|
||||
}
|
||||
else {
|
||||
candidateCount = Zi8GetSyllablesCandidates(parameters,options,ZI_WORK);
|
||||
}
|
||||
}
|
||||
else {
|
||||
candidateCount = Zi8AlphaGetCandidates(parameters,options,ZI_WORK);
|
||||
}
|
||||
}
|
||||
if (restoreCandidates) {
|
||||
parameters->getOptions = savedOptions;
|
||||
parameters->candidates = savedCandidates;
|
||||
for (elementCount = 0; elementCount < parameters->letters; elementCount = elementCount + 1) {
|
||||
parameters->candidates[elementCount] = elementCount - 0x10;
|
||||
}
|
||||
}
|
||||
if (error != 0) {
|
||||
Zi8LogError(error,ZI_WORK);
|
||||
}
|
||||
}
|
||||
finishCandidates:
|
||||
return candidateCount;
|
||||
}
|
||||
|
||||
void Zi8InitDupWordBuf(ziPtr __zi8_work_data) {
|
||||
ZI_WORK->unk_0x539 = 0;
|
||||
}
|
||||
|
||||
ziBool Zi8IsDupWChar(ziWChar character ZI_NEED_WORK) {
|
||||
ziBool duplicate;
|
||||
ziU16* buffer;
|
||||
unsigned int index;
|
||||
duplicate = 0;
|
||||
buffer = ZI_WORK->unk_0x57A;
|
||||
if (ZI_WORK->unk_0x539 == 0) {
|
||||
buffer[0] = 2;
|
||||
buffer[1] = character;
|
||||
ZI_WORK->unk_0x539 = 1;
|
||||
Zi8LogError(0x8fd, ZI_WORK);
|
||||
return 0;
|
||||
}
|
||||
for (index = ZI_WORK->unk_0x539; index != 0; index--) {
|
||||
if (character == buffer[index]) {
|
||||
duplicate = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ZI_WORK->unk_0x539++;
|
||||
buffer[(*buffer)++] = character;
|
||||
if (*buffer > 100) {
|
||||
*buffer = 2;
|
||||
buffer[1] = character;
|
||||
ZI_WORK->unk_0x539 = 1;
|
||||
}
|
||||
Zi8LogError(100, ZI_WORK);
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
ziBool Zi8IsDupWordW(ziWChar* word, ziU8 length ZI_NEED_WORK) {
|
||||
ziU8 slot;
|
||||
ziBool duplicate = 0;
|
||||
unsigned int position;
|
||||
int index;
|
||||
int character;
|
||||
if (word == 0 || length == 0) {
|
||||
Zi8LogError(300, ZI_WORK);
|
||||
return 0;
|
||||
}
|
||||
if (length > 20) {
|
||||
word += length - 20;
|
||||
length = 20;
|
||||
}
|
||||
for (index = 0; index < ZI_WORK->unk_0x539; index++) {
|
||||
slot = ZI_WORK->unk_0x53A[index];
|
||||
for (character = 0; character < length; character++) {
|
||||
if (word[character] != ZI_WORK->unk_0x57A[slot * 21 + character]) break;
|
||||
}
|
||||
if (character >= length && ZI_WORK->unk_0x57A[slot * 21 + character] == 0) {
|
||||
duplicate = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!duplicate) {
|
||||
if (ZI_WORK->unk_0x539 < 64) {
|
||||
position = ZI_WORK->unk_0x539;
|
||||
ZI_WORK->unk_0x53A[ZI_WORK->unk_0x539] = ZI_WORK->unk_0x539;
|
||||
ZI_WORK->unk_0x539++;
|
||||
} else {
|
||||
slot = ZI_WORK->unk_0x53A[0];
|
||||
position = slot;
|
||||
for (index = 1; index < ZI_WORK->unk_0x539; index++) {
|
||||
ZI_WORK->unk_0x53A[index - 1] = ZI_WORK->unk_0x53A[index];
|
||||
}
|
||||
ZI_WORK->unk_0x53A[index - 1] = slot;
|
||||
}
|
||||
} else {
|
||||
slot = ZI_WORK->unk_0x53A[index];
|
||||
position = slot;
|
||||
for (; index < ZI_WORK->unk_0x539 - 1; index++) {
|
||||
ZI_WORK->unk_0x53A[index] = ZI_WORK->unk_0x53A[index + 1];
|
||||
}
|
||||
ZI_WORK->unk_0x53A[index] = slot;
|
||||
}
|
||||
for (index = 0; index < length; index++) {
|
||||
ZI_WORK->unk_0x57A[position * 21 + index] = word[index];
|
||||
}
|
||||
ZI_WORK->unk_0x57A[position * 21 + index] = 0;
|
||||
Zi8LogError(100, ZI_WORK);
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
void Zi8Memset(ziU8* destination, ziU32 value, ziS32 count) {
|
||||
ziS32 index;
|
||||
for (index = 0; index < count; index++) destination[index] = (ziU8)value;
|
||||
}
|
||||
|
||||
void Zi8Memcpy(ziU8* destination, ziU8* source, ziS32 count) {
|
||||
ziS32 index;
|
||||
for (index = 0; index < count; index++) destination[index] = source[index];
|
||||
}
|
||||
|
||||
ziBool Zi8SetMaxWordLength(ziU8 length ZI_NEED_WORK) {
|
||||
ZI_WORK->unk_0x0A = length;
|
||||
return 1;
|
||||
}
|
||||
876
libs/RVLMiddleware/eZiText/src/clib/zi8match.c
Normal file
876
libs/RVLMiddleware/eZiText/src/clib/zi8match.c
Normal file
@@ -0,0 +1,876 @@
|
||||
#include <zi8clib/zierror.h>
|
||||
#include <zi8clib/zitypes.h>
|
||||
|
||||
extern ziU32 Zi8GetTableAddress(ziU8 lang, ziU8 tableIdx ZI_NEED_WORK);
|
||||
|
||||
const ziU8 Zi8PinyinInitials[0x1C] = {
|
||||
0x00, 0x3C, 0x98, 0x02, 0x00, 0x38, 0x34, 0x3B, 0x00, 0x06, 0x37, 0x2B,
|
||||
0x0C, 0x26, 0x00, 0x3F, 0x09, 0x2C, 0x9A, 0x05, 0x00, 0x00, 0x11, 0x0A,
|
||||
0x0D, 0x9C, 0x00, 0x00
|
||||
};
|
||||
const ziU8 Zi8BpmfInitials[0x24] = {
|
||||
0x3C, 0x3F, 0x0C, 0x38, 0x02, 0x05, 0x26, 0x2B, 0x34, 0x37, 0x3B, 0x06,
|
||||
0x09, 0x0A, 0x1D, 0x19, 0x1B, 0x2C, 0x1C, 0x18, 0x1A, 0x01, 0x02, 0x03,
|
||||
0x05, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0E, 0x0D, 0x0F, 0x04, 0x00, 0x00
|
||||
};
|
||||
const ziU8 Zi8PinyinFinals[0x36][8] = {
|
||||
{0x0F, 0xFF, 0x00, 0x00, 0x3C, 0x28, 0x00, 0x00},
|
||||
{0x0F, 0x00, 0x00, 0x00, 0x3F, 0x2B, 0x00, 0x00},
|
||||
{0x0F, 0x0E, 0xFF, 0x00, 0x3F, 0x28, 0x00, 0x00},
|
||||
{0x0F, 0x0E, 0x07, 0x00, 0x3F, 0x28, 0x00, 0x00},
|
||||
{0x0F, 0x15, 0x00, 0x00, 0x3F, 0x2A, 0x00, 0x00},
|
||||
{0x09, 0xFF, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00},
|
||||
{0x09, 0x00, 0x00, 0x00, 0x3F, 0x08, 0x00, 0x00},
|
||||
{0x09, 0x01, 0xFF, 0x00, 0x38, 0x00, 0x00, 0x00},
|
||||
{0x09, 0x01, 0x00, 0x00, 0x3F, 0x04, 0x00, 0x00},
|
||||
{0x09, 0x01, 0x0F, 0x00, 0x3F, 0x01, 0x00, 0x00},
|
||||
{0x09, 0x01, 0x0E, 0xFF, 0x3E, 0x02, 0x00, 0x00},
|
||||
{0x09, 0x01, 0x0E, 0x00, 0x3F, 0x02, 0x00, 0x00},
|
||||
{0x09, 0x01, 0x0E, 0x07, 0x3F, 0x03, 0x00, 0x00},
|
||||
{0x09, 0x05, 0x00, 0x00, 0x3F, 0x09, 0x00, 0x00},
|
||||
{0x09, 0x15, 0x00, 0x00, 0x3F, 0x0B, 0x00, 0x00},
|
||||
{0x09, 0x0E, 0xFF, 0x00, 0x3E, 0x0C, 0x00, 0x00},
|
||||
{0x09, 0x0E, 0x00, 0x00, 0x3F, 0x0C, 0x00, 0x00},
|
||||
{0x09, 0x0E, 0x07, 0x00, 0x3F, 0x0D, 0x00, 0x00},
|
||||
{0x09, 0x0F, 0xFF, 0x00, 0x3E, 0x0E, 0x00, 0x00},
|
||||
{0x09, 0x0F, 0x15, 0x00, 0x3F, 0x0E, 0x00, 0x00},
|
||||
{0x09, 0x0F, 0x0E, 0xFF, 0x3F, 0x0F, 0x00, 0x00},
|
||||
{0x09, 0x0F, 0x0E, 0x07, 0x3F, 0x0F, 0x00, 0x00},
|
||||
{0x15, 0xFF, 0x00, 0x00, 0x30, 0x10, 0x00, 0x00},
|
||||
{0x15, 0x00, 0x00, 0x00, 0x3F, 0x18, 0x00, 0x00},
|
||||
{0x15, 0x01, 0xFF, 0x00, 0x38, 0x10, 0x00, 0x00},
|
||||
{0x15, 0x01, 0x00, 0x00, 0x3F, 0x17, 0x00, 0x00},
|
||||
{0x15, 0x01, 0x0E, 0xFF, 0x3E, 0x10, 0x00, 0x00},
|
||||
{0x15, 0x01, 0x0E, 0x00, 0x3F, 0x10, 0x00, 0x00},
|
||||
{0x15, 0x01, 0x0E, 0x07, 0x3F, 0x11, 0x00, 0x00},
|
||||
{0x15, 0x01, 0x09, 0x00, 0x3F, 0x13, 0x00, 0x00},
|
||||
{0x15, 0x0E, 0x00, 0x00, 0x3F, 0x1C, 0x00, 0x00},
|
||||
{0x15, 0x09, 0x00, 0x00, 0x3F, 0x1D, 0x00, 0x00},
|
||||
{0x15, 0x0F, 0x00, 0x00, 0x3F, 0x1E, 0x00, 0x00},
|
||||
{0x15, 0x05, 0x00, 0x00, 0x3F, 0x1F, 0x00, 0x00},
|
||||
{0x01, 0xFF, 0x00, 0x00, 0x38, 0x20, 0x00, 0x00},
|
||||
{0x01, 0x00, 0x00, 0x00, 0x3F, 0x23, 0x00, 0x00},
|
||||
{0x01, 0x0E, 0xFF, 0x00, 0x3E, 0x20, 0x00, 0x00},
|
||||
{0x01, 0x0E, 0x00, 0x00, 0x3F, 0x20, 0x00, 0x00},
|
||||
{0x01, 0x0E, 0x07, 0x00, 0x3F, 0x21, 0x00, 0x00},
|
||||
{0x01, 0x09, 0x00, 0x00, 0x3F, 0x25, 0x00, 0x00},
|
||||
{0x01, 0x0F, 0x00, 0x00, 0x3F, 0x26, 0x00, 0x00},
|
||||
{0x05, 0xFF, 0x00, 0x00, 0x38, 0x30, 0x00, 0x00},
|
||||
{0x05, 0x00, 0x00, 0x00, 0x3F, 0x34, 0x00, 0x00},
|
||||
{0x05, 0x0E, 0xFF, 0x00, 0x3E, 0x30, 0x00, 0x00},
|
||||
{0x05, 0x0E, 0x00, 0x00, 0x3F, 0x30, 0x00, 0x00},
|
||||
{0x05, 0x0E, 0x07, 0x00, 0x3F, 0x31, 0x00, 0x00},
|
||||
{0x05, 0x09, 0x00, 0x00, 0x3F, 0x35, 0x00, 0x00},
|
||||
{0x05, 0x12, 0x00, 0x00, 0x3F, 0x33, 0x00, 0x00},
|
||||
{0x16, 0xFF, 0x00, 0x00, 0x3C, 0x38, 0x00, 0x00},
|
||||
{0x16, 0x00, 0x00, 0x00, 0x3F, 0x38, 0x00, 0x00},
|
||||
{0x16, 0x01, 0xFF, 0x00, 0x3F, 0x39, 0x00, 0x00},
|
||||
{0x16, 0x01, 0x0E, 0x00, 0x3F, 0x39, 0x00, 0x00},
|
||||
{0x16, 0x05, 0x00, 0x00, 0x3F, 0x1F, 0x00, 0x00},
|
||||
{0x16, 0x0E, 0x00, 0x00, 0x3F, 0x3B, 0x00, 0x00}
|
||||
};
|
||||
const ziU8 nodeHeaderTable[0x20] = {
|
||||
0x00, 0x10, 0x00, 0x01, 0x00, 0x03, 0x00, 0x14, 0x00, 0x05, 0x00, 0x07,
|
||||
0x00, 0x1C, 0x00, 0x0D, 0x00, 0x0F, 0x00, 0x11, 0x00, 0x13, 0x00, 0x15,
|
||||
0x00, 0x17, 0x00, 0x1D, 0x00, 0x1F, 0x00, 0x35
|
||||
};
|
||||
|
||||
ziBool Zi8PriMatchNextChar(ziU8* node, ziU8 mask0, ziU8 value0, ziU8 mask1, ziU8 value1, ziU8 mask2, ziU8 value2, ziU8 mask3, ziU8 value3, ziU16* count, ziU8** result, ziU16* code ZI_NEED_WORK) {
|
||||
ziU16 remaining = *count;
|
||||
while (remaining-- != 0) {
|
||||
if ((value0 == (node[0] & mask0)) && (value3 == (node[3] & mask3)) && (value2 == (node[2] & mask2)) && (value1 == (node[1] & mask1))) {
|
||||
*result = node;
|
||||
*code = ((ziU16)node[6] << 8) + (ziU16)node[7];
|
||||
*count = remaining;
|
||||
Zi8LogError(0x64, ZI_WORK);
|
||||
return 1;
|
||||
}
|
||||
node += 0xC;
|
||||
}
|
||||
Zi8LogError(0x12E, ZI_WORK);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ziBool Zi8ExactMatchNextChar(ziU8* node, ziU8 mask0, ziU8 value0, ziU8 mask1, ziU8 value1, ziU8 mask2, ziU8 value2, ziU8 mask3, ziU8 value3, ziU16* count, ziU8** result, ziU16* code ZI_NEED_WORK) {
|
||||
ziU16 remaining = *count;
|
||||
ziU8* current = node;
|
||||
while (remaining-- != 0) {
|
||||
if ((value0 == (current[0] & mask0)) && (value3 == (current[3] & mask3)) && (value2 == (current[2] & mask2)) && (value1 == (current[1] & mask1))) {
|
||||
*result = current;
|
||||
*code = ((ziU16)current[6] << 8) + (ziU16)current[7];
|
||||
*count = remaining;
|
||||
Zi8LogError(0x64, ZI_WORK);
|
||||
return 1;
|
||||
}
|
||||
current += 0xC;
|
||||
}
|
||||
Zi8LogError(0x12E, ZI_WORK);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ziU32 Zi8SecMatchChar(ziPtr nodeAddress, ziU8* dictionaryAddress, ziMatchParam* match, ziU16* code ZI_NEED_WORK) {
|
||||
ziBool isPartial = 0;
|
||||
ziU16 matchCode;
|
||||
ziU8* data;
|
||||
ziU8 value;
|
||||
struct {
|
||||
ziU8 remaining;
|
||||
ziU8 dataIndex;
|
||||
ziU16 targetCode;
|
||||
} state;
|
||||
|
||||
if (match->field22 != 0) {
|
||||
state.targetCode = match->field22;
|
||||
matchCode = ((ziU16)(((ziU8*)nodeAddress)[4] & 3) << 8) | ((ziU8*)nodeAddress)[5];
|
||||
value = 0;
|
||||
while (value++ < 6) {
|
||||
if (state.targetCode == matchCode) {
|
||||
break;
|
||||
}
|
||||
matchCode = ((ziU16)(*(dictionaryAddress + matchCode * 8 + 6) & 3) << 8) | *(dictionaryAddress + matchCode * 8 + 7);
|
||||
if (matchCode == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (state.targetCode != matchCode) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
data = (ziU8*)Zi8GetTableAddress(1, 1, ZI_WORK);
|
||||
data += ((ziU8*)nodeAddress)[0xB] + (((ziU8*)nodeAddress)[0xA] << 8) + ((((ziU8*)nodeAddress)[9] & 0xF) << 16);
|
||||
if (ZI_WORK->unk_0x16 != 0) {
|
||||
switch (data[0] & 7) {
|
||||
case 2:
|
||||
data += 2;
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
data += 3;
|
||||
break;
|
||||
case 5:
|
||||
data += 4;
|
||||
break;
|
||||
default:
|
||||
data++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
value = data[0];
|
||||
value = (value >> 4) & 7;
|
||||
if (value * 2 + 10 < match->length) {
|
||||
return 0;
|
||||
}
|
||||
if (match->length < 9) {
|
||||
if (match->length == 8) {
|
||||
if ((data[0] & 0xF) == 0xF) {
|
||||
isPartial = 1;
|
||||
}
|
||||
} else if ((match->length & 1) != 0) {
|
||||
if ((((ziU8*)nodeAddress)[match->length >> 1] & 0xF) == 0xF) {
|
||||
isPartial = 1;
|
||||
}
|
||||
} else {
|
||||
if ((((ziU8*)nodeAddress)[match->length >> 1] & 0xF0) == 0xF0) {
|
||||
isPartial = 1;
|
||||
}
|
||||
}
|
||||
if (match->length > 2) {
|
||||
if ((match->length & 1) != 0) {
|
||||
if (((((ziU8*)nodeAddress)[(match->length - 1) >> 1] & 0xF0) == 0) || ((((ziU8*)nodeAddress)[(match->length - 1) >> 1] & 0xF0) == 0xF0)) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
if (((((ziU8*)nodeAddress)[(match->length - 1) >> 1] & 0xF) == 0) || ((((ziU8*)nodeAddress)[(match->length - 1) >> 1] & 0xF) == 0xF)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (code != 0) {
|
||||
*code = ((ziU16)((ziU8*)nodeAddress)[6] << 8) + (ziU16)((ziU8*)nodeAddress)[7];
|
||||
}
|
||||
if (isPartial) {
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((match->length & 1) != 0) {
|
||||
if (((data[((match->length - 1) >> 1) - 4] & 0xF0) == 0) || ((data[((match->length - 1) >> 1) - 4] & 0xF0) == 0xF0)) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
if (((data[((match->length - 1) >> 1) - 4] & 0xF) == 0) || ((data[((match->length - 1) >> 1) - 4] & 0xF) == 0xF)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
state.dataIndex = 4;
|
||||
state.remaining = ((match->length + 1) >> 1) - 4;
|
||||
if (((ziU8)value + 1) < (int)state.remaining) {
|
||||
return 0;
|
||||
}
|
||||
if ((match->length & 1) != 0) {
|
||||
if ((data[(match->length >> 1) - 4] & 0xF) == 0xF) {
|
||||
isPartial = 1;
|
||||
}
|
||||
} else {
|
||||
if ((data[(match->length >> 1) - 4] & 0xF0) == 0xF0) {
|
||||
isPartial = 1;
|
||||
}
|
||||
}
|
||||
if (match->count == 0) {
|
||||
while (state.remaining != 0) {
|
||||
if ((data[0] & match->arr1[state.dataIndex]) != match->arrD[state.dataIndex]) {
|
||||
return 0;
|
||||
}
|
||||
state.dataIndex++;
|
||||
state.remaining--;
|
||||
data++;
|
||||
}
|
||||
}
|
||||
if (code != 0) {
|
||||
*code = ((ziU16)((ziU8*)nodeAddress)[6] << 8) + (ziU16)((ziU8*)nodeAddress)[7];
|
||||
}
|
||||
if (isPartial) {
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
ziBool Zi8PriMatchNextComp(ziU8* node, ziU8 mask0, ziU8 value0, ziU8 mask1, ziU8 value1, ziU8 mask2, ziU8 value2, ziU8 mask3, ziU8 value3, ziU16* count, ziU8** result ZI_NEED_WORK) {
|
||||
ziU16 remaining = *count;
|
||||
while (remaining-- != 0) {
|
||||
if ((value0 == (node[0] & mask0)) && (value1 == (node[1] & mask1)) && (value2 == (node[2] & mask2)) && (value3 == (node[3] & mask3))) {
|
||||
*result = node;
|
||||
*count = remaining;
|
||||
Zi8LogError(0x64, ZI_WORK);
|
||||
return 1;
|
||||
}
|
||||
node += 8;
|
||||
}
|
||||
Zi8LogError(0x12E, ZI_WORK);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ziBool Zi8SecMatchComp(ziPtr nodeAddress, ziMatchParam* matchAddress, ziPtr dictionaryAddress) {
|
||||
int chainIndex;
|
||||
ziU16 matchCode;
|
||||
ziU16 targetCode;
|
||||
|
||||
if (matchAddress->field22 != 0) {
|
||||
targetCode = matchAddress->field22;
|
||||
matchCode = ((ziU16)(((ziU8*)nodeAddress)[6] & 3) << 8) | ((ziU8*)nodeAddress)[7];
|
||||
chainIndex = 0;
|
||||
while (chainIndex++ < 6) {
|
||||
if (targetCode == matchCode) {
|
||||
break;
|
||||
}
|
||||
matchCode = ((ziU16)(*((ziU8*)dictionaryAddress + matchCode * 8 + 6) & 3) << 8) | *((ziU8*)dictionaryAddress + matchCode * 8 + 7);
|
||||
if (matchCode == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (targetCode != matchCode) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (matchAddress->length > 8) {
|
||||
if ((int)((ziU8*)nodeAddress)[5] < (int)(matchAddress->length - 2)) {
|
||||
return 0;
|
||||
}
|
||||
} else if ((int)((ziU8*)nodeAddress)[5] < (int)(matchAddress->length - 1)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
extern ziU16 Zi8MatchAltSound(ziPtr soundTable, ziU16 soundCode, ziPtr pCodeTable, ziU16 index, ziU16 mask, ziU16 value, ziU8 flag ZI_NEED_WORK);
|
||||
ziU16 Zi8GetPCode(ziU8* table, ziU8* node);
|
||||
|
||||
ziBool Zi8MatchPhonetic(ziPtr pCodeTable, ziPtr dictionary, ziPtr soundTable, ziU16 soundCode, ziU32 tableAddress, ziU8* node, ziU16* masks, ziU16* values, ziU16* count, ziU8** resultNode, ziU8** stringOffset, ziS8 partialMode, ziU8 strictMode, ziU8 numParts, ziU16 partMask, ziU16 partValue, ziU8 flag, ziU8 altMode, ziU16 initialCode, ziU16* resultCode, ziU8 lastMode ZI_NEED_WORK) {
|
||||
ziBool hasString;
|
||||
ziU32 matchedParts;
|
||||
ziU32 altModeActive;
|
||||
ziU8 partCode;
|
||||
ziU8 partCount;
|
||||
ziU8 partIndex;
|
||||
ziU16 soundIndex;
|
||||
ziU16 remaining;
|
||||
ziU16 code;
|
||||
ziU16 dictionaryIndex;
|
||||
ziU8 nextCode;
|
||||
ziU8* sound;
|
||||
ziU8* nextPart;
|
||||
|
||||
if (*stringOffset != 0) {
|
||||
hasString = 1;
|
||||
} else {
|
||||
hasString = 0;
|
||||
}
|
||||
if (*count == 0) {
|
||||
remaining = 1;
|
||||
} else {
|
||||
remaining = *count;
|
||||
}
|
||||
matchedParts = 0;
|
||||
altModeActive = altMode;
|
||||
if ((lastMode != 0) && (numParts > 1)) {
|
||||
altModeActive = 1;
|
||||
}
|
||||
while (remaining-- != 0) {
|
||||
if ((node[0] & flag) != 0) {
|
||||
code = Zi8GetPCode((ziU8*)pCodeTable, node);
|
||||
if ((*values != (code & *masks)) && (altModeActive == 0) && ((node[0] & 0x80) != 0)) {
|
||||
if (*count != 0) {
|
||||
soundIndex = (initialCode - remaining) - 1;
|
||||
} else {
|
||||
soundIndex = initialCode;
|
||||
}
|
||||
code = Zi8MatchAltSound(soundTable, soundCode, pCodeTable, soundIndex, *masks, *values, flag, ZI_WORK);
|
||||
}
|
||||
if ((*values == (code & *masks)) && (partValue != (code & partMask))) {
|
||||
matchedParts = 1;
|
||||
sound = (ziU8*)((tableAddress + ((node[9] & 0xF) * 0x10000)) + node[0xB] + node[0xA] * 0x100);
|
||||
if (ZI_WORK->unk_0x16 != 0) {
|
||||
switch (sound[0] & 7) {
|
||||
case 2:
|
||||
sound += 2;
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
sound += 3;
|
||||
break;
|
||||
case 5:
|
||||
sound += 4;
|
||||
break;
|
||||
default:
|
||||
sound++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((sound[0] & 0x80) != 0) {
|
||||
sound += ((sound[0] & 0x7F) >> 4) + 1;
|
||||
} else if (numParts > 1) {
|
||||
goto next_node;
|
||||
}
|
||||
if (((ziU8)matchedParts == numParts) || (numParts == 0)) {
|
||||
*resultNode = node;
|
||||
*resultCode = ((ziU16)node[6] << 8) + node[7];
|
||||
*count = remaining;
|
||||
return 1;
|
||||
}
|
||||
do {
|
||||
nextCode = *sound++;
|
||||
partCount = nextCode & 0xF;
|
||||
if ((nextCode & flag) == 0) {
|
||||
for (; partCount != 0; partCount--) {
|
||||
for (sound++; (*sound & 0x80) == 0; sound += 2) {
|
||||
}
|
||||
sound++;
|
||||
}
|
||||
}
|
||||
for (; partCount != 0; partCount--) {
|
||||
partIndex = 1;
|
||||
if (hasString && (*stringOffset < sound)) {
|
||||
hasString = 0;
|
||||
}
|
||||
nextPart = sound;
|
||||
if (!hasString) {
|
||||
*stringOffset = sound;
|
||||
}
|
||||
do {
|
||||
partCode = nextPart[1];
|
||||
dictionaryIndex = ((ziU16)partCode << 8) | nextPart[0];
|
||||
sound = nextPart + 2;
|
||||
if (hasString) {
|
||||
goto phonetic_skip;
|
||||
}
|
||||
code = Zi8GetPCode((ziU8*)pCodeTable, (ziU8*)dictionary + (dictionaryIndex & 0x7FFF) * 0xC);
|
||||
if (((code & masks[partIndex]) != values[partIndex]) && (altModeActive == 0) && (((ziU8*)dictionary)[(dictionaryIndex & 0x7FFF) * 0xC] & 0x80) != 0) {
|
||||
code = Zi8MatchAltSound(soundTable, soundCode, pCodeTable, dictionaryIndex & 0x7FFF, masks[partIndex], values[partIndex], flag, ZI_WORK);
|
||||
}
|
||||
if ((code & masks[partIndex]) != values[partIndex]) {
|
||||
goto phonetic_skip;
|
||||
}
|
||||
partIndex++;
|
||||
if (partIndex == numParts) {
|
||||
if ((partialMode != 0) && ((strictMode == 0 && (partCode & 0x80) != 0) || (strictMode != 0 && (partCode & 0x80) == 0))) {
|
||||
goto phonetic_skip;
|
||||
}
|
||||
*resultNode = node;
|
||||
code = ((ziU16)node[6] << 8) + node[7];
|
||||
*resultCode = code;
|
||||
*count = remaining;
|
||||
return 1;
|
||||
}
|
||||
nextPart = sound;
|
||||
} while ((partCode & 0x80) == 0);
|
||||
continue;
|
||||
phonetic_skip:
|
||||
if ((partCode & 0x80) == 0) {
|
||||
nextPart += 3;
|
||||
while ((*nextPart & 0x80) == 0) {
|
||||
nextPart += 2;
|
||||
}
|
||||
sound = nextPart + 1;
|
||||
}
|
||||
}
|
||||
} while ((nextCode & 0x80) == 0);
|
||||
}
|
||||
}
|
||||
next_node:
|
||||
node += 0xC;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
ziBool Zi8GetPyFinal(ziU8* pinyin, ziU8* initial, ziU8* final);
|
||||
|
||||
ziU8 Zi8GetPyPhonetic(ziWChar* text, ziU8 count, ziU16* initial, ziU16* final, ziU8* resultCount, ziU16* bestInitial, ziU16* bestFinal ZI_NEED_WORK) {
|
||||
ziU8 firstInitial;
|
||||
ziU8 pyFinal;
|
||||
ziU8 pyInitial;
|
||||
ziU8 convertedCount;
|
||||
ziBool partial;
|
||||
ziU8 result;
|
||||
ziU8 outputIndex;
|
||||
ziU8 partCount;
|
||||
ziU16 value;
|
||||
ziU8 index;
|
||||
ziWChar converted[256];
|
||||
ziWChar* current;
|
||||
ziU8 pinyin[12];
|
||||
|
||||
current = converted;
|
||||
result = 0;
|
||||
*resultCount = 0;
|
||||
if (count == 0) {
|
||||
Zi8LogError(0x135, ZI_WORK);
|
||||
return 0;
|
||||
}
|
||||
convertedCount = 0;
|
||||
for (index = 0; index < count; index++) {
|
||||
if (((text[index] >= 0xF341) && (text[index] <= 0xF35A)) || ((text[index] >= 0x41) && (text[index] <= 0x5A))) {
|
||||
if ((convertedCount != 0) && (current[convertedCount - 1] != 0xF360) && (current[convertedCount - 1] != 0x27)) {
|
||||
current[convertedCount] = 0x27;
|
||||
convertedCount++;
|
||||
}
|
||||
current[convertedCount] = (text[index] & 0xFF) + 0x20;
|
||||
} else {
|
||||
current[convertedCount] = text[index];
|
||||
}
|
||||
convertedCount++;
|
||||
}
|
||||
|
||||
count = convertedCount;
|
||||
outputIndex = 0;
|
||||
*bestInitial = 0;
|
||||
*bestFinal = 0;
|
||||
while ((outputIndex < 0x10) && (count != 0)) {
|
||||
initial[outputIndex] = 0;
|
||||
final[outputIndex] = 0;
|
||||
value = *current;
|
||||
if (value < 0x61) {
|
||||
goto check_pinyin_extension;
|
||||
}
|
||||
if (value <= 0x7A) {
|
||||
goto pinyin_ascii;
|
||||
}
|
||||
check_pinyin_extension:
|
||||
if (value < 0xF361) {
|
||||
goto invalid_pinyin;
|
||||
}
|
||||
if (value <= 0xF37A) {
|
||||
value += 0xC9F;
|
||||
goto pinyin_initial;
|
||||
}
|
||||
invalid_pinyin:
|
||||
initial[0] = 0xFFFF;
|
||||
final[0] = 0xFFFF;
|
||||
*bestInitial = 0xFFFF;
|
||||
*bestFinal = 0xFFFF;
|
||||
return 1;
|
||||
pinyin_ascii:
|
||||
value -= 0x61;
|
||||
pinyin_initial:
|
||||
firstInitial = Zi8PinyinInitials[value];
|
||||
if (firstInitial != 0) {
|
||||
if (outputIndex == 0) {
|
||||
*resultCount = *resultCount + 1;
|
||||
}
|
||||
result++;
|
||||
initial[outputIndex] = 0x7E00;
|
||||
final[outputIndex] = (ziU16)firstInitial << 9;
|
||||
*bestInitial = initial[outputIndex];
|
||||
*bestFinal = final[outputIndex];
|
||||
count--;
|
||||
if (count == 0) {
|
||||
break;
|
||||
}
|
||||
current += 1;
|
||||
if (((firstInitial & 0x80) != 0) && ((current[0] == 0x68) || (current[0] == 0xF368))) {
|
||||
if (outputIndex == 0) {
|
||||
*resultCount = *resultCount + 1;
|
||||
}
|
||||
final[outputIndex] += 0x200;
|
||||
*bestInitial = initial[outputIndex];
|
||||
*bestFinal = final[outputIndex];
|
||||
count--;
|
||||
if (count == 0) {
|
||||
break;
|
||||
}
|
||||
current += 1;
|
||||
}
|
||||
} else if ((*current == 0xF369) || (*current == 0x69)) {
|
||||
goto invalid_pinyin;
|
||||
}
|
||||
partial = 0;
|
||||
for (index = 0; index < 4; index++) {
|
||||
pinyin[index] = 0;
|
||||
}
|
||||
index = 0;
|
||||
do {
|
||||
while (1) {
|
||||
if (index > 3) {
|
||||
goto finish_final;
|
||||
}
|
||||
value = *current;
|
||||
if ((value == 0x27) || (value == 0xF360) || (value == 0x20)) {
|
||||
if (index != 0) {
|
||||
partial = 1;
|
||||
}
|
||||
goto finish_final;
|
||||
}
|
||||
if ((value > 0xF330) && (value < 0xF336)) {
|
||||
if (index != 0) {
|
||||
partial = 1;
|
||||
}
|
||||
goto finish_final;
|
||||
}
|
||||
if ((value < 0x61) || (value > 0x7A)) {
|
||||
if (value < 0xF361) {
|
||||
goto finish_final;
|
||||
}
|
||||
value += 0xC9F;
|
||||
if (value > 0x19) {
|
||||
if (outputIndex == 0) {
|
||||
*resultCount = *resultCount + 1;
|
||||
}
|
||||
goto finish_final;
|
||||
}
|
||||
} else {
|
||||
value -= 0x61;
|
||||
}
|
||||
pinyin[index] = (ziU8)value + 1;
|
||||
if (Zi8GetPyFinal(pinyin, &pyInitial, &pyFinal) == 0) {
|
||||
break;
|
||||
}
|
||||
if (outputIndex == 0) {
|
||||
*resultCount = *resultCount + 1;
|
||||
}
|
||||
current++;
|
||||
index++;
|
||||
count--;
|
||||
if (count == 0) {
|
||||
goto finish_final;
|
||||
}
|
||||
}
|
||||
if (index > 2) {
|
||||
pinyin[index] = 0;
|
||||
partial = 1;
|
||||
break;
|
||||
}
|
||||
pinyin[index + 1] = 0xFF;
|
||||
if (Zi8GetPyFinal(pinyin, &pyInitial, &pyFinal) == 0) {
|
||||
pinyin[index + 1] = 0;
|
||||
pinyin[index] = 0;
|
||||
partial = 1;
|
||||
break;
|
||||
}
|
||||
if (outputIndex == 0) {
|
||||
*resultCount = *resultCount + 1;
|
||||
}
|
||||
pinyin[index + 1] = 0;
|
||||
current++;
|
||||
index++;
|
||||
count--;
|
||||
} while (count != 0);
|
||||
|
||||
finish_final:
|
||||
if ((index > 3) && (count != 0) && ((*current == 0x27) || (*current == 0xF360) || (*current == 0x20))) {
|
||||
if (outputIndex == 0) {
|
||||
*resultCount = *resultCount + 1;
|
||||
}
|
||||
current++;
|
||||
count--;
|
||||
}
|
||||
if (index > 3) {
|
||||
partial = 1;
|
||||
}
|
||||
if (!partial) {
|
||||
pinyin[index] = 0xFF;
|
||||
if (Zi8GetPyFinal(pinyin, &pyInitial, &pyFinal) == 0) {
|
||||
pinyin[index] = 0;
|
||||
if (Zi8GetPyFinal(pinyin, &pyInitial, &pyFinal) != 0) {
|
||||
if (firstInitial == 0) {
|
||||
result++;
|
||||
initial[outputIndex] = 0x7E00;
|
||||
final[outputIndex] = 0x200;
|
||||
}
|
||||
initial[outputIndex] |= (ziU16)pyInitial << 3;
|
||||
final[outputIndex] |= (ziU16)pyFinal << 3;
|
||||
*bestInitial = initial[outputIndex];
|
||||
*bestFinal = final[outputIndex];
|
||||
}
|
||||
} else {
|
||||
if (firstInitial == 0) {
|
||||
result++;
|
||||
initial[outputIndex] = 0x7E00;
|
||||
final[outputIndex] = 0x200;
|
||||
}
|
||||
initial[outputIndex] |= (ziU16)pyInitial << 3;
|
||||
final[outputIndex] |= (ziU16)pyFinal << 3;
|
||||
*bestInitial = initial[outputIndex];
|
||||
*bestFinal = final[outputIndex];
|
||||
if ((outputIndex == 0) && (count == 0)) {
|
||||
pinyin[index] = 0;
|
||||
if (Zi8GetPyFinal(pinyin, &pyInitial, &pyFinal) != 0) {
|
||||
if (firstInitial == 0) {
|
||||
*bestInitial = 0x7E00;
|
||||
*bestFinal = 0x200;
|
||||
}
|
||||
*bestInitial |= (ziU16)pyInitial << 3;
|
||||
*bestFinal |= (ziU16)pyFinal << 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (Zi8GetPyFinal(pinyin, &pyInitial, &pyFinal) != 0) {
|
||||
if (firstInitial == 0) {
|
||||
result++;
|
||||
initial[outputIndex] = 0x7E00;
|
||||
final[outputIndex] = 0x200;
|
||||
}
|
||||
initial[outputIndex] |= (ziU16)pyInitial << 3;
|
||||
final[outputIndex] |= (ziU16)pyFinal << 3;
|
||||
*bestInitial = initial[outputIndex];
|
||||
*bestFinal = final[outputIndex];
|
||||
} else {
|
||||
if ((index != 0) && (count != 0)) {
|
||||
goto invalid_pinyin;
|
||||
}
|
||||
}
|
||||
}
|
||||
convertedCount = count;
|
||||
if (count != 0) {
|
||||
value = *current;
|
||||
if ((value == 0x27) || (value == 0xF360) || (value == 0x20)) {
|
||||
current++;
|
||||
convertedCount = count - 1;
|
||||
if (outputIndex == 0) {
|
||||
*resultCount = *resultCount + 1;
|
||||
}
|
||||
} else if ((value > 0xF330) && ((ziU16)(value + 0xCCF) < 5)) {
|
||||
initial[outputIndex] |= 7;
|
||||
final[outputIndex] |= value + 0xCD0;
|
||||
*bestInitial = initial[outputIndex];
|
||||
*bestFinal = final[outputIndex];
|
||||
convertedCount = count - 1;
|
||||
current++;
|
||||
if (outputIndex == 0) {
|
||||
*resultCount = *resultCount + 1;
|
||||
}
|
||||
if ((convertedCount != 0) && ((*current == 0x27) || (*current == 0xF360) || (*current == 0x20))) {
|
||||
convertedCount = count - 2;
|
||||
current++;
|
||||
if (outputIndex == 0) {
|
||||
*resultCount = *resultCount + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
count = convertedCount;
|
||||
outputIndex++;
|
||||
}
|
||||
if ((*resultCount > 1) && (text[*resultCount - 1] > 0xF340) && (text[*resultCount - 1] < 0xF35B)) {
|
||||
*resultCount = *resultCount - 1;
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
ziBool Zi8GetPyFinal(ziU8* pinyin, ziU8* initial, ziU8* final) {
|
||||
ziU8 index = 0;
|
||||
ziU8 row;
|
||||
row = 0;
|
||||
goto check_row;
|
||||
scan_row:
|
||||
while (index < 4) {
|
||||
if (pinyin[index] != Zi8PinyinFinals[row][index]) {
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
if (index < 4) {
|
||||
goto next_row;
|
||||
}
|
||||
*initial = Zi8PinyinFinals[row][4];
|
||||
*final = Zi8PinyinFinals[row][5];
|
||||
return 1;
|
||||
next_row:
|
||||
row++;
|
||||
index = 0;
|
||||
check_row:
|
||||
if (row < 0x36) {
|
||||
goto scan_row;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
ziS32 Zi8GetBpmfPhonetic(ziWChar* text, ziU8 count, ziU16* initial, ziU16* final, ziU16* bestInitial, ziU16* bestFinal ZI_NEED_WORK) {
|
||||
ziU16 value;
|
||||
ziU32 resultCount = 0;
|
||||
|
||||
Zi8LogError(0x64, ZI_WORK);
|
||||
if (count == 0) {
|
||||
Zi8ReplaceLastError(0x135, ZI_WORK);
|
||||
return 0;
|
||||
}
|
||||
value = text[0];
|
||||
if (value < 0xF305) {
|
||||
Zi8ReplaceLastError(0x154, ZI_WORK);
|
||||
return 0;
|
||||
}
|
||||
value -= 0xF305;
|
||||
if (value >= 0x25) {
|
||||
Zi8ReplaceLastError(0x154, ZI_WORK);
|
||||
return 0;
|
||||
}
|
||||
if (value < 0x15) {
|
||||
*initial = 0x7E00;
|
||||
*final = ((ziU16)Zi8BpmfInitials[value] & 0x7F) << 9;
|
||||
resultCount++;
|
||||
count--;
|
||||
if (count == 0) {
|
||||
*bestInitial = *initial;
|
||||
*bestFinal = *final;
|
||||
if ((value >= 0xE) && (value <= 0x14)) {
|
||||
*bestInitial |= 0x1F8;
|
||||
*bestFinal |= 0x38;
|
||||
}
|
||||
return resultCount;
|
||||
}
|
||||
text++;
|
||||
if (*text == 0xF360) {
|
||||
resultCount++;
|
||||
count--;
|
||||
if (count == 0) {
|
||||
return resultCount;
|
||||
}
|
||||
Zi8ReplaceLastError(0x156, ZI_WORK);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
*initial = 0x7E00;
|
||||
*final = 0x200;
|
||||
}
|
||||
|
||||
value = *text - 0xF305;
|
||||
switch ((ziS32)value) {
|
||||
case 0x22:
|
||||
goto bpmf_value_22;
|
||||
case 0x23:
|
||||
goto bpmf_value_23;
|
||||
case 0x24:
|
||||
goto bpmf_value_24;
|
||||
default:
|
||||
goto set_bpmf_initial;
|
||||
}
|
||||
bpmf_value_22:
|
||||
*final |= 0x80;
|
||||
*initial |= 0x180;
|
||||
resultCount++;
|
||||
count--;
|
||||
if (count == 0) {
|
||||
*bestInitial = *initial | 0x78;
|
||||
*bestFinal = *final | 0x38;
|
||||
return resultCount;
|
||||
}
|
||||
text++;
|
||||
goto after_bpmf_initial;
|
||||
bpmf_value_23:
|
||||
*final |= 0x100;
|
||||
*initial |= 0x180;
|
||||
resultCount++;
|
||||
count--;
|
||||
if (count == 0) {
|
||||
*bestInitial = *initial | 0x78;
|
||||
*bestFinal = *final | 0x38;
|
||||
return resultCount;
|
||||
}
|
||||
text++;
|
||||
goto after_bpmf_initial;
|
||||
bpmf_value_24:
|
||||
*final |= 0x180;
|
||||
*initial |= 0x180;
|
||||
resultCount++;
|
||||
count--;
|
||||
if (count == 0) {
|
||||
*bestInitial = *initial | 0x78;
|
||||
*bestFinal = *final | 0x38;
|
||||
return resultCount;
|
||||
}
|
||||
text++;
|
||||
goto after_bpmf_initial;
|
||||
set_bpmf_initial:
|
||||
if ((*text < 0xF331) || (*text > 0xF335)) {
|
||||
*initial |= 0x180;
|
||||
}
|
||||
after_bpmf_initial:
|
||||
|
||||
value = *text - 0xF305;
|
||||
if ((value > 0x14) && (value < 0x22)) {
|
||||
*final |= (ziU16)Zi8BpmfInitials[value] << 3;
|
||||
*initial |= 0x78;
|
||||
resultCount++;
|
||||
count--;
|
||||
if (count == 0) {
|
||||
*bestInitial = *initial;
|
||||
*bestFinal = *final;
|
||||
return resultCount;
|
||||
}
|
||||
text++;
|
||||
} else if ((*text < 0xF331) || (*text > 0xF335) || ((*initial & 0x180) == 0x180)) {
|
||||
*final |= 0x38;
|
||||
*initial |= 0x78;
|
||||
}
|
||||
|
||||
value = *text;
|
||||
if (value < 0xF331) {
|
||||
Zi8ReplaceLastError(0x155, ZI_WORK);
|
||||
return 0;
|
||||
}
|
||||
value -= 0xF330;
|
||||
if (value > 5) {
|
||||
Zi8ReplaceLastError(0x155, ZI_WORK);
|
||||
return 0;
|
||||
}
|
||||
*initial |= 7;
|
||||
*final |= value;
|
||||
*bestInitial = *initial;
|
||||
*bestFinal = *final;
|
||||
resultCount++;
|
||||
count--;
|
||||
if (count != 0) {
|
||||
Zi8ReplaceLastError(0x157, ZI_WORK);
|
||||
return 0;
|
||||
}
|
||||
return resultCount;
|
||||
}
|
||||
|
||||
ziU16 Zi8GetPCode(ziU8* table, ziU8* node) {
|
||||
ziU16 index = ((ziU16)node[8] << 2) | (((ziU16)node[9] & 0x80) >> 6);
|
||||
return ((((ziU16)node[9] >> 4) & 7) | (ziU16)table[index] | ((ziU16)table[index + 1] << 8));
|
||||
}
|
||||
423
libs/RVLMiddleware/eZiText/src/clib/zikorean.c
Normal file
423
libs/RVLMiddleware/eZiText/src/clib/zikorean.c
Normal file
@@ -0,0 +1,423 @@
|
||||
#include <zi8clib/zierror.h>
|
||||
#include <zi8clib/zitypes.h>
|
||||
|
||||
ziU32 Zi8GetTableAddress(ziU8 lang, ziU8 tableIdx, ziPtr workData);
|
||||
ziU16 Zi8GetTableCount(ziU8 lang, ziU8 tableIdx, ziPtr workData);
|
||||
|
||||
ziU8 Zi8_814813FC(ziWChar character, ziU8* result, ziU16* index, ziPtr workData) {
|
||||
ziU16 i;
|
||||
ziU8* table;
|
||||
|
||||
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 5, workData);
|
||||
i = 0;
|
||||
while (table[i] != 0) {
|
||||
if (character == table[i]) {
|
||||
*index = i;
|
||||
*result = table[i];
|
||||
Zi8LogError(0x64, workData);
|
||||
return 1;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
Zi8LogError(0x2A8, workData);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ziU8 Zi8_81481E6C(ziU16* resultIndex, ziU16* input, ziU8 type, ziU16 count, ziPtr workData);
|
||||
|
||||
ziU8 Zi8GetKoreanCandidates(ziGetParam* params, ziU8* argument,
|
||||
ziPtr workData) {
|
||||
struct {
|
||||
ziU8 characterIndex;
|
||||
ziU8 matched;
|
||||
ziU8 elementIndex;
|
||||
ziU8 reserved;
|
||||
ziU16 index;
|
||||
ziU16 currentCandidate;
|
||||
ziU16 inputIndex;
|
||||
ziU16 nextIndex;
|
||||
ziU16 tableCount31;
|
||||
ziU16 tableCount6;
|
||||
ziU16 tableCount3;
|
||||
ziU16 tableCount0;
|
||||
ziU8* table31;
|
||||
ziU8* table2;
|
||||
ziU8* table1;
|
||||
} state;
|
||||
ziU16 buffer[100];
|
||||
unsigned int result;
|
||||
ziU16 currentCharacter;
|
||||
ziU8* selectedTable;
|
||||
|
||||
state.nextIndex = 0;
|
||||
result = 0;
|
||||
state.characterIndex = 0xFF;
|
||||
state.currentCandidate = params->firstCandidate;
|
||||
params->unk_0x20 = 0;
|
||||
params->count = 0;
|
||||
params->letters = 0;
|
||||
if ((argument != 0) && (*argument != 0)) {
|
||||
Zi8LogError(0x7D0, workData);
|
||||
return 0;
|
||||
}
|
||||
if ((params->elementCount == 0) || (params->elementCount > 100)) {
|
||||
Zi8LogError(0x64, workData);
|
||||
return 0;
|
||||
}
|
||||
|
||||
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 4, workData);
|
||||
state.table1 = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 1, workData);
|
||||
state.table2 = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 2, workData);
|
||||
state.table31 = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x31, workData);
|
||||
state.tableCount0 = Zi8GetTableCount(ZI8_LANG_KO, 0, workData);
|
||||
state.tableCount3 = Zi8GetTableCount(ZI8_LANG_KO, 3, workData);
|
||||
state.tableCount6 = Zi8GetTableCount(ZI8_LANG_KO, 6, workData);
|
||||
state.tableCount31 = Zi8GetTableCount(ZI8_LANG_KO, 0x31, workData);
|
||||
|
||||
for (state.elementIndex = 0; state.elementIndex < params->elementCount;
|
||||
state.elementIndex++) {
|
||||
currentCharacter = params->elements[state.elementIndex];
|
||||
|
||||
if ((currentCharacter >= 0x61) && (currentCharacter <= 0x7A)) {
|
||||
buffer[state.elementIndex] = state.table1[(currentCharacter - 0x61) * 2];
|
||||
} else if ((currentCharacter >= 0x41) && (currentCharacter <= 0x5A)) {
|
||||
buffer[state.elementIndex] = state.table1[(currentCharacter - 0x41) * 2 + 1];
|
||||
} else {
|
||||
state.matched = 0;
|
||||
for (; state.table2[state.matched * 3] != 0; state.matched++) {
|
||||
if (currentCharacter == state.table2[state.matched * 3]) break;
|
||||
}
|
||||
if (state.table2[(state.matched * 3)] == 0) {
|
||||
Zi8LogError(0x161, workData);
|
||||
return 0;
|
||||
}
|
||||
buffer[state.elementIndex] =
|
||||
(state.table2[(state.matched * 3) + 1] << 8) |
|
||||
state.table2[(state.matched * 3) + 2];
|
||||
}
|
||||
}
|
||||
|
||||
for (currentCharacter = 0; currentCharacter < state.elementIndex; currentCharacter++) {
|
||||
state.inputIndex = 0;
|
||||
if (Zi8_814813FC(buffer[currentCharacter], (ziU8*)&state.characterIndex,
|
||||
(ziU16*)&state.inputIndex, workData) == 0) {
|
||||
state.matched = 0;
|
||||
} else {
|
||||
state.matched = Zi8_81481E6C((ziU16*)&state.nextIndex,
|
||||
&buffer[currentCharacter + 1],
|
||||
state.characterIndex,
|
||||
(state.elementIndex - currentCharacter) - 1,
|
||||
workData);
|
||||
if ((((struct __zi8_work_data_s*)workData)->unk_0x1B30 == 1) && (state.characterIndex < 0x1F)) {
|
||||
switch (state.characterIndex) {
|
||||
case 1:
|
||||
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x1E, workData);
|
||||
break;
|
||||
case 2:
|
||||
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x1F, workData);
|
||||
break;
|
||||
case 4:
|
||||
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x20, workData);
|
||||
break;
|
||||
case 7:
|
||||
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x21, workData);
|
||||
break;
|
||||
case 8:
|
||||
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x22, workData);
|
||||
break;
|
||||
case 9:
|
||||
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x23, workData);
|
||||
break;
|
||||
case 0x11:
|
||||
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x24, workData);
|
||||
break;
|
||||
case 0x12:
|
||||
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x25, workData);
|
||||
break;
|
||||
case 0x13:
|
||||
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x26, workData);
|
||||
break;
|
||||
case 0x15:
|
||||
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x27, workData);
|
||||
break;
|
||||
case 0x16:
|
||||
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x28, workData);
|
||||
break;
|
||||
case 0x17:
|
||||
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x29, workData);
|
||||
break;
|
||||
case 0x18:
|
||||
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x2A, workData);
|
||||
break;
|
||||
case 0x19:
|
||||
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x2B, workData);
|
||||
break;
|
||||
case 0x1A:
|
||||
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x2C, workData);
|
||||
break;
|
||||
case 0x1B:
|
||||
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x2D, workData);
|
||||
break;
|
||||
case 0x1C:
|
||||
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x2E, workData);
|
||||
break;
|
||||
case 0x1D:
|
||||
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x2F, workData);
|
||||
break;
|
||||
case 0x1E:
|
||||
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x30, workData);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (state.matched == 0) {
|
||||
if (state.currentCandidate == 0) {
|
||||
for (state.index = 0; state.index < state.tableCount31; state.index++) {
|
||||
if (((ziU16)state.table31[(state.index * 3)] == buffer[currentCharacter]) &&
|
||||
((ziU16)state.table31[(state.index * 3) + 1] == buffer[currentCharacter + 1])) {
|
||||
if (currentCharacter == 0) {
|
||||
params->count = 1;
|
||||
}
|
||||
params->candidates[result] =
|
||||
state.tableCount0 + state.table31[(state.index * 3) + 2];
|
||||
result++;
|
||||
currentCharacter++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (state.index == state.tableCount31) {
|
||||
params->candidates[result] = buffer[currentCharacter];
|
||||
if (buffer[currentCharacter] < 0xFF) {
|
||||
if (currentCharacter == 0) {
|
||||
params->count = 1;
|
||||
}
|
||||
params->candidates[result] += state.tableCount0;
|
||||
result++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
state.index = 0;
|
||||
while ((state.index < state.tableCount31) &&
|
||||
(((ziU16)state.table31[(state.index * 3)] != buffer[currentCharacter]) ||
|
||||
((ziU16)state.table31[(state.index * 3) + 1] != buffer[currentCharacter + 1]))) {
|
||||
state.index++;
|
||||
}
|
||||
if (state.index == state.tableCount31) {
|
||||
state.currentCandidate--;
|
||||
}
|
||||
if (currentCharacter == 0) {
|
||||
params->count = 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (state.tableCount6 == 0) {
|
||||
state.nextIndex += state.inputIndex * state.tableCount3;
|
||||
}
|
||||
if (state.currentCandidate == 0) {
|
||||
params->candidates[result] =
|
||||
(selectedTable[state.nextIndex * 2] << 8) | selectedTable[state.nextIndex * 2 + 1];
|
||||
if ((state.tableCount6 != 0) && (((struct __zi8_work_data_s*)workData)->unk_0x1B30 == 0)) {
|
||||
params->candidates[result] += state.inputIndex * state.tableCount3;
|
||||
}
|
||||
result++;
|
||||
} else {
|
||||
state.currentCandidate--;
|
||||
}
|
||||
if (currentCharacter == 0) {
|
||||
params->count = state.matched + 1;
|
||||
}
|
||||
currentCharacter += state.matched;
|
||||
}
|
||||
if (result >= params->maxCandidates) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
params->letters = result;
|
||||
Zi8LogError(0x64, workData);
|
||||
return result;
|
||||
}
|
||||
|
||||
ziU8 Zi8_81481E6C(ziU16* resultIndex, ziU16* input, ziU8 type, ziU16 count, ziPtr workData) {
|
||||
ziU16 nestedScratch;
|
||||
ziU16 nestedIndexStorage;
|
||||
ziU16 index1;
|
||||
ziU16 index2;
|
||||
ziU16 index3;
|
||||
ziU16 index4;
|
||||
ziU16 firstCharacter;
|
||||
ziU16 tableCount;
|
||||
ziU8 mappedCharacter;
|
||||
ziU8* table;
|
||||
|
||||
firstCharacter = input[0];
|
||||
mappedCharacter = 0xFF;
|
||||
if (((struct __zi8_work_data_s*)workData)->unk_0x1B30 == 0) {
|
||||
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 3, workData);
|
||||
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 3, workData);
|
||||
} else {
|
||||
switch (type) {
|
||||
case 1:
|
||||
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0xB, workData);
|
||||
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0xB, workData);
|
||||
break;
|
||||
case 2:
|
||||
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0xC, workData);
|
||||
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0xC, workData);
|
||||
break;
|
||||
case 4:
|
||||
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0xD, workData);
|
||||
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0xD, workData);
|
||||
break;
|
||||
case 7:
|
||||
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0xE, workData);
|
||||
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0xE, workData);
|
||||
break;
|
||||
case 8:
|
||||
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0xF, workData);
|
||||
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0xF, workData);
|
||||
break;
|
||||
case 9:
|
||||
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x10, workData);
|
||||
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x10, workData);
|
||||
break;
|
||||
case 0x11:
|
||||
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x11, workData);
|
||||
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x11, workData);
|
||||
break;
|
||||
case 0x12:
|
||||
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x12, workData);
|
||||
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x12, workData);
|
||||
break;
|
||||
case 0x13:
|
||||
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x13, workData);
|
||||
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x13, workData);
|
||||
break;
|
||||
case 0x15:
|
||||
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x14, workData);
|
||||
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x14, workData);
|
||||
break;
|
||||
case 0x16:
|
||||
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x15, workData);
|
||||
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x15, workData);
|
||||
break;
|
||||
case 0x17:
|
||||
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x16, workData);
|
||||
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x16, workData);
|
||||
break;
|
||||
case 0x18:
|
||||
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x17, workData);
|
||||
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x17, workData);
|
||||
break;
|
||||
case 0x19:
|
||||
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x18, workData);
|
||||
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x18, workData);
|
||||
break;
|
||||
case 0x1A:
|
||||
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x19, workData);
|
||||
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x19, workData);
|
||||
break;
|
||||
case 0x1B:
|
||||
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x1A, workData);
|
||||
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x1A, workData);
|
||||
break;
|
||||
case 0x1C:
|
||||
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x1B, workData);
|
||||
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x1B, workData);
|
||||
break;
|
||||
case 0x1D:
|
||||
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x1C, workData);
|
||||
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x1C, workData);
|
||||
break;
|
||||
case 0x1E:
|
||||
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x1D, workData);
|
||||
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x1D, workData);
|
||||
break;
|
||||
}
|
||||
}
|
||||
*resultIndex = 0;
|
||||
if ((count < 1) || (firstCharacter >= 0xFF)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
index1 = *resultIndex;
|
||||
for (; index1 < tableCount; index1++) {
|
||||
if (table[index1 * 4] >= firstCharacter) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((index1 >= tableCount) || (firstCharacter != table[index1 * 4])) {
|
||||
return 0;
|
||||
}
|
||||
if ((count < 2) || ((firstCharacter = input[1]) >= 0xFF)) {
|
||||
*resultIndex = index1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
index2 = index1;
|
||||
for (; index2 < tableCount; index2++) {
|
||||
if ((table + index2 * 4)[1] >= firstCharacter) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((index2 >= tableCount) || (firstCharacter != (table + index2 * 4)[1]) ||
|
||||
(input[0] != table[index2 * 4])) {
|
||||
*resultIndex = index1;
|
||||
return 1;
|
||||
}
|
||||
if ((count < 3) || ((firstCharacter = input[2]) >= 0xFF)) {
|
||||
*resultIndex = index2;
|
||||
return 2;
|
||||
}
|
||||
|
||||
index3 = index2;
|
||||
for (; index3 < tableCount; index3++) {
|
||||
if ((table + index3 * 4)[2] >= firstCharacter) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((index3 >= tableCount) || (firstCharacter != (table + index3 * 4)[2]) ||
|
||||
(input[1] != (table + index3 * 4)[1]) || (input[0] != table[index3 * 4])) {
|
||||
if ((Zi8_814813FC(input[1], &mappedCharacter, &nestedScratch, workData) != 0) &&
|
||||
(Zi8_81481E6C(&nestedIndexStorage, input + 2, mappedCharacter, 1, workData) != 0)) {
|
||||
*resultIndex = index1;
|
||||
return 1;
|
||||
}
|
||||
*resultIndex = index2;
|
||||
return 2;
|
||||
}
|
||||
if ((count < 4) || ((firstCharacter = input[3]) >= 0xFF)) {
|
||||
*resultIndex = index3;
|
||||
return 3;
|
||||
}
|
||||
|
||||
index4 = index3;
|
||||
for (; index4 < tableCount; index4++) {
|
||||
if ((table + index4 * 4)[3] >= firstCharacter) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((index4 >= tableCount) || (firstCharacter != (table + index4 * 4)[3]) ||
|
||||
(input[2] != (table + index4 * 4)[2]) || (input[1] != (table + index4 * 4)[1]) ||
|
||||
(input[0] != table[index4 * 4])) {
|
||||
if ((Zi8_814813FC(input[2], &mappedCharacter, &nestedScratch, workData) != 0) &&
|
||||
(Zi8_81481E6C(&nestedIndexStorage, input + 3, mappedCharacter, 1, workData) != 0)) {
|
||||
*resultIndex = index2;
|
||||
return 2;
|
||||
}
|
||||
*resultIndex = index3;
|
||||
return 3;
|
||||
}
|
||||
if ((count < 5) || ((firstCharacter = input[4]) >= 0xFF)) {
|
||||
*resultIndex = index4;
|
||||
return 4;
|
||||
}
|
||||
if ((Zi8_814813FC(input[3], &mappedCharacter, &nestedScratch, workData) != 0) &&
|
||||
(Zi8_81481E6C(&nestedIndexStorage, input + 4, mappedCharacter, 1, workData) != 0)) {
|
||||
*resultIndex = index3;
|
||||
return 3;
|
||||
}
|
||||
*resultIndex = index4;
|
||||
return 4;
|
||||
}
|
||||
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
|
||||
@@ -7,6 +7,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define AXFX_STEREO_CHANNEL_MAX 3
|
||||
|
||||
typedef struct AXFX_BUS {
|
||||
s32* left; // 0x00
|
||||
s32* right; // 0x04
|
||||
@@ -19,6 +21,13 @@ typedef struct AXFX_BUFFERUPDATE {
|
||||
s32* surround; // 0x08
|
||||
} AXFX_BUFFERUPDATE;
|
||||
|
||||
typedef struct AXFX_BUS_DPL2 {
|
||||
s32* left; // 0x00
|
||||
s32* right; // 0x04
|
||||
s32* left_surround; // 0x08
|
||||
s32* right_surround; // 0x0C
|
||||
} AXFX_BUS_DPL2;
|
||||
|
||||
typedef struct AXFX_BUFFERUPDATE_DPL2 {
|
||||
s32* left; // 0x00
|
||||
s32* right; // 0x04
|
||||
|
||||
@@ -49,13 +49,13 @@ typedef struct AXFX_REVERBHI_EXP_DPL2 {
|
||||
f32 crosstalk; // 0x15C
|
||||
f32 earlyGain; // 0x160
|
||||
f32 fusedGain; // 0x164
|
||||
AXFX_BUS* busIn; // 0x168
|
||||
AXFX_BUS* busOut; // 0x16C
|
||||
AXFX_BUS_DPL2* busIn; // 0x168
|
||||
AXFX_BUS_DPL2* busOut; // 0x16C
|
||||
f32 outGain; // 0x170
|
||||
f32 sendGain; // 0x174
|
||||
} AXFX_REVERBHI_EXP_DPL2;
|
||||
|
||||
u32 AXFXReverbHiExpGetMemSizeDpl2(const AXFX_REVERBHI_EXP_DPL2* fx);
|
||||
u32 AXFXReverbHiExpGetMemSizeDpl2(AXFX_REVERBHI_EXP_DPL2* fx);
|
||||
BOOL AXFXReverbHiExpInitDpl2(AXFX_REVERBHI_EXP_DPL2* fx);
|
||||
void AXFXReverbHiExpShutdownDpl2(AXFX_REVERBHI_EXP_DPL2* fx);
|
||||
BOOL AXFXReverbHiExpSettingsDpl2(AXFX_REVERBHI_EXP_DPL2* fx);
|
||||
|
||||
@@ -49,11 +49,11 @@ typedef struct AXFX_REVERBSTD_EXP {
|
||||
f32 sendGain; // 0xE4
|
||||
} AXFX_REVERBSTD_EXP;
|
||||
|
||||
u32 AXFXReverbStdExpGetMemSize(const AXFX_REVERBSTD_EXP* fx);
|
||||
u32 AXFXReverbStdExpGetMemSize(AXFX_REVERBSTD_EXP* fx);
|
||||
BOOL AXFXReverbStdExpInit(AXFX_REVERBSTD_EXP* fx);
|
||||
void AXFXReverbStdExpShutdown(AXFX_REVERBSTD_EXP* fx);
|
||||
BOOL AXFXReverbStdExpSettings(AXFX_REVERBSTD_EXP* fx);
|
||||
void AXFXReverbStdExpCallback(void* chans, AXFX_REVERBSTD_EXP* context);
|
||||
void AXFXReverbStdExpCallback(AXFX_BUS* update, AXFX_REVERBSTD_EXP* fx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
461
libs/RVL_SDK/src/axfx/AXFXReverbHiExpDpl2.c
Normal file
461
libs/RVL_SDK/src/axfx/AXFXReverbHiExpDpl2.c
Normal file
@@ -0,0 +1,461 @@
|
||||
#include <private/axfx.h>
|
||||
#include <revolution/AXFX.h>
|
||||
#include <revolution/MEM.h>
|
||||
#include <revolution/OS.h>
|
||||
#include <revolution/ax.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
static BOOL __AllocDelayLine(AXFX_REVERBHI_EXP_DPL2* fx);
|
||||
static void __BzeroDelayLines(AXFX_REVERBHI_EXP_DPL2* fx);
|
||||
static void __FreeDelayLine(AXFX_REVERBHI_EXP_DPL2* fx);
|
||||
static BOOL __InitParams(AXFX_REVERBHI_EXP_DPL2* fx);
|
||||
|
||||
static u32 __EarlySizeTable[8][3] = {{157, 479, 829}, {317, 809, 1117}, {479, 941, 1487}, {641, 1259, 1949},
|
||||
{797, 1667, 2579}, {967, 1901, 2903}, {1123, 2179, 3413}, {1279, 2477, 3889}};
|
||||
|
||||
static f32 __EarlyCoefTable[8][3] = {{0.4f, -1.0f, 0.3f}, {0.5f, -0.95f, 0.3f}, {0.6f, -0.9f, 0.3f}, {0.75f, -0.85f, 0.3f},
|
||||
{-0.9f, 0.8f, 0.3f}, {-1.0f, 0.7f, 0.3f}, {-1.0f, 0.7f, 0.3f}, {-1.0f, 0.7f, 0.3f}};
|
||||
|
||||
static u32 __FilterSizeTable[7][9] = {{1789, 1999, 2333, 433, 149, 47, 73, 67, 71}, {149, 293, 449, 251, 103, 47, 73, 67, 71},
|
||||
{947, 1361, 1531, 433, 137, 47, 73, 67, 71}, {1279, 1531, 1973, 509, 149, 47, 73, 67, 71},
|
||||
{1531, 1847, 2297, 563, 179, 47, 73, 67, 71}, {1823, 2357, 2693, 571, 137, 47, 73, 67, 71},
|
||||
{1823, 2357, 2693, 571, 179, 47, 73, 67, 71}};
|
||||
|
||||
u32 AXFXReverbHiExpGetMemSizeDpl2(AXFX_REVERBHI_EXP_DPL2* fx) {
|
||||
u32 sum = 0;
|
||||
u32 i = 0;
|
||||
|
||||
sum += __EarlySizeTable[7][2];
|
||||
sum += (int)(fx->preDelayTimeMax * 32000);
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
sum += __FilterSizeTable[6][i];
|
||||
}
|
||||
|
||||
sum *= 4;
|
||||
|
||||
for (i = 5; i < 9; i++) {
|
||||
sum += __FilterSizeTable[6][i];
|
||||
}
|
||||
|
||||
sum *= 4;
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
BOOL AXFXReverbHiExpInitDpl2(AXFX_REVERBHI_EXP_DPL2* fx) {
|
||||
u32 ch, i;
|
||||
BOOL result = TRUE;
|
||||
BOOL mask = OSDisableInterrupts();
|
||||
|
||||
if (AXGetMode() != AX_OUTPUT_DPL2) {
|
||||
OSRestoreInterrupts(mask);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fx->active = 1;
|
||||
|
||||
if (fx->preDelayTimeMax < 0.0f) {
|
||||
AXFXReverbHiExpShutdownDpl2(fx);
|
||||
OSRestoreInterrupts(mask);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fx->earlyMaxLength = __EarlySizeTable[8 - 1][2];
|
||||
fx->preDelayMaxLength = (u32)(fx->preDelayTimeMax * 32000);
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
fx->combMaxLength[i] = __FilterSizeTable[6][i];
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
fx->allpassMaxLength[i] = __FilterSizeTable[6][3 + i];
|
||||
}
|
||||
|
||||
for (ch = 0; ch < 4; ch++) {
|
||||
fx->lastAllpassMaxLength[ch] = __FilterSizeTable[6][5 + ch];
|
||||
}
|
||||
|
||||
result = __AllocDelayLine(fx);
|
||||
if (result == FALSE) {
|
||||
AXFXReverbHiExpShutdownDpl2(fx);
|
||||
OSRestoreInterrupts(mask);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
__BzeroDelayLines(fx);
|
||||
result = __InitParams(fx);
|
||||
if (result == FALSE) {
|
||||
AXFXReverbHiExpShutdownDpl2(fx);
|
||||
OSRestoreInterrupts(mask);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fx->active &= ~1;
|
||||
OSRestoreInterrupts(mask);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL AXFXReverbHiExpSettingsDpl2(AXFX_REVERBHI_EXP_DPL2* fx) {
|
||||
BOOL mask = OSDisableInterrupts();
|
||||
fx->active = fx->active | 1;
|
||||
AXFXReverbHiExpShutdownDpl2(fx);
|
||||
|
||||
if (!AXFXReverbHiExpInitDpl2(fx)) {
|
||||
AXFXReverbHiExpShutdownDpl2(fx);
|
||||
OSRestoreInterrupts(mask);
|
||||
return FALSE;
|
||||
} else {
|
||||
fx->active |= 2;
|
||||
fx->active &= ~1;
|
||||
OSRestoreInterrupts(mask);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void AXFXReverbHiExpShutdownDpl2(AXFX_REVERBHI_EXP_DPL2* fx) {
|
||||
BOOL mask = OSDisableInterrupts();
|
||||
fx->active |= 1;
|
||||
__FreeDelayLine(fx);
|
||||
OSRestoreInterrupts(mask);
|
||||
}
|
||||
|
||||
void AXFXReverbHiExpCallbackDpl2(AXFX_BUFFERUPDATE_DPL2* bufferUpdate, AXFX_REVERBHI_EXP_DPL2* fx) {
|
||||
u32 ch, i;
|
||||
u32 samp;
|
||||
s32* input[4];
|
||||
f32 data;
|
||||
f32 output[4];
|
||||
f32* earlyLine;
|
||||
f32 earlyOut;
|
||||
f32* preDelayLine;
|
||||
f32 preDelayOut;
|
||||
f32 filterOut;
|
||||
f32* combLine;
|
||||
f32 combOutOne;
|
||||
f32* allpass;
|
||||
f32 outTmp;
|
||||
f32 allpassIn;
|
||||
f32 allpassCoef;
|
||||
f32 lpfOut;
|
||||
f32 lpfCoef1;
|
||||
f32 lpfCoef2;
|
||||
f32 fusedOut[4];
|
||||
f32 fusedGain;
|
||||
f32 crosstalkGain;
|
||||
f32 crosstalkL;
|
||||
f32 crosstalkR;
|
||||
f32 crosstalkLs;
|
||||
f32 crosstalkRs;
|
||||
s32* inBusData[4];
|
||||
s32* outBusData[4];
|
||||
|
||||
if (fx->active != 0) {
|
||||
fx->active &= ~2;
|
||||
return;
|
||||
}
|
||||
|
||||
input[0] = bufferUpdate->left;
|
||||
input[1] = bufferUpdate->right;
|
||||
input[2] = bufferUpdate->left_surround;
|
||||
input[3] = bufferUpdate->right_surround;
|
||||
|
||||
if (fx->busIn != NULL) {
|
||||
inBusData[0] = fx->busIn->left;
|
||||
inBusData[1] = fx->busIn->right;
|
||||
inBusData[2] = fx->busIn->left_surround;
|
||||
inBusData[3] = fx->busIn->right_surround;
|
||||
}
|
||||
|
||||
if (fx->busOut != NULL) {
|
||||
outBusData[0] = fx->busOut->left;
|
||||
outBusData[1] = fx->busOut->right;
|
||||
outBusData[2] = fx->busOut->left_surround;
|
||||
outBusData[3] = fx->busOut->right_surround;
|
||||
}
|
||||
|
||||
lpfCoef1 = 1.0f - fx->lpfCoef;
|
||||
lpfCoef2 = fx->lpfCoef;
|
||||
allpassCoef = fx->allpassCoef;
|
||||
fusedGain = fx->fusedGain * 0.6f;
|
||||
crosstalkGain = fx->crosstalk * 0.333333f;
|
||||
|
||||
for (samp = 0; samp < 96; samp++) {
|
||||
for (ch = 0; ch < 4; ch++) {
|
||||
if (fx->busIn != NULL) {
|
||||
data = (f32)(*(input[ch]) + *(inBusData[ch]++));
|
||||
} else {
|
||||
data = (f32)(*input[ch]);
|
||||
}
|
||||
|
||||
earlyLine = fx->earlyLine[ch];
|
||||
earlyOut = earlyLine[fx->earlyPos[0]] * fx->earlyCoef[0] + earlyLine[fx->earlyPos[1]] * fx->earlyCoef[1] +
|
||||
earlyLine[fx->earlyPos[2]] * fx->earlyCoef[2];
|
||||
|
||||
earlyLine[fx->earlyPos[2]] = data;
|
||||
|
||||
if (fx->preDelayLength != 0) {
|
||||
preDelayLine = fx->preDelayLine[ch];
|
||||
preDelayOut = preDelayLine[fx->preDelayPos];
|
||||
preDelayLine[fx->preDelayPos] = data;
|
||||
} else {
|
||||
preDelayOut = data;
|
||||
}
|
||||
|
||||
filterOut = 0.0f;
|
||||
for (i = 0; i < 3; i++) {
|
||||
combLine = fx->combLine[ch][i];
|
||||
combOutOne = combLine[fx->combPos[i]];
|
||||
combLine[fx->combPos[i]] = preDelayOut + (combOutOne * fx->combCoef[i]);
|
||||
filterOut += combOutOne;
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
allpass = fx->allpassLine[ch][i];
|
||||
outTmp = allpass[fx->allpassPos[i]];
|
||||
allpassIn = filterOut + outTmp * allpassCoef;
|
||||
allpass[fx->allpassPos[i]] = allpassIn;
|
||||
filterOut = outTmp - allpassIn * allpassCoef;
|
||||
}
|
||||
|
||||
lpfOut = lpfCoef1 * filterOut + lpfCoef2 * fx->lastLpfOut[ch];
|
||||
fx->lastLpfOut[ch] = lpfOut;
|
||||
allpass = fx->lastAllpassLine[ch];
|
||||
outTmp = allpass[fx->lastAllpassPos[ch]];
|
||||
allpassIn = lpfOut + outTmp * allpassCoef;
|
||||
allpass[fx->lastAllpassPos[ch]] = allpassIn;
|
||||
fusedOut[ch] = outTmp - allpassIn * allpassCoef;
|
||||
if (++fx->lastAllpassPos[ch] >= fx->lastAllpassLength[ch]) {
|
||||
fx->lastAllpassPos[ch] = 0;
|
||||
}
|
||||
|
||||
fusedOut[ch] *= fusedGain;
|
||||
fusedOut[ch] += earlyOut;
|
||||
}
|
||||
|
||||
crosstalkL = fusedOut[1] + fusedOut[2] + fusedOut[3];
|
||||
crosstalkR = fusedOut[0] + fusedOut[2] + fusedOut[3];
|
||||
crosstalkLs = fusedOut[0] + fusedOut[1] + fusedOut[3];
|
||||
crosstalkRs = fusedOut[0] + fusedOut[1] + fusedOut[2];
|
||||
|
||||
output[0] = fusedOut[0] + crosstalkL * crosstalkGain;
|
||||
output[1] = fusedOut[1] + crosstalkR * crosstalkGain;
|
||||
output[2] = fusedOut[2] + crosstalkLs * crosstalkGain;
|
||||
output[3] = fusedOut[3] + crosstalkRs * crosstalkGain;
|
||||
|
||||
*(input[0]++) = (s32)(output[0] * fx->outGain);
|
||||
*(input[1]++) = (s32)(output[1] * fx->outGain);
|
||||
*(input[2]++) = (s32)(output[2] * fx->outGain);
|
||||
*(input[3]++) = (s32)(output[3] * fx->outGain);
|
||||
|
||||
if (fx->busOut != NULL) {
|
||||
*(outBusData[0]++) = (s32)(output[0] * fx->sendGain);
|
||||
*(outBusData[1]++) = (s32)(output[1] * fx->sendGain);
|
||||
*(outBusData[2]++) = (s32)(output[2] * fx->sendGain);
|
||||
*(outBusData[3]++) = (s32)(output[3] * fx->sendGain);
|
||||
}
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (++fx->earlyPos[i] >= fx->earlyLength) {
|
||||
fx->earlyPos[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (fx->preDelayLength != 0) {
|
||||
if (++fx->preDelayPos >= fx->preDelayLength) {
|
||||
fx->preDelayPos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (++fx->combPos[i] >= fx->combLength[i]) {
|
||||
fx->combPos[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (++fx->allpassPos[i] >= fx->allpassLength[i]) {
|
||||
fx->allpassPos[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static BOOL __AllocDelayLine(AXFX_REVERBHI_EXP_DPL2* fx) {
|
||||
u32 ch, i;
|
||||
|
||||
for (ch = 0; ch < 4; ch++) {
|
||||
fx->earlyLine[ch] = (f32*)__AXFXAlloc(sizeof(f32) * fx->earlyMaxLength);
|
||||
if (fx->earlyLine[ch] == NULL)
|
||||
return FALSE;
|
||||
|
||||
if (fx->preDelayMaxLength != 0) {
|
||||
fx->preDelayLine[ch] = (f32*)__AXFXAlloc(sizeof(f32) * fx->preDelayMaxLength);
|
||||
if (fx->preDelayLine[ch] == NULL)
|
||||
return FALSE;
|
||||
} else {
|
||||
fx->preDelayLine[ch] = NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
fx->combLine[ch][i] = (f32*)__AXFXAlloc(sizeof(f32) * fx->combMaxLength[i]);
|
||||
if (fx->combLine[ch][i] == NULL)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
fx->allpassLine[ch][i] = (f32*)__AXFXAlloc(sizeof(f32) * fx->allpassMaxLength[i]);
|
||||
if (fx->allpassLine[ch][i] == NULL)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fx->lastAllpassLine[ch] = (f32*)__AXFXAlloc(sizeof(f32) * fx->lastAllpassMaxLength[ch]);
|
||||
if (fx->lastAllpassLine[ch] == NULL)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void __BzeroDelayLines(AXFX_REVERBHI_EXP_DPL2* fx) {
|
||||
u32 ch, i;
|
||||
|
||||
for (ch = 0; ch < 4; ch++) {
|
||||
if (fx->earlyLine[ch] != NULL) {
|
||||
memset(fx->earlyLine[ch], 0, sizeof(f32) * fx->earlyMaxLength);
|
||||
}
|
||||
|
||||
if (fx->preDelayLine[ch] != NULL) {
|
||||
memset(fx->preDelayLine[ch], 0, sizeof(f32) * fx->preDelayMaxLength);
|
||||
}
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (fx->combLine[ch][i] != NULL) {
|
||||
memset(fx->combLine[ch][i], 0, sizeof(f32) * fx->combMaxLength[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (fx->allpassLine[ch][i] != NULL) {
|
||||
memset(fx->allpassLine[ch][i], 0, sizeof(f32) * fx->allpassMaxLength[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (fx->lastAllpassLine[ch] != NULL) {
|
||||
memset(fx->lastAllpassLine[ch], 0, sizeof(f32) * fx->lastAllpassMaxLength[ch]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void __FreeDelayLine(AXFX_REVERBHI_EXP_DPL2* fx) {
|
||||
u32 ch, i;
|
||||
|
||||
for (ch = 0; ch < 4; ch++) {
|
||||
if (fx->earlyLine[ch] != NULL) {
|
||||
__AXFXFree(fx->earlyLine[ch]);
|
||||
fx->earlyLine[ch] = NULL;
|
||||
}
|
||||
|
||||
if (fx->preDelayLine[ch] != NULL) {
|
||||
__AXFXFree(fx->preDelayLine[ch]);
|
||||
fx->preDelayLine[ch] = NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (fx->combLine[ch][i] != NULL) {
|
||||
__AXFXFree(fx->combLine[ch][i]);
|
||||
fx->combLine[ch][i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (fx->allpassLine[ch][i] != NULL) {
|
||||
__AXFXFree(fx->allpassLine[ch][i]);
|
||||
fx->allpassLine[ch][i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (fx->lastAllpassLine[ch] != NULL) {
|
||||
__AXFXFree(fx->lastAllpassLine[ch]);
|
||||
fx->lastAllpassLine[ch] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DECOMP_FORCE_LITERAL(AXFXReverbHiExpDpl2_c, -3.0f, 10.0);
|
||||
|
||||
static BOOL __InitParams(AXFX_REVERBHI_EXP_DPL2* reverb) {
|
||||
u32 ch, i;
|
||||
|
||||
if (reverb->earlyMode >= 8)
|
||||
return FALSE;
|
||||
|
||||
if (reverb->preDelayTime < 0.0f || reverb->preDelayTime > reverb->preDelayTimeMax)
|
||||
return FALSE;
|
||||
|
||||
if (reverb->fusedMode >= 6)
|
||||
return FALSE;
|
||||
|
||||
if (reverb->fusedTime < 0.0f)
|
||||
return FALSE;
|
||||
|
||||
if (reverb->coloration < 0.0f || reverb->coloration > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
if (reverb->damping < 0.0f || reverb->damping > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
if (reverb->crosstalk < 0.0f || reverb->crosstalk > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
if (reverb->earlyGain < 0.0f || reverb->earlyGain > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
if (reverb->fusedGain < 0.0f || reverb->fusedGain > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
if (reverb->outGain < 0.0f || reverb->outGain > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
if (reverb->sendGain < 0.0f || reverb->sendGain > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
reverb->earlyLength = __EarlySizeTable[reverb->earlyMode][2];
|
||||
for (i = 0; i < 3; i++) {
|
||||
reverb->earlyPos[i] = reverb->earlyLength - __EarlySizeTable[reverb->earlyMode][i];
|
||||
reverb->earlyCoef[i] = __EarlyCoefTable[reverb->earlyMode][i] * reverb->earlyGain * 0.6f;
|
||||
}
|
||||
|
||||
reverb->preDelayPos = 0;
|
||||
reverb->preDelayLength = (u32)(reverb->preDelayTime * (f32)32000);
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
reverb->combPos[i] = 0;
|
||||
reverb->combLength[i] = __FilterSizeTable[reverb->fusedMode][i];
|
||||
reverb->combCoef[i] = pow(10.0f, (-3.0f * (f32)(reverb->combLength[i]) / (f32)(reverb->fusedTime * 32000)));
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
reverb->allpassPos[i] = 0;
|
||||
reverb->allpassLength[i] = __FilterSizeTable[reverb->fusedMode][3 + i];
|
||||
}
|
||||
|
||||
for (ch = 0; ch < 4; ch++) {
|
||||
reverb->lastAllpassPos[ch] = 0;
|
||||
reverb->lastAllpassLength[ch] = __FilterSizeTable[reverb->fusedMode][5 + ch];
|
||||
}
|
||||
|
||||
reverb->allpassCoef = reverb->coloration;
|
||||
reverb->lpfCoef = 1.0f - reverb->damping;
|
||||
if (reverb->lpfCoef > 0.95f)
|
||||
reverb->lpfCoef = 0.95f;
|
||||
|
||||
for (ch = 0; ch < 4; ch++) {
|
||||
reverb->lastLpfOut[ch] = 0.0f;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -23,7 +23,7 @@ BOOL AXFXReverbStdSettings(AXFX_REVERBSTD* fx) {
|
||||
}
|
||||
|
||||
void AXFXReverbStdCallback(void* chans, void* context) {
|
||||
AXFXReverbStdExpCallback((AXFX_BUFFERUPDATE*)chans, (AXFX_REVERBSTD_EXP*)context);
|
||||
AXFXReverbStdExpCallback((AXFX_BUS*)chans, (AXFX_REVERBSTD_EXP*)context);
|
||||
}
|
||||
|
||||
static void __ParamConvert(AXFX_REVERBSTD* fx) {
|
||||
|
||||
397
libs/RVL_SDK/src/axfx/AXFXReverbStdExp.c
Normal file
397
libs/RVL_SDK/src/axfx/AXFXReverbStdExp.c
Normal file
@@ -0,0 +1,397 @@
|
||||
#include <private/axfx.h>
|
||||
#include <revolution/AXFX.h>
|
||||
#include <revolution/MEM.h>
|
||||
#include <revolution/OS.h>
|
||||
#include <revolution/ax.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
static BOOL __AllocDelayLine(AXFX_REVERBSTD_EXP* fx);
|
||||
static void __BzeroDelayLines(AXFX_REVERBSTD_EXP* fx);
|
||||
static void __FreeDelayLine(AXFX_REVERBSTD_EXP* fx);
|
||||
static BOOL __InitParams(AXFX_REVERBSTD_EXP* fx);
|
||||
|
||||
static u32 __EarlySizeTable[8] = {163, 317, 479, 641, 797, 967, 1123, 1283};
|
||||
|
||||
static u32 __FilterSizeTable[7][4] = {{1789, 1999, 433, 149}, {149, 293, 251, 103}, {947, 1361, 433, 137},
|
||||
{1279, 1531, 509, 149}, {1531, 1847, 563, 179}, {1823, 2357, 571, 137},
|
||||
{1823, 2357, 571, 179}};
|
||||
|
||||
u32 AXFXReverbStdExpGetMemSize(AXFX_REVERBSTD_EXP* fx) {
|
||||
u32 sum = 0;
|
||||
u32 i = 0;
|
||||
|
||||
sum += __EarlySizeTable[7];
|
||||
sum += (int)(fx->preDelayTimeMax * 32000);
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
sum += __FilterSizeTable[6][i];
|
||||
}
|
||||
|
||||
sum *= 3;
|
||||
sum *= 4;
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
BOOL AXFXReverbStdExpInit(AXFX_REVERBSTD_EXP* fx) {
|
||||
u32 ch, i;
|
||||
BOOL result = TRUE;
|
||||
BOOL mask = OSDisableInterrupts();
|
||||
|
||||
fx->active = 1;
|
||||
|
||||
if (fx->preDelayTimeMax < 0.0f) {
|
||||
AXFXReverbStdExpShutdown(fx);
|
||||
OSRestoreInterrupts(mask);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fx->earlyMaxLength = __EarlySizeTable[8 - 1];
|
||||
fx->preDelayMaxLength = (u32)(fx->preDelayTimeMax * 32000);
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
fx->combMaxLength[i] = __FilterSizeTable[6][i];
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
fx->allpassMaxLength[i] = __FilterSizeTable[6][2 + i];
|
||||
}
|
||||
|
||||
result = __AllocDelayLine(fx);
|
||||
if (result == FALSE) {
|
||||
AXFXReverbStdExpShutdown(fx);
|
||||
OSRestoreInterrupts(mask);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
__BzeroDelayLines(fx);
|
||||
result = __InitParams(fx);
|
||||
if (result == FALSE) {
|
||||
AXFXReverbStdExpShutdown(fx);
|
||||
OSRestoreInterrupts(mask);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fx->active &= ~1;
|
||||
OSRestoreInterrupts(mask);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL AXFXReverbStdExpSettings(AXFX_REVERBSTD_EXP* fx) {
|
||||
BOOL mask = OSDisableInterrupts();
|
||||
fx->active = fx->active | 1;
|
||||
AXFXReverbStdExpShutdown(fx);
|
||||
|
||||
if (!AXFXReverbStdExpInit(fx)) {
|
||||
AXFXReverbStdExpShutdown(fx);
|
||||
OSRestoreInterrupts(mask);
|
||||
return FALSE;
|
||||
} else {
|
||||
fx->active |= 2;
|
||||
fx->active &= ~1;
|
||||
OSRestoreInterrupts(mask);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void AXFXReverbStdExpShutdown(AXFX_REVERBSTD_EXP* fx) {
|
||||
BOOL mask = OSDisableInterrupts();
|
||||
fx->active |= 1;
|
||||
__FreeDelayLine(fx);
|
||||
OSRestoreInterrupts(mask);
|
||||
}
|
||||
|
||||
|
||||
void AXFXReverbStdExpCallback(AXFX_BUS* bus, AXFX_REVERBSTD_EXP* reverb) {
|
||||
u32 i, j;
|
||||
|
||||
s32* busParam[AXFX_STEREO_CHANNEL_MAX];
|
||||
s32* busIn[AXFX_STEREO_CHANNEL_MAX];
|
||||
s32* busOut[AXFX_STEREO_CHANNEL_MAX];
|
||||
u32 earlyPos;
|
||||
u32 preDelayPos;
|
||||
u32 combPos0;
|
||||
u32 combPos1;
|
||||
u32 allpassPos0;
|
||||
u32 allpassPos1;
|
||||
f32 sp64;
|
||||
f32 sp60;
|
||||
f32* earlyLine;
|
||||
f32 sp58;
|
||||
f32 earlyCoef;
|
||||
f32* preDelayLine;
|
||||
f32 sp4C;
|
||||
f32* combLine0;
|
||||
f32* combLine1;
|
||||
f32 sp40;
|
||||
f32 sp3C;
|
||||
f32 sp38;
|
||||
f32 combCoef0;
|
||||
f32 combCoef1;
|
||||
f32 sp2C;
|
||||
f32 sp28;
|
||||
f32 sp24;
|
||||
f32 sp20;
|
||||
f32 allpassCoef;
|
||||
f32 sp18;
|
||||
f32 sp14;
|
||||
f32 lpfCoef;
|
||||
f32 spC;
|
||||
f32 sp8;
|
||||
f32* allpassLine;
|
||||
|
||||
if (reverb->active != 0) {
|
||||
reverb->active &= ~2;
|
||||
return;
|
||||
}
|
||||
busParam[AX_STEREO_L] = bus->left;
|
||||
busParam[AX_STEREO_R] = bus->right;
|
||||
busParam[AX_STEREO_S] = bus->surround;
|
||||
if (reverb->busIn) {
|
||||
busIn[AX_STEREO_L] = reverb->busIn->left;
|
||||
busIn[AX_STEREO_R] = reverb->busIn->right;
|
||||
busIn[AX_STEREO_S] = reverb->busIn->surround;
|
||||
}
|
||||
if (reverb->busOut) {
|
||||
busOut[AX_STEREO_L] = reverb->busOut->left;
|
||||
busOut[AX_STEREO_R] = reverb->busOut->right;
|
||||
busOut[AX_STEREO_S] = reverb->busOut->surround;
|
||||
}
|
||||
sp14 = 1.0f - reverb->lpfCoef;
|
||||
lpfCoef = reverb->lpfCoef;
|
||||
earlyCoef = reverb->earlyCoef;
|
||||
combCoef0 = reverb->combCoef[0];
|
||||
combCoef1 = reverb->combCoef[1];
|
||||
allpassCoef = reverb->allpassCoef;
|
||||
spC = 0.6f * reverb->earlyGain;
|
||||
sp8 = 0.6f * reverb->fusedGain;
|
||||
|
||||
for (i = 0; i < 96; i++) {
|
||||
earlyPos = reverb->earlyPos;
|
||||
preDelayPos = reverb->preDelayPos;
|
||||
combPos0 = reverb->combPos[0];
|
||||
combPos1 = reverb->combPos[1];
|
||||
allpassPos0 = reverb->allpassPos[0];
|
||||
allpassPos1 = reverb->allpassPos[1];
|
||||
|
||||
for (j = 0; j < AXFX_STEREO_CHANNEL_MAX; j++) {
|
||||
if (reverb->busIn) {
|
||||
sp64 = *busParam[j] + *busIn[j]++;
|
||||
} else {
|
||||
sp64 = *busParam[j];
|
||||
}
|
||||
earlyLine = reverb->earlyLine[j];
|
||||
sp58 = earlyLine[earlyPos];
|
||||
earlyLine[earlyPos] = sp64 + (sp58 * earlyCoef);
|
||||
if (reverb->preDelayLength != 0) {
|
||||
preDelayLine = reverb->preDelayLine[j];
|
||||
sp4C = preDelayLine[preDelayPos];
|
||||
preDelayLine[preDelayPos] = sp64;
|
||||
} else {
|
||||
sp4C = sp64;
|
||||
}
|
||||
combLine0 = reverb->combLine[j][0];
|
||||
sp40 = combLine0[combPos0];
|
||||
combLine0[combPos0] = sp4C + (sp40 * combCoef0);
|
||||
combLine1 = reverb->combLine[j][1];
|
||||
sp3C = combLine1[combPos1];
|
||||
combLine1[combPos1] = sp4C + (sp3C * combCoef1);
|
||||
sp38 = sp40 + sp3C;
|
||||
allpassLine = reverb->allpassLine[j][0];
|
||||
sp2C = allpassLine[allpassPos0];
|
||||
sp28 = sp38 + (sp2C * allpassCoef);
|
||||
allpassLine[allpassPos0] = sp28;
|
||||
sp24 = sp2C - (sp28 * allpassCoef);
|
||||
sp18 = (sp14 * sp24) + (lpfCoef * reverb->lastLpfOut[j]);
|
||||
reverb->lastLpfOut[j] = sp18;
|
||||
allpassLine = reverb->allpassLine[j][1];
|
||||
sp2C = allpassLine[allpassPos1];
|
||||
sp28 = sp18 + (sp2C * allpassCoef);
|
||||
allpassLine[allpassPos1] = sp28;
|
||||
sp20 = sp2C - (sp28 * allpassCoef);
|
||||
sp60 = (sp58 * spC) + (sp20 * sp8);
|
||||
*busParam[j]++ = (sp60 * reverb->outGain);
|
||||
if (reverb->busOut) {
|
||||
*busOut[j]++ = (sp60 * reverb->sendGain);
|
||||
}
|
||||
}
|
||||
if (++reverb->earlyPos >= reverb->earlyLength) {
|
||||
reverb->earlyPos = 0;
|
||||
}
|
||||
if (reverb->preDelayLength != 0) {
|
||||
if (++reverb->preDelayPos >= reverb->preDelayLength) {
|
||||
reverb->preDelayPos = 0;
|
||||
}
|
||||
}
|
||||
if (++reverb->combPos[0] >= reverb->combLength[0]) {
|
||||
reverb->combPos[0] = 0;
|
||||
}
|
||||
if (++reverb->combPos[1] >= reverb->combLength[1]) {
|
||||
reverb->combPos[1] = 0;
|
||||
}
|
||||
if (++reverb->allpassPos[0] >= reverb->allpassLength[0]) {
|
||||
reverb->allpassPos[0] = 0;
|
||||
}
|
||||
if (++reverb->allpassPos[1] >= reverb->allpassLength[1]) {
|
||||
reverb->allpassPos[1] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static BOOL __AllocDelayLine(AXFX_REVERBSTD_EXP* fx) {
|
||||
u32 ch, i;
|
||||
|
||||
for (ch = 0; ch < 3; ch++) {
|
||||
fx->earlyLine[ch] = (f32*)__AXFXAlloc(sizeof(f32) * fx->earlyMaxLength);
|
||||
if (fx->earlyLine[ch] == NULL)
|
||||
return FALSE;
|
||||
|
||||
if (fx->preDelayMaxLength) {
|
||||
fx->preDelayLine[ch] = (f32*)__AXFXAlloc(sizeof(f32) * fx->preDelayMaxLength);
|
||||
if (fx->preDelayLine[ch] == NULL)
|
||||
return FALSE;
|
||||
} else {
|
||||
fx->preDelayLine[ch] = NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
fx->combLine[ch][i] = (f32*)__AXFXAlloc(sizeof(f32) * fx->combMaxLength[i]);
|
||||
if (fx->combLine[ch][i] == NULL)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
fx->allpassLine[ch][i] = (f32*)__AXFXAlloc(sizeof(f32) * fx->allpassMaxLength[i]);
|
||||
if (fx->allpassLine[ch][i] == NULL)
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void __BzeroDelayLines(AXFX_REVERBSTD_EXP* fx) {
|
||||
u32 ch, i;
|
||||
|
||||
for (ch = 0; ch < 3; ch++) {
|
||||
if (fx->earlyLine[ch])
|
||||
memset(fx->earlyLine[ch], 0, sizeof(f32) * fx->earlyMaxLength);
|
||||
|
||||
if (fx->preDelayLine[ch])
|
||||
memset(fx->preDelayLine[ch], 0, sizeof(f32) * fx->preDelayMaxLength);
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (fx->combLine[ch][i])
|
||||
memset(fx->combLine[ch][i], 0, sizeof(f32) * fx->combMaxLength[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (fx->allpassLine[ch][i])
|
||||
memset(fx->allpassLine[ch][i], 0, sizeof(f32) * fx->allpassMaxLength[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void __FreeDelayLine(AXFX_REVERBSTD_EXP* fx) {
|
||||
u32 ch, i;
|
||||
|
||||
for (ch = 0; ch < 3; ch++) {
|
||||
if (fx->earlyLine[ch]) {
|
||||
__AXFXFree(fx->earlyLine[ch]);
|
||||
fx->earlyLine[ch] = NULL;
|
||||
}
|
||||
|
||||
if (fx->preDelayLine[ch]) {
|
||||
__AXFXFree(fx->preDelayLine[ch]);
|
||||
fx->preDelayLine[ch] = NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (fx->combLine[ch][i]) {
|
||||
__AXFXFree(fx->combLine[ch][i]);
|
||||
fx->combLine[ch][i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (fx->allpassLine[ch][i]) {
|
||||
__AXFXFree(fx->allpassLine[ch][i]);
|
||||
fx->allpassLine[ch][i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static BOOL __InitParams(AXFX_REVERBSTD_EXP* fx) {
|
||||
u32 i;
|
||||
|
||||
if (fx->earlyMode >= 8)
|
||||
return FALSE;
|
||||
|
||||
if (fx->preDelayTime < 0.0f || fx->preDelayTime > fx->preDelayTimeMax)
|
||||
return FALSE;
|
||||
|
||||
if (fx->fusedMode >= 6)
|
||||
return FALSE;
|
||||
|
||||
if (fx->fusedTime < 0.0f)
|
||||
return FALSE;
|
||||
|
||||
if (fx->coloration < 0.0f || fx->coloration > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
if (fx->damping < 0.0f || fx->damping > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
if (fx->earlyGain < 0.0f || fx->earlyGain > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
if (fx->fusedGain < 0.0f || fx->fusedGain > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
if (fx->outGain < 0.0f || fx->outGain > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
if (fx->sendGain < 0.0f || fx->sendGain > 1.0f)
|
||||
return FALSE;
|
||||
|
||||
fx->earlyPos = 0;
|
||||
fx->earlyLength = __EarlySizeTable[fx->earlyMode];
|
||||
if (fx->earlyMode <= 3) {
|
||||
fx->earlyCoef = -0.33f;
|
||||
} else {
|
||||
fx->earlyCoef = 0.33f;
|
||||
}
|
||||
|
||||
fx->preDelayPos = 0;
|
||||
fx->preDelayLength = (u32)(fx->preDelayTime * 32000);
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
f32 t;
|
||||
fx->combPos[i] = 0;
|
||||
fx->combLength[i] = __FilterSizeTable[fx->fusedMode][i];
|
||||
t = -3.0f * (f32)(fx->combLength[i]) / (f32)(fx->fusedTime * 32000);
|
||||
fx->combCoef[i] = pow(10.0f, t);
|
||||
}
|
||||
|
||||
fx->allpassPos[0] = 0;
|
||||
fx->allpassLength[0] = __FilterSizeTable[fx->fusedMode][2];
|
||||
fx->allpassPos[1] = 0;
|
||||
fx->allpassLength[1] = __FilterSizeTable[fx->fusedMode][3];
|
||||
|
||||
fx->allpassCoef = fx->coloration;
|
||||
fx->lpfCoef = 1.0f - fx->damping;
|
||||
if (fx->lpfCoef > 0.95f) {
|
||||
fx->lpfCoef = 0.95f;
|
||||
}
|
||||
|
||||
fx->lastLpfOut[0] = 0.0f;
|
||||
fx->lastLpfOut[1] = 0.0f;
|
||||
fx->lastLpfOut[2] = 0.0f;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
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;
|
||||
}
|
||||
@@ -102,6 +102,8 @@ typedef struct PFDIR_VOLUME_DIRS {
|
||||
typedef struct PFDIR_GLOBAL_STATE {
|
||||
pf_u8 state_prefix[0x40];
|
||||
pf_s32 last_error;
|
||||
pf_u8 driver_and_code_state[0x1C];
|
||||
pf_u32 setting;
|
||||
} PFDIR_GLOBAL_STATE;
|
||||
|
||||
extern PFDIR_GLOBAL_STATE pf_vol_set;
|
||||
@@ -134,6 +136,26 @@ extern pf_s32 PFVOL_CheckCurrentDir(PF_VOLUME* volume, pf_u32 start_cluster);
|
||||
extern pf_s32 PFENT_RemoveEntry(PF_DIR_ENT* entry, PF_ENT_ITER* iter);
|
||||
extern pf_s32 PFFAT_FreeChain(PFDIR_FFD* ffd, pf_u32 start_cluster, pf_u32 chain_index, pf_u32 size);
|
||||
|
||||
static inline pf_u32 directory_is_open(PF_DIR_ENT* entry) {
|
||||
PFDIR_VOLUME_DIRS* volume = (PFDIR_VOLUME_DIRS*)entry->p_vol;
|
||||
pf_s32 index;
|
||||
PFDIR_SDD* sdd = volume->sdds;
|
||||
for (index = 0; index < 3; index++, sdd++) {
|
||||
if ((sdd->stat & 1) != 0 && (sdd->stat & 2) != 0 &&
|
||||
entry->p_vol == sdd->dir_entry.p_vol &&
|
||||
entry->entry_sector == sdd->dir_entry.entry_sector &&
|
||||
entry->entry_offset == sdd->dir_entry.entry_offset) { return 1; }
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern void PFFAT_ResetFFD(PFDIR_FFD*, pf_u32*);
|
||||
static inline pf_s32 release_directory_chain(PFDIR_FFD* ffd, pf_u32 cluster, pf_u32 count) {
|
||||
pf_s32 error = PFFAT_FreeChain(ffd, cluster, -1U, count);
|
||||
if (error != 0) { return error; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFDIR_CheckDirIsEmpty(PF_ENT_ITER* iter, pf_u32* is_empty) {
|
||||
pf_u32 start_cluster = *iter->ffd.p_start_cluster;
|
||||
pf_s32 error;
|
||||
@@ -177,8 +199,8 @@ PFDIR_SDD* PFDIR_GetSDD(PF_VOLUME* volume, PF_DIR_ENT* entry) {
|
||||
pf_s32 i;
|
||||
pf_s32 remaining = 3;
|
||||
|
||||
for (i = 0; remaining != 0; i++, free_candidate++, remaining--) {
|
||||
if ((volume_dirs->sdds[i].stat & 1) == 0 || (volume_dirs->sdds[i].stat & 2) == 0) {
|
||||
for (i = 0; remaining != 0; remaining--) {
|
||||
if ((volume_dirs->sdds[i].stat & 1) == 0 || ((volume_dirs->sdds[i].stat & 1) != 0 && (!volume_dirs->sdds[i].stat & 2) != 0)) {
|
||||
if (first_free_sdd == 0) {
|
||||
first_free_sdd = free_candidate;
|
||||
}
|
||||
@@ -187,6 +209,8 @@ PFDIR_SDD* PFDIR_GetSDD(PF_VOLUME* volume, PF_DIR_ENT* entry) {
|
||||
entry->entry_offset == volume_dirs->sdds[i].dir_entry.entry_offset) {
|
||||
return &volume_dirs->sdds[i];
|
||||
}
|
||||
free_candidate++;
|
||||
i++;
|
||||
}
|
||||
if (first_free_sdd == 0) {
|
||||
return 0;
|
||||
@@ -198,12 +222,21 @@ PFDIR_SDD* PFDIR_GetSDD(PF_VOLUME* volume, PF_DIR_ENT* entry) {
|
||||
return first_free_sdd;
|
||||
}
|
||||
|
||||
static inline PFDIR_DIR* unused_directory(PF_VOLUME* volume) {
|
||||
pf_s32 index;
|
||||
for (index = 0; index < 3; index++) {
|
||||
if ((((PFDIR_VOLUME_DIRS*)volume)->udds[index].stat & 1) == 0) {
|
||||
return &((PFDIR_VOLUME_DIRS*)volume)->udds[index];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFDIR_DoFsexecOpenDir(PF_DIR_ENT* entry, PF_ENT_ITER* iter, PFDIR_DIR** opened_dir) {
|
||||
PFDIR_VOLUME_DIRS* volume_dirs = (PFDIR_VOLUME_DIRS*)entry->p_vol;
|
||||
pf_s32 i;
|
||||
PFDIR_SDD* sdd;
|
||||
PFDIR_DIR* dir;
|
||||
PFDIR_DIR* scan_dir;
|
||||
pf_s32 i;
|
||||
|
||||
*opened_dir = 0;
|
||||
if ((entry->attr & 0x10) == 0) {
|
||||
@@ -213,15 +246,7 @@ pf_s32 PFDIR_DoFsexecOpenDir(PF_DIR_ENT* entry, PF_ENT_ITER* iter, PFDIR_DIR** o
|
||||
if (sdd == 0) {
|
||||
return 0x15;
|
||||
}
|
||||
scan_dir = volume_dirs->udds;
|
||||
for (i = 0; i < 3; i++, scan_dir++) {
|
||||
if ((scan_dir->stat & 1) == 0) {
|
||||
dir = &volume_dirs->udds[i];
|
||||
goto directory_available;
|
||||
}
|
||||
}
|
||||
dir = 0;
|
||||
directory_available:
|
||||
dir = unused_directory((PF_VOLUME*)volume_dirs);
|
||||
if (dir == 0) {
|
||||
return 0x16;
|
||||
}
|
||||
@@ -239,9 +264,9 @@ directory_available:
|
||||
pf_s32 PFDIR_p_opendir(PF_VOLUME* volume, PFDIR_STR* path, PFDIR_DIR** opened_dir) {
|
||||
PF_ENT_ITER iter;
|
||||
PF_DIR_ENT entry;
|
||||
pf_s32 i;
|
||||
PFDIR_SDD* sdd;
|
||||
PFDIR_DIR* dir;
|
||||
pf_s32 i;
|
||||
pf_s32 error;
|
||||
|
||||
if ((PFSTR_StrNCmp(path, (const pf_s8*)"\\", 1, 0, 1) == 0 ||
|
||||
@@ -255,9 +280,6 @@ pf_s32 PFDIR_p_opendir(PF_VOLUME* volume, PFDIR_STR* path, PFDIR_DIR** opened_di
|
||||
} else if (PFSTR_StrNumChar(path, 1) == 2 &&
|
||||
PFSTR_StrNCmp(path, (const pf_s8*)":", 1, 1, 1) == 0) {
|
||||
error = PFVOL_GetCurrentDir(volume, &entry);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
goto open_directory;
|
||||
} else if (PFSTR_StrNumChar(path, 1) == 3 &&
|
||||
PFSTR_StrNCmp(path, (const pf_s8*)":", 1, 1, 1) == 0 &&
|
||||
@@ -288,14 +310,7 @@ open_directory:
|
||||
if (sdd == 0) {
|
||||
return 0x15;
|
||||
}
|
||||
for (i = 0; i < 3; i++) {
|
||||
if ((((PFDIR_VOLUME_DIRS*)volume)->udds[i].stat & 1) == 0) {
|
||||
dir = &((PFDIR_VOLUME_DIRS*)volume)->udds[i];
|
||||
goto directory_available;
|
||||
}
|
||||
}
|
||||
dir = 0;
|
||||
directory_available:
|
||||
dir = unused_directory(volume);
|
||||
if (dir == 0) {
|
||||
return 0x16;
|
||||
}
|
||||
@@ -349,17 +364,23 @@ pf_s32 PFDIR_p_readdir(PFDIR_DIR* dir, PFDIR_READ_RESULT* result) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern pf_s32 PFENT_findEntry(PFDIR_FFD*, PF_DIR_ENT*, pf_u32, PFDIR_STR*, pf_u8, pf_u32*, pf_u32*);
|
||||
extern pf_s32 PFFAT_GetSectorSpecified(PFDIR_FFD*, pf_u32, pf_u32, pf_u32*);
|
||||
extern pf_s32 PFPATH_transformInUnicode(pf_u16*, const pf_s8*);
|
||||
extern void PFPATH_SetSearchPattern(pf_s8*, pf_u16*, PFDIR_STR*);
|
||||
extern pf_u16* pf_w_strcpy(pf_u16*, const pf_u16*);
|
||||
|
||||
pf_s32 PFDIR_p_mkdir(PF_VOLUME* p_vol, PF_STR* p_path, pf_u32 option, PF_DTA* p_dta) {
|
||||
pf_s32 err;
|
||||
PF_STR full_path;
|
||||
PF_STR dirname;
|
||||
PFDIR_STR full_path;
|
||||
PFDIR_STR dirname;
|
||||
pf_u16 dirname_len;
|
||||
PF_ENT_ITER parent_iter;
|
||||
PF_DIR_ENT entry;
|
||||
PF_DIR_ENT parent_entry;
|
||||
PF_ENT_ITER parent_iter;
|
||||
PF_FFD ffd;
|
||||
PFDIR_FFD ffd;
|
||||
PFDIR_FAT_HINT fat_hint;
|
||||
pf_u32 pos;
|
||||
PF_FAT_HINT fat_hint;
|
||||
pf_u32 prev_chain[2];
|
||||
pf_u32 new_sector;
|
||||
|
||||
@@ -368,7 +389,7 @@ pf_s32 PFDIR_p_mkdir(PF_VOLUME* p_vol, PF_STR* p_path, pf_u32 option, PF_DTA* p_
|
||||
err = 0;
|
||||
new_sector = 0;
|
||||
|
||||
err = VFiPFPATH_SplitPath(p_path, &full_path, &dirname);
|
||||
err = PFPATH_SplitPath((PFDIR_STR*)p_path, &full_path, &dirname);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
@@ -383,40 +404,39 @@ pf_s32 PFDIR_p_mkdir(PF_VOLUME* p_vol, PF_STR* p_path, pf_u32 option, PF_DTA* p_
|
||||
if (p_dta != PF_NULL) {
|
||||
p_dta->parent_start_cluster = parent_entry.start_cluster;
|
||||
}
|
||||
VFiPFFAT_InitFFD(&ffd, &fat_hint, p_vol, &parent_entry.start_cluster);
|
||||
err = VFiPFENT_findEntry(&ffd, &entry, 0U, &dirname, 0x77U, PF_NULL, PF_NULL);
|
||||
PFFAT_InitFFD(&ffd, &fat_hint, p_vol, &parent_entry.start_cluster);
|
||||
err = PFENT_findEntry(&ffd, &entry, 0U, &dirname, 0x77U, PF_NULL, PF_NULL);
|
||||
if (err == 0) {
|
||||
return 8;
|
||||
}
|
||||
if (err != 3) {
|
||||
return err;
|
||||
}
|
||||
dirname_len = VFiPFSTR_StrNumChar(&dirname, 1U);
|
||||
if ((dirname_len > 0xFFU) || ((dirname_len + parent_entry.path_len) > 0x103U)) {
|
||||
return 2;
|
||||
}
|
||||
err = VFiPFENT_InitENT(&entry, &dirname, 0x10U, 1U, &parent_entry, p_vol);
|
||||
dirname_len = PFSTR_StrNumChar(&dirname, 1U);
|
||||
if (dirname_len + parent_entry.path_len > 0x103U) { return 2; }
|
||||
if (dirname_len > 0xFFU) { return 1; }
|
||||
err = VFiPFENT_InitENT(&entry, (PF_STR*)&dirname, 0x10U, 1U, &parent_entry, p_vol);
|
||||
if (err == 0) {
|
||||
VFiPFFAT_InitFFD(&ffd, &fat_hint, p_vol, &parent_entry.start_cluster);
|
||||
err = VFiPFENT_allocateEntry(&entry, (entry.num_entry_LFNs + 1), &ffd, prev_chain, PF_NULL, 0x77U, &pos);
|
||||
PFFAT_InitFFD(&ffd, &fat_hint, p_vol, &parent_entry.start_cluster);
|
||||
err = VFiPFENT_allocateEntry(&entry, (entry.num_entry_LFNs + 1), (PF_FFD*)&ffd, prev_chain, PF_NULL, 0x77U, &pos);
|
||||
if (err == 0) {
|
||||
entry.start_cluster = 0;
|
||||
VFiPFFAT_InitFFD(&ffd, &fat_hint, p_vol, &entry.start_cluster);
|
||||
err = VFiPFFAT_GetSectorSpecified(&ffd, 0U, 1U, &new_sector);
|
||||
PFFAT_InitFFD(&ffd, &fat_hint, p_vol, &entry.start_cluster);
|
||||
err = PFFAT_GetSectorSpecified(&ffd, 0U, 1U, &new_sector);
|
||||
if (new_sector == -1U) {
|
||||
err = 6;
|
||||
}
|
||||
if (err == 0) {
|
||||
err = VFiPFENT_FillVoidEntryToSectors(p_vol, new_sector, p_vol->bpb.sectors_per_cluster, 1U, &entry, &parent_entry);
|
||||
if (err == 0) {
|
||||
if ((entry.long_name[0] != 0) && ((VFipf_vol_set.setting & 2) == 2)) {
|
||||
if ((entry.long_name[0] != 0) && ((pf_vol_set.setting & 2) == 2)) {
|
||||
VFiPFPATH_AdjustExtShortName(&entry.short_name[0], pos);
|
||||
entry.check_sum = VFiPFENT_CalcCheckSum(&entry);
|
||||
}
|
||||
err = VFiPFENT_UpdateEntry(&entry, prev_chain, 0U);
|
||||
}
|
||||
if (err != 0) {
|
||||
VFiPFFAT_FreeChain(&ffd, entry.start_cluster, -1U, -1U);
|
||||
PFFAT_FreeChain(&ffd, entry.start_cluster, -1U, -1U);
|
||||
} else if (p_dta != PF_NULL) {
|
||||
p_dta->p_file = PF_NULL;
|
||||
p_dta->p_dir = PF_NULL;
|
||||
@@ -428,16 +448,16 @@ pf_s32 PFDIR_p_mkdir(PF_VOLUME* p_vol, PF_STR* p_path, pf_u32 option, PF_DTA* p_
|
||||
p_dta->Date = entry.modify_date;
|
||||
p_dta->FileSize = entry.file_size;
|
||||
p_dta->Attribute = entry.attr;
|
||||
if (VFiPFSTR_GetCodeMode(&dirname) == 1) {
|
||||
VFiPFPATH_SetSearchPattern(p_dta->reg_exp, PF_NULL, &dirname);
|
||||
if (VFiPFSTR_GetCodeMode((PF_STR*)&dirname) == 1) {
|
||||
PFPATH_SetSearchPattern(p_dta->reg_exp, PF_NULL, &dirname);
|
||||
p_dta->status |= 1;
|
||||
} else {
|
||||
VFiPFPATH_SetSearchPattern(p_dta->reg_exp, ((PF_DTAW*)p_dta)->reg_expW, &dirname);
|
||||
PFPATH_SetSearchPattern(p_dta->reg_exp, ((PF_DTAW*)p_dta)->reg_expW, &dirname);
|
||||
p_dta->status |= 2;
|
||||
}
|
||||
VFipf_strcpy(p_dta->FileName, &entry.short_name[0]);
|
||||
pf_strcpy(p_dta->FileName, &entry.short_name[0]);
|
||||
if ((p_dta->status & 2) == 2) {
|
||||
VFiPFPATH_transformInUnicode(((PF_DTAW*)p_dta)->FileNameW, p_dta->FileName);
|
||||
PFPATH_transformInUnicode(((PF_DTAW*)p_dta)->FileNameW, p_dta->FileName);
|
||||
}
|
||||
if (entry.long_name[0] == 0) {
|
||||
p_dta->ordinal = 0;
|
||||
@@ -449,17 +469,17 @@ pf_s32 PFDIR_p_mkdir(PF_VOLUME* p_vol, PF_STR* p_path, pf_u32 option, PF_DTA* p_
|
||||
} else {
|
||||
p_dta->ordinal = 1;
|
||||
p_dta->check_sum = entry.check_sum;
|
||||
if ((VFipf_vol_set.setting & 2) == 2) {
|
||||
VFipf_vol_set.setting &= 0xFFFFFFFC;
|
||||
VFipf_vol_set.setting |= 1;
|
||||
VFiPFPATH_transformFromUnicodeToNormal(p_dta->LongName, entry.long_name);
|
||||
VFipf_vol_set.setting &= 0xFFFFFFFC;
|
||||
VFipf_vol_set.setting |= 2;
|
||||
if ((pf_vol_set.setting & 2) == 2) {
|
||||
pf_vol_set.setting &= 0xFFFFFFFC;
|
||||
pf_vol_set.setting |= 1;
|
||||
PFPATH_transformFromUnicodeToNormal(p_dta->LongName, entry.long_name);
|
||||
pf_vol_set.setting &= 0xFFFFFFFC;
|
||||
pf_vol_set.setting |= 2;
|
||||
} else {
|
||||
VFiPFPATH_transformFromUnicodeToNormal(p_dta->LongName, entry.long_name);
|
||||
PFPATH_transformFromUnicodeToNormal(p_dta->LongName, entry.long_name);
|
||||
}
|
||||
if ((p_dta->status & 2) == 2) {
|
||||
VFipf_w_strcpy(((PF_DTAW*)p_dta)->LongNameW, entry.long_name);
|
||||
pf_w_strcpy(((PF_DTAW*)p_dta)->LongNameW, entry.long_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -524,7 +544,7 @@ pf_s32 PFDIR_p_chdir(PF_VOLUME* p_vol, PFDIR_STR* p_path_str) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFDIR_p_chmod(PF_VOLUME* volume, PFDIR_STR* path, pf_u8 attributes) {
|
||||
pf_s32 PFDIR_p_chmod(PF_VOLUME* volume, PFDIR_STR* path, pf_u32 attributes) {
|
||||
PFDIR_STR directory_path;
|
||||
PFDIR_STR filename;
|
||||
PF_ENT_ITER iter;
|
||||
@@ -544,52 +564,50 @@ pf_s32 PFDIR_p_chmod(PF_VOLUME* volume, PFDIR_STR* path, pf_u8 attributes) {
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if (((entry.attr & 0x10) == 0 && (attributes & 0x10) != 0) ||
|
||||
((entry.attr & 0x10) != 0 && (attributes & 0x10) == 0)) {
|
||||
if (((entry.attr & 0x10) != 0 && (attributes & 0x10) == 0) ||
|
||||
((entry.attr & 0x10) == 0 && (attributes & 0x10) != 0)) {
|
||||
return 10;
|
||||
}
|
||||
if ((attributes & 0x40) != 0) {
|
||||
attributes &= (pf_u8)~0x40;
|
||||
attributes = (pf_u8)(attributes & ~0x40);
|
||||
}
|
||||
if ((entry.attr & 0x10) == 0) {
|
||||
if (PFFILE_IsOpened(&entry) != 0) {
|
||||
return 0x13;
|
||||
}
|
||||
} else {
|
||||
if ((entry.attr & 0x10) != 0) {
|
||||
volume_dirs = (PFDIR_VOLUME_DIRS*)volume;
|
||||
for (i = 0; i < 3; i++) {
|
||||
PFDIR_SDD* sdd = &volume_dirs->sdds[i];
|
||||
if ((sdd->stat & 1) != 0 && (sdd->stat & 2) != 0 &&
|
||||
entry.p_vol == sdd->dir_entry.p_vol &&
|
||||
entry.entry_sector == sdd->dir_entry.entry_sector &&
|
||||
entry.entry_offset == sdd->dir_entry.entry_offset) {
|
||||
return 0x13;
|
||||
}
|
||||
}
|
||||
if ((attributes & 4) != 0 && (attributes & 0xF) != 0xF) {
|
||||
if (directory_is_open(&entry) != 0) { return 0x13; }
|
||||
|
||||
if ((attributes & 4) != 0 && (pf_s32)(attributes & 0xF) != 0xF) {
|
||||
return 10;
|
||||
}
|
||||
attributes |= 0x10;
|
||||
entry.attr = attributes;
|
||||
} else {
|
||||
if (PFFILE_IsOpened(&entry) != 0) {
|
||||
return 0x13;
|
||||
}
|
||||
entry.attr = attributes;
|
||||
}
|
||||
create_time_ms = PFENT_getcurrentDateTimeForEnt(&date, &time);
|
||||
entry.modify_date = date;
|
||||
entry.modify_time = time;
|
||||
entry.create_time_ms = create_time_ms;
|
||||
entry.attr = attributes;
|
||||
return PFENT_updateEntry(&entry, 0);
|
||||
PFENT_getcurrentDateTimeForEnt(&entry.access_date, &time);
|
||||
if (entry.file_size == 0 && (entry.attr & 0x10) == 0) { entry.start_cluster = 0; }
|
||||
error = PFENT_updateEntry(&entry, 0);
|
||||
if (error != 0) { return error; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFDIR_p_rmdir(PF_VOLUME* volume, PFDIR_STR* path) {
|
||||
PFDIR_VOLUME_DIRS* volume_dirs;
|
||||
PFDIR_STR directory_path;
|
||||
PFDIR_STR filename;
|
||||
PFDIR_FAT_HINT saved_hint;
|
||||
PFDIR_FAT_HINT hint;
|
||||
PFDIR_FFD ffd;
|
||||
PF_ENT_ITER iter;
|
||||
PF_ENT_ITER directory_iter;
|
||||
PF_DIR_ENT entry;
|
||||
pf_u32 is_empty;
|
||||
pf_u32 is_empty = 0;
|
||||
pf_u32 i;
|
||||
pf_s32 error;
|
||||
|
||||
error = PFPATH_SplitPath(path, &directory_path, &filename);
|
||||
if (error != 0) { return error; }
|
||||
error = PFENT_ITER_GetEntryOfPath(&iter, &entry, volume, path, 0);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
@@ -597,30 +615,19 @@ pf_s32 PFDIR_p_rmdir(PF_VOLUME* volume, PFDIR_STR* path) {
|
||||
if ((entry.attr & 0x10) == 0 || (entry.attr & 1) != 0) {
|
||||
return 0x14;
|
||||
}
|
||||
if (entry.start_cluster == 1 ||
|
||||
(volume->bpb.fat_type == FAT_32 && entry.start_cluster == volume->bpb.root_dir_cluster)) {
|
||||
return 0x1C;
|
||||
}
|
||||
volume_dirs = (PFDIR_VOLUME_DIRS*)volume;
|
||||
for (i = 0; i < 3; i++) {
|
||||
PFDIR_SDD* sdd = &volume_dirs->sdds[i];
|
||||
if ((sdd->stat & 3) == 3 && entry.p_vol == sdd->dir_entry.p_vol &&
|
||||
entry.entry_sector == sdd->dir_entry.entry_sector &&
|
||||
entry.entry_offset == sdd->dir_entry.entry_offset) {
|
||||
return 0x13;
|
||||
}
|
||||
}
|
||||
directory_iter = iter;
|
||||
saved_hint = *iter.ffd.p_hint;
|
||||
if (directory_is_open(&entry) != 0) { return 0x13; }
|
||||
|
||||
error = PFVOL_CheckCurrentDir(volume, entry.start_cluster);
|
||||
if (error != 0) {
|
||||
return 0x1C;
|
||||
}
|
||||
if (error != 0 || entry.start_cluster == 1 ||
|
||||
(volume->bpb.fat_type == FAT_32 && entry.start_cluster == volume->bpb.root_dir_cluster)) { return 0x1C; }
|
||||
PFFAT_InitFFD(&ffd, &hint, volume, &entry.start_cluster);
|
||||
directory_iter.ffd = ffd;
|
||||
error = PFENT_ITER_IteratorInitialize(&directory_iter, 0);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
is_empty = 0;
|
||||
error = PFDIR_CheckDirIsEmpty(&directory_iter, &is_empty);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
@@ -628,18 +635,20 @@ pf_s32 PFDIR_p_rmdir(PF_VOLUME* volume, PFDIR_STR* path) {
|
||||
if (is_empty == 0) {
|
||||
return 0x1D;
|
||||
}
|
||||
iter = directory_iter;
|
||||
iter.ffd.p_hint = &saved_hint;
|
||||
error = PFENT_RemoveEntry(&entry, &iter);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
return PFFAT_FreeChain(&iter.ffd, entry.start_cluster, -1U, -1U);
|
||||
return release_directory_chain(&iter.ffd, entry.start_cluster, -1U);
|
||||
}
|
||||
|
||||
pf_s32 PFDIR_p_fstat(PF_VOLUME* volume, PFDIR_STR* path, PFDIR_FILE_STAT* file_stat) {
|
||||
PF_ENT_ITER iter;
|
||||
PF_DIR_ENT entry;
|
||||
PFDIR_VOLUME_DIRS* volume_dirs = (PFDIR_VOLUME_DIRS*)volume;
|
||||
pf_u32 index;
|
||||
pf_s32 index = 0;
|
||||
pf_s32 error;
|
||||
|
||||
error = PFENT_ITER_GetEntryOfPath(&iter, &entry, volume, path, 0);
|
||||
@@ -648,32 +657,32 @@ pf_s32 PFDIR_p_fstat(PF_VOLUME* volume, PFDIR_STR* path, PFDIR_FILE_STAT* file_s
|
||||
}
|
||||
if (volume_dirs->num_opened_files != 0) {
|
||||
for (index = 0; index < 5; index++) {
|
||||
PFDIR_SFD* sfd = &volume_dirs->sfds[index];
|
||||
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) {
|
||||
file_stat->file_size = sfd->dir_entry.file_size;
|
||||
file_stat->access_date = sfd->dir_entry.access_date;
|
||||
file_stat->modify_time = sfd->dir_entry.modify_time;
|
||||
file_stat->modify_date = sfd->dir_entry.modify_date;
|
||||
file_stat->create_time = sfd->dir_entry.create_time;
|
||||
file_stat->create_date = sfd->dir_entry.create_date;
|
||||
file_stat->small_letter_flag = sfd->dir_entry.small_letter_flag;
|
||||
file_stat->attributes = sfd->dir_entry.attr;
|
||||
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) {
|
||||
file_stat->file_size = volume_dirs->sfds[index].dir_entry.file_size;
|
||||
file_stat->attributes = volume_dirs->sfds[index].dir_entry.attr;
|
||||
file_stat->modify_time = volume_dirs->sfds[index].dir_entry.modify_time;
|
||||
file_stat->modify_date = volume_dirs->sfds[index].dir_entry.modify_date;
|
||||
file_stat->access_date = volume_dirs->sfds[index].dir_entry.access_date;
|
||||
file_stat->create_time = volume_dirs->sfds[index].dir_entry.create_time;
|
||||
file_stat->create_date = volume_dirs->sfds[index].dir_entry.create_date;
|
||||
file_stat->small_letter_flag = volume_dirs->sfds[index].dir_entry.create_time_ms;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (volume_dirs->num_opened_files == 0 || index == 5) {
|
||||
file_stat->file_size = (entry.attr & 0x10) == 0 ? entry.file_size : 0;
|
||||
file_stat->access_date = entry.access_date;
|
||||
if ((entry.attr & 0x10) != 0) { file_stat->file_size = 0; }
|
||||
else { file_stat->file_size = entry.file_size; }
|
||||
file_stat->attributes = entry.attr;
|
||||
file_stat->modify_time = entry.modify_time;
|
||||
file_stat->modify_date = entry.modify_date;
|
||||
file_stat->access_date = entry.access_date;
|
||||
file_stat->create_time = entry.create_time;
|
||||
file_stat->create_date = entry.create_date;
|
||||
file_stat->small_letter_flag = entry.small_letter_flag;
|
||||
file_stat->attributes = entry.attr;
|
||||
file_stat->small_letter_flag = entry.create_time_ms;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -721,14 +730,18 @@ pf_s32 PFDIR_p_rename(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
|
||||
PFDIR_STR destination_directory;
|
||||
PFDIR_STR destination_name;
|
||||
pf_s8 normalized_name[512];
|
||||
pf_u32 code_mode;
|
||||
const pf_s8* name;
|
||||
pf_u32 entry_position;
|
||||
pf_u16 filename_length;
|
||||
pf_s32 error;
|
||||
|
||||
error = PFPATH_SplitPath((PFDIR_STR*)old_path, &source_directory, &source_name);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
filename_length = PFSTR_StrNumChar(&source_name, 1);
|
||||
if (filename_length > 0xFF) { return 1; }
|
||||
if (PFSTR_GetCodeMode(&source_name) == 2) {
|
||||
if (PFSTR_StrNumChar(&source_name, 1) > 0xFF) {
|
||||
return 1;
|
||||
@@ -755,7 +768,7 @@ pf_s32 PFDIR_p_rename(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if (entry_position == 0) {
|
||||
if (entry_position == 999999) {
|
||||
return 3;
|
||||
}
|
||||
if ((source_entry.attr & 0x10) != 0) {
|
||||
@@ -784,7 +797,7 @@ pf_s32 PFDIR_p_rename(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
|
||||
if (source_iter.ffd.start_cluster != destination_parent.start_cluster) {
|
||||
return 0x1F;
|
||||
}
|
||||
if (PFSTR_GetCodeMode(&destination_name) == 2) {
|
||||
if ((code_mode = PFSTR_GetCodeMode(&destination_name)) == 2) {
|
||||
if (PFSTR_StrNumChar(&destination_name, 1) > 0xFF) {
|
||||
return 1;
|
||||
}
|
||||
@@ -822,8 +835,10 @@ pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
|
||||
PFDIR_STR destination_name;
|
||||
PFDIR_VOLUME_DIRS* volume_dirs;
|
||||
pf_s8 normalized_name[512];
|
||||
pf_u32 code_mode;
|
||||
pf_u32 entry_position;
|
||||
pf_u32 index;
|
||||
pf_u16 filename_length;
|
||||
pf_s32 index = 0;
|
||||
pf_s32 error;
|
||||
|
||||
error = PFENT_ITER_GetEntryOfPath(&source_iter, &source_entry, volume,
|
||||
@@ -839,7 +854,9 @@ pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if (PFSTR_GetCodeMode(&destination_name) == 2) {
|
||||
filename_length = PFSTR_StrNumChar(&destination_name, 1);
|
||||
if (filename_length > 0xFF) { return 1; }
|
||||
if ((code_mode = PFSTR_GetCodeMode(&destination_name)) == 2) {
|
||||
if (PFSTR_StrNumChar(&destination_name, 1) > 0xFF) {
|
||||
return 1;
|
||||
}
|
||||
@@ -869,15 +886,7 @@ pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
|
||||
source_entry.start_cluster == volume->bpb.root_dir_cluster)) {
|
||||
return 0x1C;
|
||||
}
|
||||
for (index = 0; index < 3; index++) {
|
||||
PFDIR_SDD* sdd = &volume_dirs->sdds[index];
|
||||
if ((sdd->stat & 1) != 0 && (sdd->stat & 2) != 0 &&
|
||||
sdd->dir_entry.p_vol == source_entry.p_vol &&
|
||||
sdd->dir_entry.entry_sector == source_entry.entry_sector &&
|
||||
sdd->dir_entry.entry_offset == source_entry.entry_offset) {
|
||||
return 0x13;
|
||||
}
|
||||
}
|
||||
if (directory_is_open(&source_entry) != 0) { return 0x13; }
|
||||
} else if (PFFILE_IsOpened(&source_entry) != 0) {
|
||||
return 0x13;
|
||||
}
|
||||
@@ -908,9 +917,10 @@ pf_s32 PFDIR_p_fsexec_remove(PF_DTA* data, PF_DIR_ENT* entry, PF_ENT_ITER* iter)
|
||||
PFDIR_VOLUME_DIRS* volume_dirs = (PFDIR_VOLUME_DIRS*)entry->p_vol;
|
||||
PFDIR_FAT_HINT hint;
|
||||
PF_ENT_ITER directory_iter;
|
||||
pf_u32 is_empty;
|
||||
pf_u32 index;
|
||||
pf_u32 start_cluster = entry->start_cluster;
|
||||
pf_u32 is_empty = 0;
|
||||
pf_s32 index = 0;
|
||||
pf_u32 start_cluster;
|
||||
pf_u32 chain_size;
|
||||
pf_s32 error;
|
||||
|
||||
if ((entry->attr & 1) != 0) {
|
||||
@@ -922,32 +932,30 @@ pf_s32 PFDIR_p_fsexec_remove(PF_DTA* data, PF_DIR_ENT* entry, PF_ENT_ITER* iter)
|
||||
entry->start_cluster == entry->p_vol->bpb.root_dir_cluster)) {
|
||||
return 0x1C;
|
||||
}
|
||||
for (index = 0; index < 3; index++) {
|
||||
PFDIR_SDD* sdd = &volume_dirs->sdds[index];
|
||||
if ((sdd->stat & 1) != 0 && (sdd->stat & 2) != 0 &&
|
||||
sdd->dir_entry.p_vol == entry->p_vol &&
|
||||
sdd->dir_entry.entry_sector == entry->entry_sector &&
|
||||
sdd->dir_entry.entry_offset == entry->entry_offset) {
|
||||
return 0x13;
|
||||
}
|
||||
}
|
||||
if (directory_is_open(entry) != 0) { return 0x13; }
|
||||
|
||||
directory_iter = *iter;
|
||||
PFFAT_InitFFD(&directory_iter.ffd, &hint, entry->p_vol, &entry->start_cluster);
|
||||
error = PFENT_ITER_IteratorInitialize(&directory_iter, 0);
|
||||
hint = *iter->ffd.p_hint;
|
||||
PFFAT_ResetFFD(&iter->ffd, &entry->start_cluster);
|
||||
error = PFENT_ITER_IteratorInitialize(iter, 0);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
is_empty = 0;
|
||||
error = PFDIR_CheckDirIsEmpty(&directory_iter, &is_empty);
|
||||
error = PFDIR_CheckDirIsEmpty(iter, &is_empty);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if (is_empty == 0) {
|
||||
return 0x1D;
|
||||
}
|
||||
} else if (PFFILE_IsOpened(entry) != 0) {
|
||||
return 0x13;
|
||||
*iter = directory_iter;
|
||||
iter->ffd.p_hint = &hint;
|
||||
chain_size = -1U;
|
||||
} else {
|
||||
if (PFFILE_IsOpened(entry) != 0) { return 0x13; }
|
||||
chain_size = entry->file_size;
|
||||
}
|
||||
start_cluster = entry->start_cluster;
|
||||
entry->num_entry_LFNs = data->num_entry_LFNs;
|
||||
entry->ordinal = data->ordinal;
|
||||
entry->check_sum = data->check_sum;
|
||||
@@ -955,21 +963,29 @@ pf_s32 PFDIR_p_fsexec_remove(PF_DTA* data, PF_DIR_ENT* entry, PF_ENT_ITER* iter)
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
return PFFAT_FreeChain(&iter->ffd, start_cluster, -1U, -1U);
|
||||
return release_directory_chain(&iter->ffd, start_cluster, chain_size);
|
||||
}
|
||||
|
||||
pf_s32 PFDIR_p_fsexec_chmod(PF_DTA* data, PF_DIR_ENT* entry, pf_u32 attributes, pf_u32 mode) {
|
||||
|
||||
pf_s32 PFDIR_p_fsexec_chmod(PF_DTA* data, PF_DIR_ENT* entry, pf_u32 mode, pf_u32 attributes) {
|
||||
PFDIR_VOLUME_DIRS* volume_dirs = (PFDIR_VOLUME_DIRS*)entry->p_vol;
|
||||
pf_u16 date;
|
||||
pf_u16 time;
|
||||
pf_u8 create_time_ms;
|
||||
pf_u32 index;
|
||||
pf_s32 index = 0;
|
||||
pf_s32 error;
|
||||
|
||||
if ((attributes & 0x40) != 0) {
|
||||
attributes &= ~0x40;
|
||||
attributes = (pf_u8)(attributes & ~0x40);
|
||||
}
|
||||
if ((entry->attr & 0x10) == 0) {
|
||||
if ((entry->attr & 0x10) != 0) {
|
||||
if ((attributes & 4) != 0) {
|
||||
return 10;
|
||||
}
|
||||
if (directory_is_open(entry) != 0) { return 0x13; }
|
||||
|
||||
entry->attr = attributes | 0x10;
|
||||
} else {
|
||||
if ((attributes & 0x10) != 0) {
|
||||
return 10;
|
||||
}
|
||||
@@ -977,25 +993,8 @@ pf_s32 PFDIR_p_fsexec_chmod(PF_DTA* data, PF_DIR_ENT* entry, pf_u32 attributes,
|
||||
return 0x13;
|
||||
}
|
||||
entry->attr = attributes;
|
||||
} else {
|
||||
if ((attributes & 4) != 0) {
|
||||
return 10;
|
||||
}
|
||||
for (index = 0; index < 3; index++) {
|
||||
PFDIR_SDD* sdd = &volume_dirs->sdds[index];
|
||||
if ((sdd->stat & 1) != 0 && (sdd->stat & 2) != 0 &&
|
||||
sdd->dir_entry.p_vol == entry->p_vol &&
|
||||
sdd->dir_entry.entry_sector == entry->entry_sector &&
|
||||
sdd->dir_entry.entry_offset == entry->entry_offset) {
|
||||
return 0x13;
|
||||
}
|
||||
}
|
||||
entry->attr = attributes | 0x10;
|
||||
}
|
||||
create_time_ms = PFENT_getcurrentDateTimeForEnt(&date, &time);
|
||||
entry->modify_date = date;
|
||||
entry->modify_time = time;
|
||||
entry->create_time_ms = create_time_ms;
|
||||
PFENT_getcurrentDateTimeForEnt(&entry->access_date, &time);
|
||||
error = PFENT_updateEntry(entry, 0);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
@@ -1003,7 +1002,9 @@ pf_s32 PFDIR_p_fsexec_chmod(PF_DTA* data, PF_DIR_ENT* entry, pf_u32 attributes,
|
||||
if ((mode & 0x80000000) == 0) {
|
||||
data->Attribute = entry->attr;
|
||||
}
|
||||
return PFCACHE_FlushDataCacheSpecific(entry->p_vol, 0);
|
||||
error = PFCACHE_FlushDataCacheSpecific(entry->p_vol, 0);
|
||||
if (error != 0) { return error; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFDIR_p_fsexec_fopen(PF_DTA* data, PF_DIR_ENT* entry, PF_ENT_ITER* iter, pf_u32 flags,
|
||||
@@ -1062,9 +1063,9 @@ pf_s32 PFDIR_p_fsexec_opendir(PF_DTA* data, PF_DIR_ENT* entry, PF_ENT_ITER* iter
|
||||
}
|
||||
|
||||
pf_s32 PFDIR_p_fsexec(PF_DTA* data, pf_u32 flags, pf_u32 mode) {
|
||||
PF_ENT_ITER iter;
|
||||
PFDIR_FFD ffd;
|
||||
PFDIR_FAT_HINT hint;
|
||||
PF_ENT_ITER iter;
|
||||
PF_DIR_ENT entry;
|
||||
PFDIR_STR pattern;
|
||||
pf_u32 logical_position;
|
||||
@@ -1074,32 +1075,34 @@ pf_s32 PFDIR_p_fsexec(PF_DTA* data, pf_u32 flags, pf_u32 mode) {
|
||||
const pf_s8* name;
|
||||
pf_s32 error;
|
||||
|
||||
if ((flags & 0x26) == 0 && (flags & 1) == 0) {
|
||||
if ((flags & 6) == 0 && (flags & 1) == 0 && (flags & 0x10) == 0 && (flags & 0x20) == 0) {
|
||||
return 10;
|
||||
}
|
||||
if ((flags & 0x26) != 0 || (flags & 1) != 0 || ((flags & 0x10) != 0 && mode != 2)) {
|
||||
if ((flags & 6) != 0 || (flags & 1) != 0 || ((flags & 0x10) != 0 && mode != 2)) {
|
||||
error = PFVOL_CheckForWrite(data->p_vol);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
entry.start_cluster = data->parent_start_cluster;
|
||||
entry.check_sum = 0;
|
||||
PFFAT_InitFFD(&ffd, &hint, data->p_vol, &entry.start_cluster);
|
||||
iter.p_vol = data->p_vol;
|
||||
iter.ffd = ffd;
|
||||
start_position = data->parent_pos - 1;
|
||||
if ((flags & 0x80000000) == 0) {
|
||||
start_position -= data->num_entry_LFNs;
|
||||
}
|
||||
PFFAT_InitFFD(&ffd, &hint, data->p_vol, &data->parent_start_cluster);
|
||||
iter.p_vol = data->p_vol;
|
||||
iter.ffd = ffd;
|
||||
error = PFENT_ITER_IteratorInitialize(&iter, start_position);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if ((data->status & 1) != 0) {
|
||||
if ((data->status & 1) == 1) {
|
||||
code_mode = 1;
|
||||
name = data->FileName;
|
||||
} else {
|
||||
code_mode = 2;
|
||||
if ((VFipf_vol_set.setting & 2) != 0) {
|
||||
if ((pf_vol_set.setting & 2) != 0) {
|
||||
name = (const pf_s8*)((PF_DTAW*)data)->LongNameW;
|
||||
} else {
|
||||
name = (const pf_s8*)((PF_DTAW*)data)->FileNameW;
|
||||
@@ -1109,7 +1112,7 @@ pf_s32 PFDIR_p_fsexec(PF_DTA* data, pf_u32 flags, pf_u32 mode) {
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if ((VFipf_vol_set.setting & 2) != 0) {
|
||||
if ((pf_vol_set.setting & 2) != 0) {
|
||||
PFSTR_SetLocalStr(&pattern, (pf_u32)data->LongName);
|
||||
} else {
|
||||
PFSTR_SetLocalStr(&pattern, (pf_u32)data->FileName);
|
||||
@@ -1137,7 +1140,7 @@ pf_s32 PFDIR_p_fsexec(PF_DTA* data, pf_u32 flags, pf_u32 mode) {
|
||||
return error;
|
||||
}
|
||||
if ((flags & 6) != 0) {
|
||||
return PFDIR_p_fsexec_chmod(data, &entry, flags, mode);
|
||||
return PFDIR_p_fsexec_chmod(data, &entry, mode, flags);
|
||||
}
|
||||
if ((flags & 1) != 0) {
|
||||
return PFDIR_p_fsexec_remove(data, &entry, &iter);
|
||||
@@ -1316,7 +1319,7 @@ void PFDIR_opendir(PF_STR* path, PFDIR_DIR** dir) {
|
||||
pf_vol_set.last_error = error;
|
||||
((PFDIR_VOLUME_DIRS*)volume)->last_error = error;
|
||||
} else {
|
||||
((PFDIR_VOLUME_DIRS*)volume)->num_opened_directories++;
|
||||
((PFDIR_VOLUME_DIRS*)volume)->num_opened_directories += 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1507,9 +1510,15 @@ pf_s32 PFDIR_chdir(PF_STR* path) {
|
||||
if (error != 0) {
|
||||
pf_vol_set.last_error = error;
|
||||
((PFDIR_VOLUME_DIRS*)volume)->last_error = error;
|
||||
return error;
|
||||
} else {
|
||||
PFVOL_SetCurrentVolume(volume);
|
||||
}
|
||||
PFVOL_SetCurrentVolume(volume);
|
||||
return error;
|
||||
}
|
||||
|
||||
static inline pf_s32 set_directory_context(PF_VOLUME* volume, PF_DIR_ENT* entry) {
|
||||
pf_s32 error = PFVOL_SetCurrentDir(volume, entry);
|
||||
if (error != 0) { return error; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1528,14 +1537,14 @@ pf_s32 PFDIR_fchdir(PFDIR_DIR* dir) {
|
||||
((PFDIR_VOLUME_DIRS*)volume)->last_error = error;
|
||||
return error;
|
||||
}
|
||||
error = PFVOL_SetCurrentDir(volume, &dir->p_sdd->dir_entry);
|
||||
error = set_directory_context(volume, &dir->p_sdd->dir_entry);
|
||||
if (error != 0) {
|
||||
pf_vol_set.last_error = error;
|
||||
((PFDIR_VOLUME_DIRS*)volume)->last_error = error;
|
||||
return error;
|
||||
} else {
|
||||
PFVOL_SetCurrentVolume(volume);
|
||||
}
|
||||
PFVOL_SetCurrentVolume(volume);
|
||||
return 0;
|
||||
return error;
|
||||
}
|
||||
|
||||
void PFDIR_chmod(PF_STR* path, pf_u8 attributes) {
|
||||
@@ -1580,7 +1589,7 @@ void PFDIR_chdmod(PF_STR* path, pf_u8 attributes) {
|
||||
return;
|
||||
}
|
||||
volume_dirs->cache_signature = 0;
|
||||
error = PFDIR_p_chmod(volume, (PFDIR_STR*)path, attributes | 0x10);
|
||||
error = PFDIR_p_chmod(volume, (PFDIR_STR*)path, (pf_u8)(attributes | 0x10));
|
||||
if (error != 0) {
|
||||
pf_vol_set.last_error = error;
|
||||
((PFDIR_VOLUME_DIRS*)volume)->last_error = error;
|
||||
@@ -1608,7 +1617,7 @@ pf_s32 PFDIR_p_fsnext(PF_DTA* data) {
|
||||
pf_u32 logical_position = 0;
|
||||
pf_u32 entry_position = 0;
|
||||
pf_u32 code_mode;
|
||||
pf_u32 index;
|
||||
pf_s32 index = 0;
|
||||
pf_s32 error;
|
||||
|
||||
if ((data->status & 1) == 1) {
|
||||
@@ -1621,63 +1630,55 @@ pf_s32 PFDIR_p_fsnext(PF_DTA* data) {
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
PFSTR_SetLocalStr(&pattern, 0);
|
||||
if (entry_position < 0xF423F) {
|
||||
if (data->parent_pos > 0xF423E) {
|
||||
return 10;
|
||||
}
|
||||
ffd.start_cluster = data->parent_start_cluster;
|
||||
PFFAT_InitFFD(&ffd, &hint, data->p_vol, &ffd.start_cluster);
|
||||
PFSTR_SetLocalStr(&pattern, (pf_u32)data->reg_exp);
|
||||
while (entry_position < 999999) {
|
||||
if (data->parent_pos >= 999999) { return 10; }
|
||||
entry.start_cluster = data->parent_start_cluster;
|
||||
PFFAT_InitFFD(&ffd, &hint, data->p_vol, &entry.start_cluster);
|
||||
error = PFENT_findEntryPos(&ffd, &entry, data->parent_pos, &pattern, data->attr, 0,
|
||||
&logical_position, &entry_position);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if (error != 0) { return error; }
|
||||
data->parent_pos = entry_position + 1;
|
||||
if (entry_position == 0xF423F) {
|
||||
return 3;
|
||||
}
|
||||
if (entry_position == 999999) { return 3; }
|
||||
}
|
||||
pf_strcpy(data->FileName, entry.short_name);
|
||||
if ((data->status & 2) == 2) {
|
||||
PFPATH_transformInUnicode(((PF_DTAW*)data)->FileNameW, data->FileName);
|
||||
}
|
||||
if (entry.long_name[0] == 0) {
|
||||
data->LongName[0] = 0;
|
||||
if ((data->status & 2) == 2) {
|
||||
((PF_DTAW*)data)->LongNameW[0] = 0;
|
||||
}
|
||||
} else {
|
||||
if ((VFipf_vol_set.setting & 2) == 2) {
|
||||
VFipf_vol_set.setting &= 0xFFFFFFFC;
|
||||
VFipf_vol_set.setting |= 1;
|
||||
if (entry.long_name[0] != 0) {
|
||||
if ((pf_vol_set.setting & 2) == 2) {
|
||||
pf_vol_set.setting &= 0xFFFFFFFC;
|
||||
pf_vol_set.setting |= 1;
|
||||
PFPATH_transformFromUnicodeToNormal(data->LongName, entry.long_name);
|
||||
VFipf_vol_set.setting &= 0xFFFFFFFC;
|
||||
VFipf_vol_set.setting |= 2;
|
||||
pf_vol_set.setting &= 0xFFFFFFFC;
|
||||
pf_vol_set.setting |= 2;
|
||||
} else {
|
||||
PFPATH_transformFromUnicodeToNormal(data->LongName, entry.long_name);
|
||||
}
|
||||
if ((data->status & 2) == 2) {
|
||||
pf_w_strcpy(((PF_DTAW*)data)->LongNameW, entry.long_name);
|
||||
}
|
||||
} else {
|
||||
data->LongName[0] = 0;
|
||||
if ((data->status & 2) == 2) {
|
||||
((PF_DTAW*)data)->LongNameW[0] = 0;
|
||||
}
|
||||
}
|
||||
if (((PFDIR_VOLUME_DIRS*)data->p_vol)->num_opened_files != 0) {
|
||||
PFDIR_SFD* sfd = ((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds;
|
||||
for (index = 0; index < 5; index++) {
|
||||
if ((sfd->stat & 1) != 0 && (sfd->stat & 2) != 0 &&
|
||||
sfd->dir_entry.p_vol == entry.p_vol &&
|
||||
sfd->dir_entry.entry_sector == entry.entry_sector &&
|
||||
sfd->dir_entry.entry_offset == entry.entry_offset) {
|
||||
data->FileSize = sfd->dir_entry.file_size;
|
||||
data->Time = sfd->dir_entry.modify_time;
|
||||
data->Date = sfd->dir_entry.modify_date;
|
||||
data->Attribute = sfd->dir_entry.attr;
|
||||
data->num_entry_LFNs = sfd->dir_entry.num_entry_LFNs;
|
||||
data->ordinal = sfd->dir_entry.ordinal;
|
||||
data->check_sum = sfd->dir_entry.check_sum;
|
||||
if ((((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds[index].stat & 1) != 0 && (((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds[index].stat & 2) != 0 &&
|
||||
entry.p_vol == ((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds[index].dir_entry.p_vol &&
|
||||
((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds[index].dir_entry.entry_sector == entry.entry_sector &&
|
||||
((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds[index].dir_entry.entry_offset == entry.entry_offset) {
|
||||
data->FileSize = ((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds[index].dir_entry.file_size;
|
||||
data->Time = ((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds[index].dir_entry.modify_time;
|
||||
data->Date = ((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds[index].dir_entry.modify_date;
|
||||
data->Attribute = ((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds[index].dir_entry.attr;
|
||||
data->num_entry_LFNs = ((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds[index].dir_entry.num_entry_LFNs;
|
||||
data->ordinal = ((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds[index].dir_entry.ordinal;
|
||||
data->check_sum = ((PFDIR_VOLUME_DIRS*)data->p_vol)->sfds[index].dir_entry.check_sum;
|
||||
break;
|
||||
}
|
||||
sfd++;
|
||||
}
|
||||
}
|
||||
if (((PFDIR_VOLUME_DIRS*)data->p_vol)->num_opened_files == 0 || index == 5) {
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -358,8 +358,8 @@ s32 PFFAT_FindClusterLink(PFFAT_FFD* file, u32 chainIndex, u32* cluster,
|
||||
u32 nextCluster;
|
||||
s32 error;
|
||||
|
||||
*found = 0;
|
||||
nextCluster = -1;
|
||||
*found = 0;
|
||||
if (file->cluster_link.position == 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -388,6 +388,7 @@ s32 PFFAT_FindClusterLink(PFFAT_FFD* file, u32 chainIndex, u32* cluster,
|
||||
&nextCluster);
|
||||
break;
|
||||
default:
|
||||
nextCluster = -1;
|
||||
error = 15;
|
||||
break;
|
||||
}
|
||||
@@ -486,6 +487,7 @@ s32 PFFAT_ReadCluster(PFFAT_FFD* file, u32 cluster, u32 chainIndex,
|
||||
u32* nextCluster, u32* checkClusterLink)
|
||||
{
|
||||
s32 error;
|
||||
u32 value;
|
||||
|
||||
*nextCluster = -1;
|
||||
if (file->cluster_link.buffer != 0 && *checkClusterLink == 1) {
|
||||
@@ -515,22 +517,22 @@ s32 PFFAT_ReadCluster(PFFAT_FFD* file, u32 cluster, u32 chainIndex,
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if (*nextCluster == 0) {
|
||||
value = *nextCluster;
|
||||
if (value == 0) {
|
||||
return 13;
|
||||
}
|
||||
if (*nextCluster == -1) {
|
||||
if (value == -1) {
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
if (file->cluster_link.buffer != 0 &&
|
||||
*nextCluster != fat_special_values[file->p_vol->bpb.fat_type].eoc2) {
|
||||
if (file->cluster_link.buffer != 0 &&
|
||||
value != fat_special_values[file->p_vol->bpb.fat_type].eoc2) {
|
||||
if (file->cluster_link.max_count > file->cluster_link.position &&
|
||||
file->cluster_link.max_count != 0) {
|
||||
if (chainIndex == file->cluster_link.position *
|
||||
(file->cluster_link.interval + 1)) {
|
||||
file->cluster_link.interval_offset = 0;
|
||||
file->cluster_link.buffer[file->cluster_link.position] =
|
||||
*nextCluster;
|
||||
value;
|
||||
file->cluster_link.position++;
|
||||
} else {
|
||||
file->cluster_link.interval_offset++;
|
||||
@@ -538,6 +540,7 @@ s32 PFFAT_ReadCluster(PFFAT_FFD* file, u32 cluster, u32 chainIndex,
|
||||
file->cluster_link.save_index = chainIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -546,6 +549,7 @@ s32 PFFAT_ReadClusterWithBuf(PFFAT_FFD* file, u32 cluster, u32 chainIndex,
|
||||
PF_CACHE_PAGE* page)
|
||||
{
|
||||
s32 error;
|
||||
u32 value;
|
||||
|
||||
*nextCluster = -1;
|
||||
if (file->cluster_link.buffer != 0 && *checkClusterLink == 1) {
|
||||
@@ -576,22 +580,22 @@ s32 PFFAT_ReadClusterWithBuf(PFFAT_FFD* file, u32 cluster, u32 chainIndex,
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if (*nextCluster == 0) {
|
||||
value = *nextCluster;
|
||||
if (value == 0) {
|
||||
return 13;
|
||||
}
|
||||
if (*nextCluster == -1) {
|
||||
if (value == -1) {
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
if (file->cluster_link.buffer != 0 &&
|
||||
*nextCluster != fat_special_values[file->p_vol->bpb.fat_type].eoc2) {
|
||||
if (file->cluster_link.buffer != 0 &&
|
||||
value != fat_special_values[file->p_vol->bpb.fat_type].eoc2) {
|
||||
if (file->cluster_link.max_count > file->cluster_link.position &&
|
||||
file->cluster_link.max_count != 0) {
|
||||
if (chainIndex == file->cluster_link.position *
|
||||
(file->cluster_link.interval + 1)) {
|
||||
file->cluster_link.interval_offset = 0;
|
||||
file->cluster_link.buffer[file->cluster_link.position] =
|
||||
*nextCluster;
|
||||
value;
|
||||
file->cluster_link.position++;
|
||||
} else {
|
||||
file->cluster_link.interval_offset++;
|
||||
@@ -599,6 +603,7 @@ s32 PFFAT_ReadClusterWithBuf(PFFAT_FFD* file, u32 cluster, u32 chainIndex,
|
||||
file->cluster_link.save_index = chainIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -608,6 +613,7 @@ s32 PFFAT_WriteCluster(PFFAT_FFD* file, u32 cluster, u32 chainIndex,
|
||||
u32 accessCluster;
|
||||
u32 position;
|
||||
u32 divisor;
|
||||
u32* linkBuffer;
|
||||
u32 precedingIndex;
|
||||
s32 error;
|
||||
|
||||
@@ -641,14 +647,15 @@ s32 PFFAT_WriteCluster(PFFAT_FFD* file, u32 cluster, u32 chainIndex,
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if (file->cluster_link.buffer != 0 && useClusterLink == 1) {
|
||||
linkBuffer = file->cluster_link.buffer;
|
||||
if (linkBuffer != 0 && useClusterLink == 1) {
|
||||
if (nextCluster == 0) {
|
||||
divisor = file->cluster_link.interval + 1;
|
||||
position = chainIndex / divisor;
|
||||
|
||||
if (file->cluster_link.max_count >= position) {
|
||||
if (chainIndex % divisor == 0) {
|
||||
file->cluster_link.buffer[position] = 0;
|
||||
linkBuffer[position] = 0;
|
||||
}
|
||||
if (file->cluster_link.save_index >= chainIndex) {
|
||||
precedingIndex = chainIndex - 1;
|
||||
@@ -694,6 +701,7 @@ s32 PFFAT_WriteClusterWithBuf(PFFAT_FFD* file, u32 cluster, u32 chainIndex,
|
||||
u32 accessCluster;
|
||||
u32 position;
|
||||
u32 divisor;
|
||||
u32* linkBuffer;
|
||||
u32 precedingIndex;
|
||||
s32 error;
|
||||
|
||||
@@ -729,14 +737,15 @@ s32 PFFAT_WriteClusterWithBuf(PFFAT_FFD* file, u32 cluster, u32 chainIndex,
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
if (file->cluster_link.buffer != 0 && useClusterLink == 1) {
|
||||
linkBuffer = file->cluster_link.buffer;
|
||||
if (linkBuffer != 0 && useClusterLink == 1) {
|
||||
if (nextCluster == 0) {
|
||||
divisor = file->cluster_link.interval + 1;
|
||||
position = chainIndex / divisor;
|
||||
|
||||
if (file->cluster_link.max_count >= position) {
|
||||
if (chainIndex % divisor == 0) {
|
||||
file->cluster_link.buffer[position] = 0;
|
||||
linkBuffer[position] = 0;
|
||||
}
|
||||
if (file->cluster_link.save_index >= chainIndex) {
|
||||
precedingIndex = chainIndex - 1;
|
||||
@@ -1108,14 +1117,25 @@ s32 PFFAT_GetClusterAllocatedInChain(PFFAT_FFD* file, u32 initialCluster,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline s32 find_cluster_in_chain(PFFAT_FFD* file, u32 index, u32 mode, u32 count, u32 useFirst, u32* cluster) {
|
||||
u32 firstCluster;
|
||||
u32 lastCluster;
|
||||
u32 candidate;
|
||||
s32 error = PFFAT_GetClusterInChain(file, index, mode, count, &firstCluster, &lastCluster);
|
||||
if (error != 0) { return error; }
|
||||
candidate = useFirst ? firstCluster : lastCluster;
|
||||
if (candidate >= 2 && candidate < file->p_vol->bpb.num_clusters + 2) { *cluster = candidate; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
s32 PFFAT_GetClusterSpecified(PFFAT_FFD* file, u32 chainIndex,
|
||||
u32 mayAllocate, u32* cluster)
|
||||
{
|
||||
PFFAT_HINT* hint;
|
||||
u32 fatType;
|
||||
u32 found;
|
||||
u32 locateEnd;
|
||||
u32 locateStart;
|
||||
u32 locateEnd;
|
||||
s32 error;
|
||||
|
||||
fatType = file->p_vol->bpb.fat_type;
|
||||
@@ -1144,20 +1164,7 @@ s32 PFFAT_GetClusterSpecified(PFFAT_FFD* file, u32 chainIndex,
|
||||
}
|
||||
}
|
||||
*cluster = -1;
|
||||
error = PFFAT_GetClusterInChain(file, chainIndex, mayAllocate != 0, 0,
|
||||
&locateStart, &locateEnd);
|
||||
if (error == 0) {
|
||||
goto cluster_lookup_succeeded;
|
||||
}
|
||||
goto cluster_lookup_complete;
|
||||
|
||||
cluster_lookup_succeeded:
|
||||
if (locateEnd >= 2 && locateEnd < file->p_vol->bpb.num_clusters + 2) {
|
||||
*cluster = locateEnd;
|
||||
}
|
||||
error = 0;
|
||||
|
||||
cluster_lookup_complete:
|
||||
error = find_cluster_in_chain(file, chainIndex, mayAllocate != 0, 0, 0, cluster);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
@@ -1173,10 +1180,10 @@ cluster_lookup_complete:
|
||||
s32 PFFAT_GetClusterAllocated(PFFAT_FFD* file, u32 chainIndex,
|
||||
u32 numClusters, u32* cluster)
|
||||
{
|
||||
u32 fatType;
|
||||
PFFAT_HINT* hint;
|
||||
u32 locateEnd;
|
||||
u32 fatType;
|
||||
u32 locateStart;
|
||||
u32 locateEnd;
|
||||
s32 error;
|
||||
|
||||
fatType = file->p_vol->bpb.fat_type;
|
||||
@@ -1189,15 +1196,7 @@ s32 PFFAT_GetClusterAllocated(PFFAT_FFD* file, u32 chainIndex,
|
||||
*file->p_start_cluster = file->p_vol->bpb.root_dir_cluster;
|
||||
}
|
||||
*cluster = -1;
|
||||
error = PFFAT_GetClusterInChain(file, chainIndex, 2, numClusters,
|
||||
&locateStart, &locateEnd);
|
||||
if (error == 0) {
|
||||
if (locateStart >= 2 &&
|
||||
locateStart < file->p_vol->bpb.num_clusters + 2) {
|
||||
*cluster = locateStart;
|
||||
}
|
||||
error = 0;
|
||||
}
|
||||
error = find_cluster_in_chain(file, chainIndex, 2, numClusters, 1, cluster);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
}
|
||||
@@ -1225,17 +1224,18 @@ s32 PFFAT_GetSector(PFFAT_FFD* file, u32 fileSectorIndex, u32 mode,
|
||||
u32 size, u32* sector)
|
||||
{
|
||||
PF_VOLUME* volume;
|
||||
u32 fatType;
|
||||
u32 chainIndex;
|
||||
u32 cluster;
|
||||
u32 numDivide;
|
||||
u32 numRemainder;
|
||||
u32 numSectors;
|
||||
u32 numDivide;
|
||||
u32 numClusters;
|
||||
u32 numSectors;
|
||||
s32 error;
|
||||
|
||||
volume = file->p_vol;
|
||||
if (*file->p_start_cluster == 1 &&
|
||||
(u32)volume->bpb.fat_type <= FAT_16) {
|
||||
fatType = volume->bpb.fat_type;
|
||||
if (*file->p_start_cluster == 1 && fatType <= FAT_16) {
|
||||
error = PFFAT_GetSectorInRootDirRegion(volume, fileSectorIndex, sector);
|
||||
if (error != 0) {
|
||||
return error;
|
||||
@@ -1244,13 +1244,12 @@ s32 PFFAT_GetSector(PFFAT_FFD* file, u32 fileSectorIndex, u32 mode,
|
||||
}
|
||||
chainIndex = fileSectorIndex >> volume->bpb.log2_sectors_per_cluster;
|
||||
if (mode == 2) {
|
||||
numDivide = size / volume->bpb.bytes_per_sector;
|
||||
numRemainder = (size % volume->bpb.bytes_per_sector) != 0;
|
||||
numSectors = numDivide + numRemainder;
|
||||
numSectors = (size / volume->bpb.bytes_per_sector) +
|
||||
((size % volume->bpb.bytes_per_sector) != 0);
|
||||
numDivide = numSectors / volume->bpb.sectors_per_cluster;
|
||||
numRemainder =
|
||||
(numSectors % volume->bpb.sectors_per_cluster) != 0;
|
||||
numClusters = numDivide + numRemainder;
|
||||
numClusters = numRemainder + numDivide;
|
||||
error = PFFAT_GetClusterAllocated(file, chainIndex, numClusters,
|
||||
&cluster);
|
||||
if (error != 0) {
|
||||
@@ -1375,7 +1374,8 @@ s32 PFFAT_CountAllocatedClusters(PFFAT_FFD* file, u32 size,
|
||||
*numAllocatedClusters = file->p_hint->chain_index;
|
||||
cluster = file->p_hint->cluster;
|
||||
chainIndex = file->p_hint->chain_index + 1;
|
||||
size -= file->p_hint->chain_index * bytesPerCluster;
|
||||
size -= file->p_hint->chain_index *
|
||||
(file->p_vol->bpb.bytes_per_sector * file->p_vol->bpb.sectors_per_cluster);
|
||||
} else {
|
||||
cluster = *file->p_start_cluster;
|
||||
chainIndex = 1;
|
||||
@@ -1520,9 +1520,9 @@ s32 PFFAT_FreeChain(PFFAT_FFD* file, u32 startCluster, u32 chainIndex,
|
||||
}
|
||||
if (nextCluster == 0) {
|
||||
s32 firstFlushError;
|
||||
u32 fatSector;
|
||||
u16 fatIndex;
|
||||
PF_CACHE_PAGE* flushPage;
|
||||
u16 fatIndex;
|
||||
u32 fatSector;
|
||||
|
||||
firstFlushError = 0;
|
||||
flushPage = page;
|
||||
@@ -1857,7 +1857,8 @@ s32 PFFAT_RefreshFSINFO(PF_VOLUME* volume)
|
||||
if ((volume->fsi_flag & 4) != 0) {
|
||||
error = PFCACHE_AllocateDataPage(volume, -1, &page,
|
||||
&alreadyAllocated);
|
||||
if (error == 0) {
|
||||
if (error != 0) { goto finished; }
|
||||
{
|
||||
error = PFSEC_ReadData(
|
||||
volume, page->p_buf, volume->bpb.fs_info_sector, 0,
|
||||
volume->bpb.bytes_per_sector, &completedBytes, 0);
|
||||
@@ -1896,6 +1897,7 @@ s32 PFFAT_RefreshFSINFO(PF_VOLUME* volume)
|
||||
PFCACHE_FreeDataPage(volume, page);
|
||||
}
|
||||
}
|
||||
finished:
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
#define PF_FA_STR_LAYOUT
|
||||
#include <private/vf/PrFILE2/fatfs/pf_volume.h>
|
||||
#include <private/vf/PrFILE2/fatfs/pf_dir.h>
|
||||
#include <private/vf/PrFILE2/fatfs/pf_path.h>
|
||||
@@ -414,16 +415,24 @@ pf_s32 PFFILE_Cursor_Read(PFFILE_FILE* file, pf_u8* buffer, pf_u32 size, pf_u32*
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void advance_write_cursor(PFFILE_FILE* file, pf_u32 size, pf_u32 sector) {
|
||||
PF_VOLUME* volume = file == PF_NULL ? PF_NULL : file->p_sfd->dir_entry.p_vol;
|
||||
pf_u32 position = file->cursor.offset_in_sector + size;
|
||||
pf_u32 next_sector = sector + (position >> volume->bpb.log2_bytes_per_sector);
|
||||
if (((volume->bpb.bytes_per_sector - 1) & position) != 0) { file->cursor.sector = next_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, next_sector);
|
||||
}
|
||||
|
||||
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 +461,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);
|
||||
advance_write_cursor(file, success_size, file->cursor.sector);
|
||||
if (success_size != size) {
|
||||
return error;
|
||||
}
|
||||
@@ -481,7 +473,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 +497,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);
|
||||
advance_write_cursor(file, success_size, file->cursor.sector);
|
||||
if (success_size != size - (size & (volume->bpb.bytes_per_sector - 1))) {
|
||||
return error;
|
||||
}
|
||||
@@ -528,12 +508,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 +537,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);
|
||||
advance_write_cursor(file, success_size, file->cursor.sector);
|
||||
if (success_size != size) {
|
||||
return error;
|
||||
}
|
||||
@@ -697,15 +654,16 @@ PFFILE_SFD* PFFILE_GetSFD(PF_VOLUME* volume, PF_DIR_ENT* entry) {
|
||||
pf_u32 index = 0;
|
||||
|
||||
for (; index < 5; index++, sfd++) {
|
||||
if ((sfd->stat & 1) == 0 || (sfd->stat & 2) == 0) {
|
||||
if ((volume_dirs->sfds[index].stat & 1) == 0 ||
|
||||
((volume_dirs->sfds[index].stat & 1) != 0 && (!volume_dirs->sfds[index].stat & 2) != 0)) {
|
||||
if (first_free_sfd == PF_NULL) {
|
||||
first_free_sfd = sfd;
|
||||
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;
|
||||
} else 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];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -744,22 +702,23 @@ PFFILE_SFD* PFFILE_GetSFD(PF_VOLUME* volume, PF_DIR_ENT* entry) {
|
||||
pf_s32 PFFILE_createEmptyFile(PF_VOLUME* volume, PF_DIR_ENT* entry, PF_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* previous_sector;
|
||||
pf_u32 success_size;
|
||||
pf_u32 entry_position;
|
||||
pf_u32 num_chars;
|
||||
pf_u32 num_entries;
|
||||
pf_s32 num_chars;
|
||||
pf_u8 num_entries;
|
||||
pf_u8 checksum;
|
||||
pf_u32 ordinal;
|
||||
pf_u32 sector;
|
||||
pf_u32 success_size;
|
||||
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) {
|
||||
return 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);
|
||||
if (((PFFILE_VOLUME_DIRS*)volume)->num_opened_files >= 5) {
|
||||
return 0x15;
|
||||
@@ -768,9 +727,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 +737,11 @@ 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;
|
||||
}
|
||||
entry->start_cluster = volume->bpb.fat_type == FAT_32 ? 1 : 0;
|
||||
if (volume->bpb.fat_type == FAT_32) { entry->start_cluster = 1; }
|
||||
else { entry->start_cluster = 0; }
|
||||
entry->file_size = 0;
|
||||
entry->p_vol = volume;
|
||||
entry->small_letter_flag = 0;
|
||||
@@ -798,14 +758,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 = 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 +779,7 @@ 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++;
|
||||
}
|
||||
}
|
||||
entry->entry_sector = sector;
|
||||
@@ -834,14 +795,25 @@ pf_s32 PFFILE_createEmptyFile(PF_VOLUME* volume, PF_DIR_ENT* entry, PF_STR* file
|
||||
return PFENT_updateEntry(entry, 1);
|
||||
}
|
||||
|
||||
static inline pf_u32 file_is_open(PF_DIR_ENT* entry) {
|
||||
pf_s32 index;
|
||||
for (index = 0; index < 5; index++) {
|
||||
PFFILE_SFD* sfd = &((PFFILE_VOLUME_DIRS*)entry->p_vol)->sfds[index];
|
||||
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 1; }
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
pf_s32 PFFILE_p_remove(PF_VOLUME* volume, PF_STR* path) {
|
||||
PF_STR directory;
|
||||
PF_STR filename;
|
||||
PF_DIR_ENT entry;
|
||||
PFFILE_ENT_ITER iter;
|
||||
PFFILE_VOLUME_DIRS* volume_dirs = (PFFILE_VOLUME_DIRS*)volume;
|
||||
pf_s32 error;
|
||||
pf_u32 index;
|
||||
PFFILE_FAT_HINT hint;
|
||||
pf_u32 start_cluster;
|
||||
|
||||
error = PFPATH_SplitPath(path, &directory, &filename);
|
||||
if (error != 0) {
|
||||
@@ -851,39 +823,34 @@ 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;
|
||||
}
|
||||
}
|
||||
if (file_is_open(&entry) != 0) { 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);
|
||||
}
|
||||
|
||||
static PFFILE_FILE* PFFILE_GetFreeUFD(PF_VOLUME* volume);
|
||||
|
||||
pf_s32 PFFILE_p_fopen(PF_VOLUME* volume, PF_STR* path, pf_u32 open_mode,
|
||||
PFFILE_FILE** result) {
|
||||
PF_STR directory;
|
||||
PF_STR filename;
|
||||
PF_STR directory;
|
||||
PF_DIR_ENT entry;
|
||||
PFFILE_ENT_ITER iter;
|
||||
PFFILE_FFD ffd;
|
||||
PF_FAT_HINT hint;
|
||||
PFFILE_FAT_HINT hint;
|
||||
PFFILE_SFD* sfd;
|
||||
PFFILE_FILE* file;
|
||||
pf_s8 normalized_filename[0x200];
|
||||
pf_u32 num_chars;
|
||||
pf_u32 index;
|
||||
pf_u32 success_size;
|
||||
pf_s32 num_chars;
|
||||
pf_u16 access_time;
|
||||
pf_s32 error;
|
||||
|
||||
@@ -908,49 +875,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,37 +888,61 @@ 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) {
|
||||
if (file_is_open(&entry) != 0) { 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);
|
||||
if (sfd == PF_NULL) {
|
||||
return 0x15;
|
||||
}
|
||||
file = PF_NULL;
|
||||
for (index = 0; index < 5; index++) {
|
||||
if ((((PFFILE_VOLUME_DIRS*)volume)->ufds[index].stat & 1) == 0) {
|
||||
file = &((PFFILE_VOLUME_DIRS*)volume)->ufds[index];
|
||||
break;
|
||||
}
|
||||
}
|
||||
file = PFFILE_GetFreeUFD(volume);
|
||||
if (file == PF_NULL) {
|
||||
return 0x16;
|
||||
}
|
||||
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++;
|
||||
@@ -1002,7 +951,26 @@ pf_s32 PFFILE_p_fopen(PF_VOLUME* volume, PF_STR* path, pf_u32 open_mode,
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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 +996,30 @@ 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;
|
||||
}
|
||||
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) {
|
||||
@@ -1126,10 +1092,8 @@ pf_s32 PFFILE_p_combine(PF_VOLUME* volume, PF_STR* first_path, PF_STR* second_pa
|
||||
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;
|
||||
pf_u32 index;
|
||||
pf_s32 found;
|
||||
PFFILE_FAT_HINT first_hint;
|
||||
PFFILE_FAT_HINT second_hint;
|
||||
pf_s32 error;
|
||||
|
||||
error = PFENT_ITER_GetEntryOfPath(&first_iter, &first_entry, volume, first_path, 0);
|
||||
@@ -1146,41 +1110,12 @@ 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) {
|
||||
return 0x13;
|
||||
}
|
||||
if (file_is_open(&first_entry) != 0 || file_is_open(&second_entry) != 0) { 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);
|
||||
@@ -1204,24 +1139,20 @@ pf_s32 PFFILE_p_combine(PF_VOLUME* volume, PF_STR* first_path, PF_STR* second_pa
|
||||
|
||||
pf_s32 PFFILE_p_divide(PF_VOLUME* volume, PF_STR* source_path, PF_STR* destination_path,
|
||||
pf_u32 split_size) {
|
||||
PF_STR destination_directory;
|
||||
PF_STR destination_filename;
|
||||
PF_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 error;
|
||||
pf_s32 divide_error;
|
||||
|
||||
error = PFENT_ITER_GetEntryOfPath(&source_iter, &source_entry, volume, source_path, 0);
|
||||
if (error != 0) {
|
||||
@@ -1233,17 +1164,7 @@ 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 (file_is_open(&source_entry) != 0) { return 0x13; }
|
||||
if (source_entry.file_size == 0) {
|
||||
return 0xA;
|
||||
}
|
||||
@@ -1255,7 +1176,7 @@ 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) {
|
||||
if ((pf_s32)(PFSTR_StrNumChar(&destination_filename, 1) & 0xFFFF) > 0xFF) {
|
||||
return 1;
|
||||
}
|
||||
PFPATH_transformFromUnicodeToNormal(
|
||||
@@ -1274,13 +1195,13 @@ 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,32 +1209,30 @@ 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);
|
||||
divide_error = error;
|
||||
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 divide_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,
|
||||
@@ -1403,20 +1322,15 @@ 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 ((mode & 1) != 0) {
|
||||
if ((file->p_sfd->lock.mode & 2) != 0) {
|
||||
return 0x27;
|
||||
}
|
||||
} else if ((mode & 2) != 0 && (file->p_sfd->lock.mode & 1) != 0) {
|
||||
return 0x27;
|
||||
}
|
||||
if (file->p_sfd->lock.owner != 0 && file->p_sfd->lock.owner != (PF_FILE*)file) {
|
||||
if ((file->p_sfd->lock.mode & 3) != 0 && (mode & 8) != 0) {
|
||||
if (((mode & 1) != 0 && (file->p_sfd->lock.mode & 2) != 0) ||
|
||||
((mode & 2) != 0 && (file->p_sfd->lock.mode & 1) != 0) ||
|
||||
(file->p_sfd->lock.owner != 0 && file->p_sfd->lock.owner != (PF_FILE*)file)) {
|
||||
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,7 +1346,7 @@ pf_s32 PFFILE_p_flock(PFFILE_FILE* file, pf_u32 mode) {
|
||||
}
|
||||
file->p_sfd->lock.count++;
|
||||
file->lock_count++;
|
||||
return 0;
|
||||
goto complete;
|
||||
}
|
||||
if (file->lock_count == 0 || file->p_sfd->lock.count == 0) {
|
||||
return 0x27;
|
||||
@@ -1440,23 +1354,14 @@ pf_s32 PFFILE_p_flock(PFFILE_FILE* file, pf_u32 mode) {
|
||||
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) {
|
||||
return 0x27;
|
||||
}
|
||||
file->p_sfd->lock.count = 0;
|
||||
file->lock_count = 0;
|
||||
file->p_sfd->lock.owner = 0;
|
||||
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;
|
||||
}
|
||||
complete:
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1708,10 +1613,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_s32 error;
|
||||
pf_u32 completed_count;
|
||||
|
||||
*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 +1631,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, &completed_count);
|
||||
*count_read = completed_count;
|
||||
((PFFILE_VOLUME_DIRS*)volume)->cache_signature = PF_NULL;
|
||||
if (error != 0) {
|
||||
pf_vol_set.last_error = error;
|
||||
@@ -1869,8 +1777,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) {
|
||||
@@ -2217,25 +2125,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;
|
||||
}
|
||||
10
libs/RVL_SDK/src/fa/pf_mount.c
Normal file
10
libs/RVL_SDK/src/fa/pf_mount.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <private/vf/PrFILE2/pf_types.h>
|
||||
|
||||
extern pf_s32 PFVOL_mount(pf_s8 drv_char);
|
||||
extern pf_s32 PFAPI_convertReturnValue(pf_s32 err);
|
||||
|
||||
pf_int32 pf2_mount(pf_ch8 drive) {
|
||||
pf_s32 err = PFVOL_mount(drive);
|
||||
err = PFAPI_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;
|
||||
}
|
||||
29
libs/RVL_SDK/src/fa/pf_rename.c
Normal file
29
libs/RVL_SDK/src/fa/pf_rename.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#define PF_FA_STR_LAYOUT
|
||||
#include <private/vf/PrFILE2/pf_types.h>
|
||||
#include <private/vf/PrFILE2/common/pf_str.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;
|
||||
|
||||
extern pf_s32 PFSTR_InitStr(PF_STR* p_str, const pf_s8* s, pf_u32 code_mode);
|
||||
extern pf_s32 PFDIR_rename(PF_STR* old_path, PF_STR* new_path);
|
||||
extern pf_s32 PFAPI_convertReturnValue(pf_s32 err);
|
||||
|
||||
pf_int32 pf2_rename(const pf_ch8* oldPath, const pf_ch8* newPath) {
|
||||
pf_s32 err;
|
||||
PF_STR old_str;
|
||||
PF_STR new_str;
|
||||
|
||||
err = PFSTR_InitStr(&old_str, (pf_s8*)oldPath, 1U);
|
||||
err |= PFSTR_InitStr(&new_str, (pf_s8*)newPath, 1U);
|
||||
if (err == 0) {
|
||||
err = PFDIR_rename(&old_str, &new_str);
|
||||
} else {
|
||||
pf_vol_set.last_error = err;
|
||||
}
|
||||
err = PFAPI_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;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user