Compare commits

...

255 Commits

Author SHA1 Message Date
coah
9b8d11475d cleanup(Controller): name Base/Classic status and pinch fields
- unk_0x08 → mDecideHoldCount (decide() when == 5)
- unk_0x1C → mbForceInvalid (setForceInvalid)
- unk_0x1D/1E → mbPinch/mbPrevPinch (A+B pinch state)
- unk_0x20 → mpStatus
- Classic unk_0x24/2C → mClassicCursor/mClassicCursorTimer

Also update ControllerManager ctor that touches Base fields.

Verified: Controller/ControllerManager 100%/100%, build/43U/ok,
DOL sha1 26116613f624061ba99c8d1a299aaa6efa85670d
2026-10-02 14:18:39 -05:00
coah
413c779180 cleanup(eZiText): rename work unk_0x0A to maxWordLength (#886)
Copied to/from options->maxWordLength; assigned from length.
2026-10-02 14:18:33 -05:00
coah
f9ecefa6a2 cleanup(NWC24Work): rename MBox header/entry work buffers (#883)
sendMbcHeader/recvMbcHeader/mbcEntry for cached MBC structures.
2026-10-02 14:17:06 -05:00
coah
320700d49b cleanup(eZiText): rename work unk_0x141E to graphTableId (#882)
Passed to Zi8GetTableAddress / Zi8GetTableSize (often 0x10).
2026-10-02 14:16:39 -05:00
coah
c52153e9f7 cleanup(eZiText): rename work unk_0x141A to capacity (#880)
Copied into options.capacity in zi8getc2; init to 0x100.
2026-10-02 14:15:52 -05:00
coah
899438ff02 cleanup(NWC24MsgObj): rename unk_0xD0 to extraData (#879)
Written by WriteExtraFields during commit.
2026-10-02 14:15:25 -05:00
coah
8476c93f00 cleanup(eZiText): rename work unk_0x17EA to matchOffset (#878)
Offset into match elements / result buffer during Zi8MatchROMdata1.
2026-10-02 14:14:57 -05:00
coah
9b375e1e50 cleanup(eZiText): rename work unk_0x1764 to groupPtr (#876)
Cursor into DAWG group table (from group / Zi8GetTableAddress).
2026-10-02 14:14:04 -05:00
coah
73795cb3fb cleanup(ErrorHandler): name set() arg storage fields (#875)
Rename unused debug-ish stash fields to match ErrorHandler::set params:
- unk_0x14 → mArg1 (char[4] from arg1)
- unk_0x0C → mArg2
- unk_0x10 → mArg3

Verified: ErrorHandler 100%/100%, build/43U/ok, DOL sha1
26116613f624061ba99c8d1a299aaa6efa85670d
2026-10-02 14:11:44 -05:00
coah
0c780f6d1f cleanup(eZiText): rename work unk_0x1418 to formatCount (#874)
Count of entries filled into formats[]; saved as savedCount.
2026-10-02 14:11:17 -05:00
coah
63f4c7aeab cleanup(NWC24MsgObj): rename flags to headerSize (#873)
Same 0x10 slot as MsgRead headerSize; Commit stamps body offset.
2026-10-02 14:10:50 -05:00
coah
282ddd99b7 cleanup(iplSettingButton): rename Unk ring-buffer placeholders (#872)
Unk -> CmdEntry; unk_0x64 -> mCmdQueue; capacity/count/read/write
indices. Byte-identical (DOL sha1 unchanged).
2026-10-02 14:10:24 -05:00
coah
c7d0f8f01b cleanup(CDBRecordFile): rename unk_0x1C to allocFlag (#871)
Stores CDB_RECORD_ALLOC_* from CDBRecordInstanceInit type arg.
2026-10-02 14:09:58 -05:00
coah
414b553743 cleanup(iplNwc24Manager): name receiving / title-table flags (#870)
unk_0xA31 -> mbReceiving
unk_0xA33 -> mbNewTitleTblReady
isUnk0xA31 -> isReceivingIdle (same == false semantics)

Touched channelTitle / sdChannelTitle / iplResetHandler callers for the getter rename.

Matching units 100% before/after; DOL sha1 unchanged.
2026-10-02 14:09:31 -05:00
coah
da96c27969 cleanup(NWC24MsgObj): rename unk_0x30/38 to fromData/toData (#868)
MIME From/To address spans used by WriteFromField/WriteToField and ReadMsgFromAddr.
2026-10-02 14:08:59 -05:00
coah
0a925c7053 cleanup(iplUrlProcessor): rename collision and processor placeholders (#865)
line_collision: unk_0x00/04/08 -> mLeft/mRight/mY
url_collision: unk_0x00/04/08 -> mTagNo/mpStart/mpEnd
UrlProcessor: unk_0x40..53 -> mHitYOffset/mMemoTranslateY/mCurTagNo/
mSelectedTagNo/mbColorPass/mbInTag/mbHoverOffset/mbFocusEnabled
Rename setUnk/getUnk accessors; update FocusObject call sites.
Byte-identical (DOL sha1 unchanged). Unit objdiff 100%.
2026-10-02 14:07:51 -05:00
coah
c0126c37d4 cleanup(WPADMem): rename WPADMemBlock.unk_0x10 to callback (#864)
Typed as WPADCallback and invoked on disconnect; leave other
_wmb fields that are only zeroed unnamed for now.

Verified: WPAD/WPADMem 100%/100%, build/43U/ok, DOL sha1
26116613f624061ba99c8d1a299aaa6efa85670d
2026-10-02 14:07:46 -05:00
coah
fc2d150c6d cleanup(WPAD): rename unk_0x98D/98E to encStatus/continuous (#863)
encStatus drives extension decode; continuous selects report mode.
2026-10-02 14:07:19 -05:00
coah
7851b2b29f cleanup(NWC24MsgObj): rename unk_0x10 to flags (#862)
Copied to/from mailbox entry->flags in NWC24MBoxCtrl.
2026-10-02 14:05:10 -05:00
coah
263411ccac cleanup(iplContest): name session NAT/HTTP unk fields (#861)
Rename clear Contest session placeholders from usage:
- unk_0x030 → natState (GameSpy/NAT detect state machine)
- unk_0x034 → gsAvailable
- unk_0x038 → natTimedOut
- unk_0x03c → natFailed
- unk_0x7f0 → httpBuf (NHTTP response buffer)

Verified: iplContest 100%/100%, build/43U/ok, DOL sha1 26116613f624061ba99c8d1a299aaa6efa85670d
2026-10-02 14:04:43 -05:00
coah
09de907f0b cleanup(eZiText): rename work unk_0x141F to maxCnt (#860)
Tracks max context->cnt during DAWG match in Matching zi8dawg.
2026-10-02 14:04:17 -05:00
coah
4e3ab6eae5 cleanup(jdec): rename MCU product fields to mcuTotal (#859)
Frame unk_0x14 and work unk_0x1804 are mcuX*mcuY totals.
2026-10-02 14:04:10 -05:00
coah
99d6fe20a2 cleanup(eZiText): rename work unk_0x1410 to formats (#858)
Saved/restored as savedFormats; assigned from formats arrays.
2026-10-02 14:03:44 -05:00
coah
00013016df cleanup(iplBS2Manager): name tick/update/abort/restart flags (#857)
unk_0x0C -> mbTickEnabled
unk_0x0D -> mbUpdateRequested
unk_0x0E -> mbAbortRequested
unk_0x0F -> mbRestartRequested

Matching 100% before/after; DOL sha1 unchanged.
2026-10-02 14:03:18 -05:00
coah
3e279ef189 cleanup(eZiText): rename work unk_0x17F0 to dawgGroup (#856)
Holds NextDawgGroup() cursor in Matching zi8dawg.
2026-10-02 14:02:52 -05:00
coah
32417fe8a2 cleanup(eZiText): rename work unk_0x01 to countOnly (#855)
Assigned/compared with options->countOnly in zi8getc2.
2026-10-02 14:02:44 -05:00
coah
2d9e3ee14a cleanup(eZiText): rename work unk_0x1A to separator (#854)
Init to space (0x20); Matching zi8space emits it; zi8cgetc saves as separator.
2026-10-02 14:00:30 -05:00
coah
23db5e05e1 cleanup(CDBCryptBuf): rename unk_0x3EC00/04 to size/offset (#853)
Decrypt fills size; Matching CDBRecordFile uses offset for seek/tell/read.
2026-10-02 14:00:24 -05:00
coah
741c9263e3 cleanup(iplSDButton): rename unk_0x54 to mAnimWait (#852)
Same pattern as Button: wait flag while help-button click anim plays.
2026-10-02 14:00:18 -05:00
coah
29fe1efaf2 Use the original Raku progress callback directly and link its thread (#851) 2026-10-02 13:32:07 -05:00
devin-ai-integration[bot]
45aaeb16b2 Link iplChannelTitle: emit gates + name 5 real .data objects (#834)
iplNand.h: IPL_CHANNEL_TITLE_NOVTABLE makes LangFile/LayoutFile virtuals
inline-only for this TU (orig emits their vtables elsewhere), while the
GUIManager.h/iplGuiManager.h gates no longer suppress ~Interface/
EventHandler/~PaneManager emission here - those vtables emit weakly as in
orig. config/43U/symbols.txt: name the 5 real emitted objects at
0x8164EFE4-0x8164F0B8 (dedup'd PaneManager/EventHandler/Interface/
LayoutFile/LangFile vtable emits) so objdiff's byte-diff range covers the
full .data extent; without names the compare stopped at 0x87c and the
extra emit range scored as inserts.

DOL sha1 identical, .data bytes + .rela.data set identical to orig, unit
all sections 100.

Co-authored-by: devin <devin@cognition.ai>
Co-authored-by: coah80 <usernamecole7@gmail.com>
2026-10-02 13:26:47 -05:00
coah
e9114959c9 Retain original socket-option APIs and link matched routines (#848) 2026-10-02 13:20:27 -05:00
coah
1f0eb50f01 match(iplChannelSelect 102/102) (rt7b) (worker e0f02483) (#850) 2026-10-02 13:17:47 -05:00
coah
d93fb2d5f8 match(iplRakuRakuThread 14/14) (rt8b) (worker 8e747652) (#849) 2026-10-02 13:14:53 -05:00
coah
27abfe81d9 Link matched FAT allocation-chain routines (#847) 2026-10-02 13:10:48 -05:00
coah
bf6bc87fbd match(nup 20/23) (fz15h) (worker d8281f4c) (#846) 2026-10-02 13:01:18 -05:00
coah
786a2dd3e8 match(ATERM 17/26, zi8alpha 11/12) (fz20e) (worker 8133f528) (#845) 2026-10-02 12:55:03 -05:00
coah
bdd15186a7 match(pf_fat 35/35) (fz21e) (worker 4f270f72) (#844) 2026-10-02 12:48:07 -05:00
coah
40a2ea7e91 match(SOOption 4/4) (fz3k) (worker 6d7c19b7) (#843) 2026-10-02 12:45:44 -05:00
coah
0b10215388 match(iplSDChannelSelect 122/129) (fz16f) (worker abd61c86) (#842) 2026-10-02 12:42:39 -05:00
coah
4e293a4223 match(odh 24/28) (fz10h) (worker afc4f94d) (#841) 2026-10-02 12:41:08 -05:00
coah
d94df60412 Link matched eZiText wide-word routines (#840) 2026-10-02 12:36:59 -05:00
coah
daf04f1f26 Link matched NWC24 mailbox and message-commit routines (#839) 2026-10-02 12:36:52 -05:00
coah
1994d24f06 match(ZiDAWGGetSibling, Zi8IsWordW: 16-bit byte widening) (orchestrator + data-d11j) (worker 993402bc) (#838) 2026-10-02 12:28:01 -05:00
coah
0d9b038782 match(NWC24MsgCommit 18/18, Texture_MCUtoY8U8V8 12/13) (fz15g) (worker fed147c9) (#837) 2026-10-02 12:25:41 -05:00
coah
ff90063ef9 match(NWC24MBoxCtrl 25/25) (fz21d) (worker 710e3312) (#836) 2026-10-02 12:19:14 -05:00
devin-ai-integration[bot]
c1183780c2 eggAudioExpMgr: emit-gate headers for orig symbol set (stays Equivalent) (#835)
Split 2 of 2 from #815. Removes the invented 'Sample' class. The
EGG_AUDIO_EXPMGR_NO_INLINE_VIRTUALS gates (ArcPlayerMgr 9 virtuals,
SoundHeapMgr loadState/getCurrentLevel, nw4r AutoLock ct/dt) reproduce
orig's .o emit set exactly: same 8 .text symbols at the same offsets plus
__vt__ at .data+0/0x78.

Stays Equivalent: orig orders the secondary-vtable thunks
[@52@dt][@52@calc] while MWCC emits [@52@calc][@52@dt] here, and orig
emits them GLOBAL while ours are WEAK. Verified across 6 other orig
units that thunk order follows most-derived declared-virtual order; the
only lever found that flips it is a second ODR-used derived class's
vtable build - invented code, rejected. See
tools/decomp-assist/linkgap-audio.attempts.md.

Co-authored-by: devin <devin@cognition.ai>
Co-authored-by: coah80 <usernamecole7@gmail.com>
2026-10-02 12:07:38 -05:00
coah
2050ad7616 match(odh 23/28, iplAddress 96/101) (fz10g) (worker 5f8a5379) (#833) 2026-10-02 11:52:47 -05:00
coah
9077ef8c7a data(SOBasic data 100%) (fz3j) (worker 2898f5a5) (#832) 2026-10-02 11:50:33 -05:00
coah
bc303bc36e match(NWC24MsgCommit 17/18) (fz15f) (worker a92a10dd) (#831) 2026-10-02 11:44:54 -05:00
coah
5518cb16fd match(NWC24MsgSubject 9/12, NWC24DateParser 6/8) (fz7h) (worker 5c09b5ac) (#830) 2026-10-02 11:21:02 -05:00
coah
0c06b01c8d Restore memo manager animation vtable and destructor emission for linking (#829) 2026-10-02 11:19:48 -05:00
coah
adc15fdf6f Link matched FAT directory-entry iterator (#828) 2026-10-02 11:17:41 -05:00
coah
dea64a8c9c data(tiPcKeyboard data 100%) (fz21b) (worker c70a72a8) (#827) 2026-10-02 11:10:50 -05:00
coah
3cde45682d match(pf_entry_iterator 16/16) (fz3i) (worker 03d4f3a7) (#826) 2026-10-02 11:04:54 -05:00
coah
ae7cf34cab match(iplSDChannelSelect 121/129) (fz16d) (worker df276bb6) (#825) 2026-10-02 11:03:03 -05:00
coah
91cc177cb7 ci: stop the separate README progress commit (#824)
Landings now write the README progress table inside their own commit,
so the progress job only rebuilds and publishes the numbers to the job
summary instead of pushing a second docs commit to main.
2026-10-02 10:51:22 -05:00
github-actions[bot]
ecee6f01e4 docs: update progress [skip ci] 2026-10-02 15:50:37 +00:00
coah
28d3333887 Link matched JPEG resolution-change routines (#823) 2026-10-02 10:49:57 -05:00
github-actions[bot]
2119935c1d docs: update progress [skip ci] 2026-10-02 15:48:02 +00:00
coah
c7896c3802 match(ATERM 15/26) (fz20) (worker 4adbcdd4) (#822) 2026-10-02 10:46:43 -05:00
github-actions[bot]
68c4c9aeac docs: update progress [skip ci] 2026-10-02 15:45:30 +00:00
coah
1b942565f7 match(Texture_MCUtoY8U8V8 11/13) (fz15e) (worker 2e0b96a1) (#821) 2026-10-02 10:44:28 -05:00
github-actions[bot]
a9705fa1a3 docs: update progress [skip ci] 2026-10-02 15:43:50 +00:00
coah
e1f0ef93a5 match(BS2Update 9/10) (fz1f) (worker 8d7decce) (#820) 2026-10-02 10:42:48 -05:00
github-actions[bot]
adcd8ca586 docs: update progress [skip ci] 2026-10-02 15:40:05 +00:00
coah
76d72f06ce match(idct_resolution_change_var 6/6) (fz3h) (worker ac1e42c9) (#819) 2026-10-02 10:39:11 -05:00
github-actions[bot]
b0474b6eac docs: update progress [skip ci] 2026-10-02 15:38:42 +00:00
coah
9ce28d272f match(KPAD 21/29) (fz16c) (worker a1ca8f8d) (#818) 2026-10-02 10:37:46 -05:00
github-actions[bot]
771208ab77 docs: update progress [skip ci] 2026-10-02 15:10:45 +00:00
coah
cee13c5a0b Correct SD notice APIs to accept aligned 64-bit title IDs (#817) 2026-10-02 10:10:09 -05:00
github-actions[bot]
1c974dbd49 docs: update progress [skip ci] 2026-10-02 14:53:28 +00:00
devin-ai-integration[bot]
bac1e5427a Decode iplSDChannelTitle + ut_ArchiveFontBase (source-only, stays NonMatching) (#816)
- SDButton::setEventHandler was genuinely 1-arg in retail (dead second
  param): corrected decl/def/call sites + symbols.txt mangle. Fixes 5
  fns to instruction-identical and lifts iplSDChannelTitle data to
  .data/.rodata/.sdata/.sdata2 100% (was 12.1%).
- ut_ArchiveFontBase: reordered sheetOffsetsScratch decl/assign to
  match orig materialization.

Both units remain NonMatching — flip attempts verified to break the
linked DOL: iplSDChannelTitle's object emits 51 net-extra anonymous
literal objects (pool merge/order differs, fuzzy 99.94) plus two fns
+4B each (updateCopyStart, startCopyProgress); ut_ArchiveFontBase has
a ~0x380B content region differing (fuzzy 98.47). DOL sha1 stays
26116613f624061ba99c8d1a299aaa6efa85670d with them unlinked.

Co-authored-by: devin <devin@cognition.ai>
Co-authored-by: coah80 <usernamecole7@gmail.com>
2026-10-02 09:52:51 -05:00
github-actions[bot]
b6687e9ff9 docs: update progress [skip ci] 2026-10-02 11:41:42 +00:00
coah
ff52d5235d Restore focus-object emission order and shared pane string for native linking (#814) 2026-10-02 06:40:57 -05:00
github-actions[bot]
7be7f1594e docs: update progress [skip ci] 2026-10-02 11:34:52 +00:00
coah
51b483cbb7 Restore FAT directory definition order and link directory/volume routines (#812) 2026-10-02 06:34:15 -05:00
github-actions[bot]
1bb1fb08be docs: update progress [skip ci] 2026-10-02 11:33:16 +00:00
coah
2f759f35f1 match(iplAddress 95/101) (fz10e) (worker 3c5ccd78) (#813) 2026-10-02 06:32:21 -05:00
github-actions[bot]
ed5c96bd85 docs: update progress [skip ci] 2026-10-02 11:24:46 +00:00
coah
3816427a3e match(iplAddressEdit 90/94) (fz16b) (worker 95d2a3ab) (#811) 2026-10-02 06:23:21 -05:00
github-actions[bot]
2d0a4faa6f docs: update progress [skip ci] 2026-10-02 11:22:42 +00:00
coah
a61a7cf140 match(pf_volume 37/37, idct_resolution_change_var 5/6) (fz3g) (worker fa51267c) (#810) 2026-10-02 06:21:42 -05:00
github-actions[bot]
dce9e0732d docs: update progress [skip ci] 2026-10-02 11:20:10 +00:00
coah
8121c71188 match(Texture_MCUtoY8U8V8 6/13, NWC24MsgCommit 16/18) (fz15c) (worker c264f4a8) (#809) 2026-10-02 06:18:58 -05:00
github-actions[bot]
d6997b0cb9 docs: update progress [skip ci] 2026-10-02 11:15:33 +00:00
github-actions[bot]
6b80fd87f5 docs: update progress [skip ci] 2026-10-02 11:13:58 +00:00
coah
8f920a08c2 match(pf_dir 38/38, iplFocusObject 89/89) (fz1e) (worker db809c39) (#808) 2026-10-02 06:13:48 -05:00
coah
9c81288c55 Link matched eZiText DAWG routines (#807) 2026-10-02 06:12:34 -05:00
github-actions[bot]
abb652bb85 docs: update progress [skip ci] 2026-10-02 11:09:26 +00:00
coah
b578087994 match(Zi8MatchUWDdata; zi8uwd 3/4) (data-d11g) (worker bd9a219c) (#806) 2026-10-02 06:07:57 -05:00
github-actions[bot]
d542ace0ed docs: update progress [skip ci] 2026-10-02 11:02:05 +00:00
coah
d195c16c86 match(zi8dawg 6/6) (fz10d) (worker 64753ac9) (#805) 2026-10-02 06:00:09 -05:00
github-actions[bot]
2daa6aedf6 docs: update progress [skip ci] 2026-10-02 10:55:47 +00:00
coah
9432f36a57 Link matched NWC24 message-reading routines (#804) 2026-10-02 05:54:37 -05:00
github-actions[bot]
4f77bbd2ae docs: update progress [skip ci] 2026-10-02 10:49:20 +00:00
coah
9c6416820d match(NWC24MsgRead 16/16) (fz7e) (worker 784d9f03) (#803) 2026-10-02 05:47:59 -05:00
github-actions[bot]
4bfa1b6c4c docs: update progress [skip ci] 2026-10-02 10:40:05 +00:00
coah
cbed5f6d77 Link matched USB mass-storage block routines (#801) 2026-10-02 05:38:55 -05:00
github-actions[bot]
f8da383802 docs: update progress [skip ci] 2026-10-02 10:38:03 +00:00
coah
18786d6b7d match(ZiDAWGGetChild; zidawg1 3/6) (data-d11f) (worker 07efcb48) (#802) 2026-10-02 05:36:59 -05:00
github-actions[bot]
e7e35742dd docs: update progress [skip ci] 2026-10-02 10:33:16 +00:00
coah
73a89b06e5 match(iplAddressEdit 88/94) (fz16) (worker 41ea7122) (#800) 2026-10-02 05:32:10 -05:00
github-actions[bot]
f0d938021e docs: update progress [skip ci] 2026-10-02 10:26:08 +00:00
coah
e9545f74d5 match(NWC24MsgSubject 8/12) (fz7d) (worker 8ef4fd28) (#799) 2026-10-02 05:25:05 -05:00
github-actions[bot]
d0a9514c9b docs: update progress [skip ci] 2026-10-02 10:22:53 +00:00
github-actions[bot]
c653415d77 docs: update progress [skip ci] 2026-10-02 10:22:05 +00:00
coah
f98ffd0da3 Link matched SD channel object natively (#797) 2026-10-02 05:21:44 -05:00
coah
c31af38e0e Link matched HTTP worker and FAT cluster routines (#796) 2026-10-02 05:21:17 -05:00
github-actions[bot]
9aef037505 docs: update progress [skip ci] 2026-10-02 10:20:51 +00:00
coah
72cf3991b2 match(pf_volume 35/37, pf_entry_iterator 15/16, puh_msc_blk 11/11) (fz3f) (worker 6b7deeb0) (#798) 2026-10-02 05:19:45 -05:00
github-actions[bot]
d8937f9e82 docs: update progress [skip ci] 2026-10-02 10:12:22 +00:00
coah
36d651fe72 match(NWC24iMBoxCheck: volatile oldest-id local proven by store/reload) (orchestrator) (worker 2dcffb88) (#795) 2026-10-02 05:11:13 -05:00
github-actions[bot]
e133119aa5 docs: update progress [skip ci] 2026-10-02 10:09:35 +00:00
coah
fa50eeea1a Link matched NWC24 MIME parser natively (#794) 2026-10-02 05:08:40 -05:00
coah
ae5f904c0b Match CHANS integer parser with a read-only input object (#793) 2026-10-02 05:08:34 -05:00
github-actions[bot]
11f4b29c64 docs: update progress [skip ci] 2026-10-02 10:04:23 +00:00
coah
c7344eccc8 match(NHTTP_thread 26/26, pf_cluster 8/8) (fz8c) (worker 0b57076a) (#792) 2026-10-02 05:03:18 -05:00
github-actions[bot]
86cda2adbe docs: update progress [skip ci] 2026-10-02 10:01:15 +00:00
coah
0d1fa438ba Match HTTP socket send with a const request view and link (#790) 2026-10-02 05:00:25 -05:00
github-actions[bot]
343fa90f9b docs: update progress [skip ci] 2026-10-02 09:59:04 +00:00
coah
ed52b1987e data(ziswordw, zi8uwd data 100%) (data-d11e) (worker d8fd359e) (#791) 2026-10-02 04:57:57 -05:00
github-actions[bot]
00f44a924b docs: update progress [skip ci] 2026-10-02 09:53:45 +00:00
coah
d494f44516 match(NWC24Mime 16/16) (fz7c) (worker 112576fc) (#789) 2026-10-02 04:52:29 -05:00
github-actions[bot]
5439b99f38 docs: update progress [skip ci] 2026-10-02 09:49:58 +00:00
coah
4ccc441d7e data(iplSDChannelTitle, tiCandidateBox data 100%) (data-d15b) (worker 1e30e292) (#788) 2026-10-02 04:48:32 -05:00
github-actions[bot]
4264e5ff51 docs: update progress [skip ci] 2026-10-02 09:44:23 +00:00
coah
f182215e66 match(NHTTP_socket_RVL 9/10, lyt_window data) (fz2e) (worker 3f0262d6) (#787) 2026-10-02 04:42:46 -05:00
github-actions[bot]
fe6a45c09a docs: update progress [skip ci] 2026-10-02 09:21:35 +00:00
coah
f07dd4a6ca match(NWC24Mime 15/16) (fz7b) (worker b676b7bc) (#786) 2026-10-02 04:20:07 -05:00
github-actions[bot]
65cd387bcb docs: update progress [skip ci] 2026-10-02 09:07:11 +00:00
coah
d0c3d43000 match(vi 29/30) (fz10) (worker 2323903b) (#785) 2026-10-02 04:05:45 -05:00
github-actions[bot]
a2abf24854 docs: update progress [skip ci] 2026-10-02 09:01:43 +00:00
coah
1ce1b0458a Link matched USB access-point thread natively (#784) 2026-10-02 04:00:56 -05:00
github-actions[bot]
0e37502750 docs: update progress [skip ci] 2026-10-02 09:00:50 +00:00
coah
78d6827757 Link matched board scene natively (#783) 2026-10-02 03:58:42 -05:00
coah
b0fbec3f25 Link matched HMAC and socket-information units (#782) 2026-10-02 03:58:34 -05:00
coah
d34e09d5dc match(iplUSBAPThread 7/7, iplSDChannelObj 37/38) (fz1d) (worker bb4dde27) (#781) 2026-10-02 03:54:27 -05:00
github-actions[bot]
7cce8859c3 docs: update progress [skip ci] 2026-10-02 08:51:16 +00:00
coah
711ee737f9 match(zi8pud2 6/8; zidawg1 data 100%, structure) (data-d11d) (worker 41cd3236) (#780) 2026-10-02 03:49:46 -05:00
github-actions[bot]
82def66db6 docs: update progress [skip ci] 2026-10-02 08:49:06 +00:00
coah
2039813ccf match(iplBoard 94/94) (fz2d) (worker 0e765719) (#779) 2026-10-02 03:47:50 -05:00
github-actions[bot]
eabfb0cde9 docs: update progress [skip ci] 2026-10-02 08:47:14 +00:00
coah
2cc9824045 match(hmac 3/3, SOInformation 4/4) (fz8) (worker 4ecc5f21) (#778) 2026-10-02 03:46:04 -05:00
github-actions[bot]
6f90840464 docs: update progress [skip ci] 2026-10-02 08:45:35 +00:00
coah
0978b074b8 data(tiInputForm, tiKeyboard data 100%) (data-d4c) (worker a49df763) (#777) 2026-10-02 03:44:38 -05:00
github-actions[bot]
252e40e22f docs: update progress [skip ci] 2026-10-02 08:44:10 +00:00
coah
2230741db8 match(NWC24Mime 13/16) (fz7) (worker 3a4b90c9) (#776) 2026-10-02 03:43:07 -05:00
github-actions[bot]
f3adacfe3d docs: update progress [skip ci] 2026-10-02 08:39:36 +00:00
coah
1cd71c6903 Describe existing MetroTRK trap entries as sized functions (#775) 2026-10-02 03:38:51 -05:00
github-actions[bot]
7b64914abb docs: update progress [skip ci] 2026-10-02 08:23:28 +00:00
devin-ai-integration[bot]
199de6f6c0 Link bannerSound/AxAdpcmPlayer (clean subset) (#774)
Co-authored-by: devin <devin@cognition.ai>
Co-authored-by: coah80 <usernamecole7@gmail.com>
2026-10-02 03:22:37 -05:00
github-actions[bot]
513c2a869e docs: update progress [skip ci] 2026-10-02 08:07:20 +00:00
coah
24b6645572 match(SOOption 3/4, pf_volume 34/37) (fz3c) (worker f024666b) (#773) 2026-10-02 03:06:10 -05:00
github-actions[bot]
9536177edd docs: update progress [skip ci] 2026-10-02 08:01:44 +00:00
coah
81325e667c Restore SDK path function emission order and native linking (#772) 2026-10-02 03:00:54 -05:00
coah
51d5dc519b Refresh completion code total after removing overlapping extent (#771) 2026-10-02 02:57:20 -05:00
github-actions[bot]
b84b3c0d57 docs: update progress [skip ci] 2026-10-02 07:45:02 +00:00
coah
950bb0dda6 match(NHTTP_socket_RVL 8/10) (fz2c) (worker d651d6ad) (#770) 2026-10-02 02:43:25 -05:00
github-actions[bot]
de05797e19 docs: update progress [skip ci] 2026-10-02 07:43:17 +00:00
coah
c70816c7e1 match(PFPATH_MatchFileNameWithPattern: fix overlapping symbol extent) (orchestrator) (worker 5f027758) (#769) 2026-10-02 02:40:46 -05:00
github-actions[bot]
1d290fa12a docs: update progress [skip ci] 2026-10-02 07:33:40 +00:00
coah
6547b1fa10 Link memo input form natively after exact data restoration (#768) 2026-10-02 02:32:54 -05:00
github-actions[bot]
3bdb663f09 docs: update progress [skip ci] 2026-10-02 07:28:48 +00:00
coah
8120309670 Link matched SDK FAT12 and file units natively (#767) 2026-10-02 02:27:48 -05:00
github-actions[bot]
a4c84cbf53 docs: update progress [skip ci] 2026-10-02 07:25:52 +00:00
coah
6ebe56bc04 Emit GCWindow interpolation constructor in native order and link (#765) 2026-10-02 02:24:55 -05:00
github-actions[bot]
69c235ffc2 docs: update progress [skip ci] 2026-10-02 07:23:27 +00:00
coah
767f393bf9 data(iplESMisc data 100%), match(NHTTP_stdlib_RVL 11/14, data 100%) (near8g) (worker 2fc43755) (#766) 2026-10-02 02:22:15 -05:00
github-actions[bot]
6368cc44e9 docs: update progress [skip ci] 2026-10-02 07:20:46 +00:00
coah
7deffd048c data(MyTiInputForm data 100%, tiInputForm/MyTiManager data up) (data-d4b) (worker 4e1959af) (#764) 2026-10-02 02:19:33 -05:00
github-actions[bot]
4aaa362c5e docs: update progress [skip ci] 2026-10-02 07:14:34 +00:00
coah
5fe0a61af7 Initialize KPR callbacks explicitly and enable native linking (#762) 2026-10-02 02:13:46 -05:00
github-actions[bot]
dbf6a1256e docs: update progress [skip ci] 2026-10-02 07:13:27 +00:00
coah
c6c0b145f8 match(pf_fat12 4/4) (fz3b) (worker 18afdc56) (#763) 2026-10-02 02:12:31 -05:00
github-actions[bot]
b38c5653df docs: update progress [skip ci] 2026-10-02 07:11:00 +00:00
coah
d9cf3598fc match(iplMemoryCardManager 18/26) (near9f) (worker 05f3938f) (#761) 2026-10-02 02:09:55 -05:00
coah
c44fbd7209 match(pf_file 45/45) (fz2b) (worker 26c4b368) (#760) 2026-10-02 02:07:43 -05:00
coah
f78a686e32 Correct AOSS allocation callback symbol signatures (#759) 2026-10-02 02:05:41 -05:00
coah
c9fb0697ca tools: audit literal values at corresponding PPC calls (#758) 2026-10-02 01:59:04 -05:00
github-actions[bot]
11df09974b docs: update progress [skip ci] 2026-10-02 06:57:45 +00:00
coah
a3b27c9ed0 match(puh_msc_blk 10/11; pf_fat12, iqdec fuzzy up) (fz3) (worker 6651d7cf) (#757) 2026-10-02 01:56:45 -05:00
github-actions[bot]
91fd1dcb69 docs: update progress [skip ci] 2026-10-02 06:55:24 +00:00
coah
b02273897c fuzzy(zidawg1, zi8pud2, ziswordw structure; ziswordw data) (data-d11b) (worker 9a700863) (#756) 2026-10-02 01:54:31 -05:00
github-actions[bot]
249c129e67 docs: update progress [skip ci] 2026-10-02 06:53:24 +00:00
coah
9ef60d674d match(iplGCWindow 48/48, NWC24MBoxCtrl data 100%) (fz4) (worker 715d7be2) (#755) 2026-10-02 01:52:29 -05:00
github-actions[bot]
aa677ad520 docs: update progress [skip ci] 2026-10-02 06:47:56 +00:00
coah
cbf6363d0f match(kpr_lib 9/9, zconvert 3/4) (fz2) (worker 7208e236) (#754) 2026-10-02 01:46:58 -05:00
github-actions[bot]
c4857800df docs: update progress [skip ci] 2026-10-02 06:33:14 +00:00
coah
0dd0a6941a data(iplSDChannelSelect, iplChannelSelect, wad, NHTTP_thread data 100%) (data-d5c) (worker a2bc7e81) (#753) 2026-10-02 01:32:21 -05:00
github-actions[bot]
422a344b28 docs: update progress [skip ci] 2026-10-02 06:29:37 +00:00
coah
5543b7b720 data(tiTextDrawer data 100%) (data-d14) (worker 6757043c) (#752) 2026-10-02 01:28:42 -05:00
github-actions[bot]
5d63d15248 docs: update progress [skip ci] 2026-10-02 06:27:05 +00:00
coah
2f0f5a44c7 data(zi8alpha data 180->516) (data-d13) (worker 5c2aec13) (#751) 2026-10-02 01:26:05 -05:00
github-actions[bot]
08923eda6c docs: update progress [skip ci] 2026-10-02 06:17:06 +00:00
coah
0c94076d99 data(NHTTP_thread data 88->304) (data-d5b) (worker b909c94b) (#750) 2026-10-02 01:16:02 -05:00
github-actions[bot]
0695760312 docs: update progress [skip ci] 2026-10-02 06:15:45 +00:00
coah
b3c23834a7 data(iplAddressEdit, iplAddress, WPADHIDParser, iplBoardObject data 100%) (data-d7b) (worker 364037a2) (#749) 2026-10-02 01:14:46 -05:00
coah
b145a74db1 data(tiHwKeyboard, sha1, nettime data 100%) (data-d12) (worker b6f9650f) (#748) 2026-10-02 01:13:29 -05:00
github-actions[bot]
b941fc6268 docs: update progress [skip ci] 2026-10-02 06:11:34 +00:00
coah
d5cd4ca777 data(RFL MiddleDatabase/MakeTex/DataUtility/NWC24 data 100%) (data-d10b) (worker 65d1c6de) (#747) 2026-10-02 01:10:19 -05:00
github-actions[bot]
5b7fb6f968 docs: update progress [skip ci] 2026-10-02 06:07:04 +00:00
coah
6fa90e5574 Link the verified native AXFXChorusExp unit (#746) 2026-10-02 01:06:03 -05:00
github-actions[bot]
9702056bda docs: update progress [skip ci] 2026-10-02 06:04:52 +00:00
coah
dc40dd44bb data(RFL Database/HiddenDatabase/NANDLoader/Model data 100%) (data-d9) (worker ba614360) (#745) 2026-10-02 01:03:37 -05:00
github-actions[bot]
32f358cd65 docs: update progress [skip ci] 2026-10-02 06:01:45 +00:00
coah
0cc4c57ecd data(NHTTP_os_RVL, iplDate data 100%, ATERM +80) (data-d3b) (worker 385ef001) (#744) 2026-10-02 01:00:51 -05:00
coah
a1d6b7d930 Correct fixed-width candidate pane-name record boundaries (#742) 2026-10-02 00:57:56 -05:00
github-actions[bot]
18e8dd2d07 docs: update progress [skip ci] 2026-10-02 05:56:49 +00:00
coah
09d3f9beef data(iplController, d_nhttp, iplKeyboard data 100%) (data-d1c) (worker 154fb6cd) (#743) 2026-10-02 00:55:55 -05:00
github-actions[bot]
41adc87d89 docs: update progress [skip ci] 2026-10-02 05:54:16 +00:00
coah
d2ef39c441 data(sd_drv, www_surface, iplFocusObject data 100%) (data-d6b) (worker 85303ada) (#741) 2026-10-02 00:52:57 -05:00
github-actions[bot]
1296031075 docs: update progress [skip ci] 2026-10-02 05:46:15 +00:00
coah
775167f4a5 Link the verified native NUP HTTP unit (#740) 2026-10-02 00:45:17 -05:00
github-actions[bot]
547637bf79 docs: update progress [skip ci] 2026-10-02 05:43:38 +00:00
coah
2b1e29a746 data(iplKeyboard data 1176/1184) (data-d1b) (worker 9e9e6cc1) (#739) 2026-10-02 00:42:44 -05:00
github-actions[bot]
394f6c2444 docs: update progress [skip ci] 2026-10-02 05:41:38 +00:00
coah
35e7147b97 data(iplUSBAP, AOSS data 100%, iplSetting +640, ATERM sbss) (data-d3) (worker ef0da9b3) (#738) 2026-10-02 00:40:50 -05:00
github-actions[bot]
ed3fad1bff docs: update progress [skip ci] 2026-10-02 05:38:15 +00:00
coah
f72e4281a8 match(AXFXChorusExp 7/7) (near7f) (worker f241c3a9) (#737) 2026-10-02 00:37:19 -05:00
github-actions[bot]
f6fd278076 docs: update progress [skip ci] 2026-10-02 05:34:04 +00:00
coah
4b25950eeb data(iplGCWindow, iplSDMemory data 100%) (data-d5) (worker a506aca5) (#736) 2026-10-02 00:32:51 -05:00
coah
dc5d3cf81b Use the implicit HKBManager destructor and link native C++ (#734) 2026-10-02 00:32:38 -05:00
github-actions[bot]
d54e4ba47a docs: update progress [skip ci] 2026-10-02 05:31:35 +00:00
coah
3f330a39ea data(sd_drv data 408->1016) (data-d6) (worker 7268acb9) (#735) 2026-10-02 00:30:26 -05:00
github-actions[bot]
85701c828f docs: update progress [skip ci] 2026-10-02 05:27:56 +00:00
coah
f37268de4f data(BS2Update, iplSound, AOSSLink, iplRakuRakuThread data 100%) (data-d2) (worker 1146ea35) (#733) 2026-10-02 00:26:43 -05:00
github-actions[bot]
26afef0d00 docs: update progress [skip ci] 2026-10-02 05:25:02 +00:00
coah
ecd5e498b5 match(iplMemoryCardManager 17/26) (near9d) (worker ef0188be) (#732) 2026-10-02 00:24:04 -05:00
coah
68e1ee3a35 Restore two original CDB record diagnostic messages (#731) 2026-10-02 00:22:41 -05:00
github-actions[bot]
bcb2ac0e37 docs: update progress [skip ci] 2026-10-02 05:21:18 +00:00
coah
00ff6ea6a0 data(OSUtf 48704/48704 data, iplKeyboard 31/32) (data-d1) (worker c9656d2b) (#730) 2026-10-02 00:20:11 -05:00
github-actions[bot]
eadb516be8 docs: update progress [skip ci] 2026-10-02 05:18:56 +00:00
coah
e3be21cd6c match(nup_nhttp 9/9) (near8e) (worker 6e28d64b) (#729) 2026-10-02 00:18:07 -05:00
coah
9eb08c48a7 Restore the original decide sound in address-book click handling (#727) 2026-10-02 00:16:06 -05:00
github-actions[bot]
456e9dbd2e docs: update progress [skip ci] 2026-10-02 05:15:36 +00:00
coah
4d08c3005b match(tiHKBManager 29/29) (near6i) (worker ba6dfd2a) (#728) 2026-10-02 00:14:31 -05:00
coah
a16c5191f0 Fix the waiting pane references in settings visibility calls (#726) 2026-10-02 00:13:43 -05:00
coah
eecf16f01e Extend memo Manager vtable through its proven final virtual slot (#725) 2026-10-02 00:02:01 -05:00
github-actions[bot]
73f5b332e2 docs: update progress [skip ci] 2026-10-02 04:55:57 +00:00
coah
3d97a4040f Prevent false pointer relocation in the SDK CP932 scalar table (#724) 2026-10-01 23:55:19 -05:00
coah
0b623f581b Restore memo destructor definitions; defer unresolved data linking (#714) 2026-10-01 23:47:34 -05:00
github-actions[bot]
f4e539191d docs: update progress [skip ci] 2026-10-02 04:46:16 +00:00
coah
cb0716f7a5 match(pf_path 26/27) (near6g) (worker 8270df04) (#723) 2026-10-01 23:45:27 -05:00
github-actions[bot]
d47d308721 docs: update progress [skip ci] 2026-10-02 04:45:10 +00:00
coah
1bf9ae4569 match(tiPcKeyboard 140/141, AXFXChorusExp 6/7, aes 7/9) (near7d) (worker 348bb89e) (#722) 2026-10-01 23:44:15 -05:00
github-actions[bot]
bab82c12dd docs: update progress [skip ci] 2026-10-02 04:40:19 +00:00
coah
ccca706770 Match and link USBAP registration; correct thread sbss ownership (#721) 2026-10-01 23:39:26 -05:00
github-actions[bot]
a9833b51a2 docs: update progress [skip ci] 2026-10-02 04:26:00 +00:00
coah
76d8500dcf Repair two reconstructed function symbol names (#720) 2026-10-01 23:25:16 -05:00
github-actions[bot]
184bee0173 docs: update progress [skip ci] 2026-10-02 03:54:08 +00:00
coah
368a86cc6c match(nup_nhttp): 6 -> 8 exact (near8c) (worker 9dbfc514) (#719) 2026-10-01 22:53:23 -05:00
github-actions[bot]
9a7da62d3a docs: update progress [skip ci] 2026-10-02 03:47:25 +00:00
coah
b3c1300392 match(iplSDChannelTitle 64/69, NHTTP_recvbuf 6/7) (worker c82a056b) (#718) 2026-10-01 22:46:49 -05:00
coah
bd762fd162 docs(agents): add orchestrator handoff section (tools, state, pickup steps) (#717) 2026-10-01 22:44:50 -05:00
215 changed files with 63240 additions and 3161 deletions

View File

@@ -2,6 +2,8 @@ name: README progress
# runs on the self-hosted runner on cole's server so it doesn't use hosted minutes. # 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. # only push/schedule/manual triggers, never pull_request, so fork PRs can't reach this machine.
# README progress is written inside each landing commit by the orchestrator, so this job never commits;
# it only rebuilds and publishes the current numbers to the job summary.
on: on:
push: push:
branches: [main] branches: [main]
@@ -15,7 +17,7 @@ concurrency:
cancel-in-progress: true cancel-in-progress: true
permissions: permissions:
contents: write contents: read
jobs: jobs:
progress: progress:
@@ -48,15 +50,8 @@ jobs:
- name: Report - name: Report
run: build/tools/objdiff-cli report generate -p . -o build/43U/report.json -f json run: build/tools/objdiff-cli report generate -p . -o build/43U/report.json -f json
- name: Update README - name: Summary
run: python3 tools/update_readme_progress.py build/43U/report.json README.md "$GITHUB_SHA"
- name: Commit
run: | run: |
if git diff --quiet README.md; then exit 0; fi python3 tools/update_readme_progress.py build/43U/report.json README.md "$GITHUB_SHA"
git config user.name "github-actions[bot]" sed -n '/progress:start/,/progress:end/p' README.md >> "$GITHUB_STEP_SUMMARY"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git checkout -- README.md
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

View File

@@ -78,6 +78,12 @@ Helper tools live in `tools/decomp-assist/`:
between your object and the original. This is the main iteration loop. between your object and the original. This is the main iteration loop.
- `disasm_fn.py <object> <symbol>` — disassembly with relocation-resolved call - `disasm_fn.py <object> <symbol>` — disassembly with relocation-resolved call
names, so you can see which real functions are being called. names, so you can see which real functions are being called.
- `literal_reference_diff.py [unit ...]` — advisory check of actual narrow-string
bytes passed at corresponding calls, including addresses derived from a shared
data base. Defaults to functions scored 100% in the live report; use
`--all-functions` to include other equal-sized functions. Inspect every
candidate against the assembly. This does not follow mutable pointer globals,
infer compiler aliases, or prove complete data matching; skips are reported.
- `pool_diff.py` — diffs the string pool in `.data` between your object and the - `pool_diff.py` — diffs the string pool in `.data` between your object and the
original, string by string. See below; this is the highest-signal tool. original, string by string. See below; this is the highest-signal tool.
- `export_pyghidra.py` — regenerates `ghidra_decomp.txt`, decompiled C for the - `export_pyghidra.py` — regenerates `ghidra_decomp.txt`, decompiled C for the
@@ -431,6 +437,53 @@ Policy additions learned in this loop:
between. Check that it changes no other function in the units that use it. between. Check that it changes no other function in the units that use it.
Use-site volatile casts and the `register` keyword stay forbidden. Use-site volatile casts and the `register` keyword stay forbidden.
### Handoff: where the loop lives
The loop's tools and state live outside the repository, in the author's
workers directory `/mnt/drive2/projects/wii-ipl-workers` (`$W` below). A new
orchestrator thread picks up from there.
Tools in `$W/_restore0928-tools/`:
| File | Purpose |
|------|---------|
| `gate.py <unit...> [--base origin/main] [--quick]` | the acceptance gate; `--quick` only skips the clean `rm -rf build/43U` |
| `land.sh <name> <worktree> merge-base <unit...> <title>` | gate a worker's diff on a fresh branch, push, open and squash-merge the PR |
| `luna.sh <worktree> <name> <prompt> <effort> [session]` | start (or resume) one Codex worker; run with `MODEL=gpt-6.1-sol CODEX_BIN=$W/_codex159/bin/codex` |
| `reviewd.sh` | review daemon: queues every open PR whose head changed |
| `revq.sh`, `automerge.py` | the daemon's gate runner and merge decision |
| `checklist.py` | regenerates `$W/CHECKLIST.md` from a report |
| `chatter.py <run-prefix>` | counts worker text messages for the silent-mode audit |
| `baseline-<sha8>.json` | objdiff reports of past `origin/main` commits, used for regressions |
State:
- `$W/_luna-runs/prompts/`: worker prompts. `common.md` is shared; each
task is `<name>.task.md`, and the launched prompt is `<name>.md` = task +
common.
- `$W/_luna-runs/<name>.<time>.jsonl` and `.last.md`: worker transcript and
final report.
- `$W/_luna-runs/effort-policy.txt`: the policy log. Records escalations,
parked functions, and every orchestrator attempt with what was tried.
- `$W/CHECKLIST.md`: units with non-exact code, worst first.
- Worktrees: `verify-fix` is the only verification and landing tree;
`sol-low`, `sol-med`, `sol-high` and `w0929-fix-board` are the four worker
slots; `orch` is orchestrator scratch.
- Logs: `/tmp/reviewd.log`, `/tmp/vfq.log` (current review batch) and
`/tmp/automerge.log` (merge decisions). These are lost on reboot, which
only means open PRs get reviewed again.
- `/tmp/wii-git.lock`: every `git fetch` or checkout in a shared worktree
runs under `flock` on this file, because worktrees share refs.
To pick up the loop:
1. Make sure no other orchestrator session is running.
2. Check `pgrep -af "reviewd.sh|luna.sh|land.sh"` and restart the review
daemon if it isn't running.
3. Read the newest `.last.md` for each slot. Land gains, then relaunch the
slot per the effort scale.
4. Handle every `NEEDS REVIEW` line in `/tmp/automerge.log`.
## Goal completion contract ## Goal completion contract
The decompilation loop does not stop after a successful wave, a convenient The decompilation loop does not stop after a successful wave, a convenient

View File

@@ -53,9 +53,9 @@ Progress
<!-- progress:start --> <!-- progress:start -->
| Decompiled | Matched | Linked | Data | | Decompiled | Matched | Linked | Data |
|:---:|:---:|:---:|:---:| |:---:|:---:|:---:|:---:|
| 99.39% | 88.26% | 62.75% | 92.12% | | 99.59% | 90.81% | 71.43% | 99.37% |
units 923/1027 complete, functions 12245/12563 matched. units 956/1027 complete, functions 12365/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 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 --> <!-- progress:end -->

View File

@@ -11,6 +11,8 @@ splits: 'config/43U/splits.txt'
ldscript_template: 'config/ldscript_ipl2.lcf' ldscript_template: 'config/ldscript_ipl2.lcf'
force_active: force_active:
- SOGetSockOpt
- SOSetInterfaceOpt
- fprintf - fprintf
- leap_days - leap_days
- __msl_time2tm - __msl_time2tm

View File

@@ -869,11 +869,12 @@ src/scene/setting/iplUSBAP.cpp:
.bss start:0x810BC148 end:0x810BD498 .bss start:0x810BC148 end:0x810BD498
.text start:0x813FC520 end:0x813FC8FC .text start:0x813FC520 end:0x813FC8FC
.data start:0x81657B08 end:0x81657B18 .data start:0x81657B08 end:0x81657B18
.sbss start:0x81698C08 end:0x81698C28 .sbss start:0x81698C08 end:0x81698C20
src/scene/setting/iplUSBAPThread.cpp: src/scene/setting/iplUSBAPThread.cpp:
.text start:0x813FC8FC end:0x813FCA0C .text start:0x813FC8FC end:0x813FCA0C
.data start:0x81657B18 end:0x81657B60 .data start:0x81657B18 end:0x81657B60
.sbss start:0x81698C20 end:0x81698C28
src/scene/setting/iplAOSSThread.cpp: src/scene/setting/iplAOSSThread.cpp:
.bss start:0x810BD498 end:0x810BD4A8 .bss start:0x810BD498 end:0x810BD4A8

File diff suppressed because it is too large Load Diff

View File

@@ -738,11 +738,11 @@ config.libs = [
] ]
), ),
IPLSection("board", [ IPLSection("board", [
Object(Equivalent, "scene/board/iplBoard.cpp"), Object(Matching, "scene/board/iplBoard.cpp"),
Object(Matching, "scene/board/iplBoardObject.cpp"), Object(Matching, "scene/board/iplBoardObject.cpp"),
Object(Matching, "scene/board/iplBoardSD.cpp"), Object(Matching, "scene/board/iplBoardSD.cpp"),
Object(Matching, "scene/board/iplUrlProcessor.cpp"), Object(Matching, "scene/board/iplUrlProcessor.cpp"),
Object(Equivalent, "scene/board/iplFocusObject.cpp"), Object(Matching, "scene/board/iplFocusObject.cpp"),
] ]
), ),
IPLSection("button", [ IPLSection("button", [
@@ -772,7 +772,7 @@ config.libs = [
] ]
), ),
IPLSection("channelTitle", [ IPLSection("channelTitle", [
Object(Equivalent, "scene/channelTitle/iplChannelTitle.cpp"), Object(Matching, "scene/channelTitle/iplChannelTitle.cpp"),
] ]
), ),
IPLSection("faceSelect", [ IPLSection("faceSelect", [
@@ -816,7 +816,7 @@ config.libs = [
Object(Matching, "scene/memoryCard/iplMemoryCardBase.cpp"), Object(Matching, "scene/memoryCard/iplMemoryCardBase.cpp"),
Object(NonMatching, "scene/memoryCard/iplMemoryCardManager.cpp"), Object(NonMatching, "scene/memoryCard/iplMemoryCardManager.cpp"),
Object(Matching, "scene/memoryCard/iplGCSaveData.cpp"), Object(Matching, "scene/memoryCard/iplGCSaveData.cpp"),
Object(NonMatching, "scene/memoryCard/iplGCWindow.cpp"), Object(Matching, "scene/memoryCard/iplGCWindow.cpp"),
] ]
), ),
IPLSection("textBalloon", [ IPLSection("textBalloon", [
@@ -850,7 +850,7 @@ config.libs = [
), ),
IPLSection("sdChannelSelect", [ IPLSection("sdChannelSelect", [
Object(NonMatching, "scene/sdChannelSelect/iplSDChannelSelect.cpp"), Object(NonMatching, "scene/sdChannelSelect/iplSDChannelSelect.cpp"),
Object(NonMatching, "scene/sdChannelSelect/iplSDChannelObj.cpp"), Object(Matching, "scene/sdChannelSelect/iplSDChannelObj.cpp"),
] ]
), ),
IPLSection("sdChannelTitle", [ IPLSection("sdChannelTitle", [
@@ -873,11 +873,11 @@ config.libs = [
Object(Matching, "scene/setting/iplNCDSetting.cpp"), Object(Matching, "scene/setting/iplNCDSetting.cpp"),
Object(Matching, "scene/setting/iplParental.cpp"), Object(Matching, "scene/setting/iplParental.cpp"),
Object(Matching, "scene/setting/iplAPScanThread.cpp"), Object(Matching, "scene/setting/iplAPScanThread.cpp"),
Object(NonMatching, "scene/setting/iplUSBAP.cpp"), Object(Matching, "scene/setting/iplUSBAP.cpp"),
Object(NonMatching, "scene/setting/iplUSBAPThread.cpp"), Object(Matching, "scene/setting/iplUSBAPThread.cpp"),
Object(Matching, "scene/setting/iplAOSSThread.cpp"), Object(Matching, "scene/setting/iplAOSSThread.cpp"),
Object(NonMatching, "scene/setting/AOSSLink.c"), Object(NonMatching, "scene/setting/AOSSLink.c"),
Object(NonMatching, "scene/setting/iplRakuRakuThread.cpp"), Object(Matching, "scene/setting/iplRakuRakuThread.cpp"),
Object(NonMatching, "scene/setting/AOSS.c", extra_cflags=["-O4,p", "-inline off"]), Object(NonMatching, "scene/setting/AOSS.c", extra_cflags=["-O4,p", "-inline off"]),
Object(NonMatching, "scene/setting/ATERM.c", extra_cflags=["-O4,p", "-inline off"]), Object(NonMatching, "scene/setting/ATERM.c", extra_cflags=["-O4,p", "-inline off"]),
] ]
@@ -901,7 +901,7 @@ config.libs = [
), ),
IPLSection("bannerSound", [ IPLSection("bannerSound", [
Object(Matching, "bannerSound/AudioWavePlayer.cpp"), Object(Matching, "bannerSound/AudioWavePlayer.cpp"),
Object(Equivalent, "bannerSound/AxAdpcmPlayer.cpp"), Object(Matching, "bannerSound/AxAdpcmPlayer.cpp"),
Object(Matching, "bannerSound/BannerSoundPlayer.cpp"), Object(Matching, "bannerSound/BannerSoundPlayer.cpp"),
Object(Matching, "bannerSound/AudioWaveUtility.cpp"), Object(Matching, "bannerSound/AudioWaveUtility.cpp"),
] ]
@@ -927,13 +927,13 @@ config.libs = [
Object(Matching, "keyboard/tiPkData.cpp", extra_cflags=["-O4,p"], shift_jis=False), Object(Matching, "keyboard/tiPkData.cpp", extra_cflags=["-O4,p"], shift_jis=False),
Object(Matching, "keyboard/tiLanguageIndependentData.cpp", extra_cflags=["-O4,p"], shift_jis=False), Object(Matching, "keyboard/tiLanguageIndependentData.cpp", extra_cflags=["-O4,p"], shift_jis=False),
Object(Matching, "keyboard/tiTextInputBase.cpp", extra_cflags=["-O4,p"]), Object(Matching, "keyboard/tiTextInputBase.cpp", extra_cflags=["-O4,p"]),
Object(NonMatching, "keyboard/MyTiManager.cpp", extra_cflags=["-O4,p"]), Object(Matching, "keyboard/MyTiManager.cpp", extra_cflags=["-O4,p"]),
Object(NonMatching, "keyboard/MyTiInputForm.cpp", extra_cflags=["-O4,p"]), Object(Matching, "keyboard/MyTiInputForm.cpp", extra_cflags=["-O4,p"]),
Object(Matching, "keyboard/MyTiLetterForm.cpp", extra_cflags=["-O4,p"]), Object(Matching, "keyboard/MyTiLetterForm.cpp", extra_cflags=["-O4,p"]),
Object(Matching, "keyboard/MyTiBg.cpp", extra_cflags=["-O4,p"]), Object(Matching, "keyboard/MyTiBg.cpp", extra_cflags=["-O4,p"]),
Object(Matching, "keyboard/tiDebug.cpp", extra_cflags=["-O4,p"]), Object(Matching, "keyboard/tiDebug.cpp", extra_cflags=["-O4,p"]),
Object(Matching, "keyboard/tiGUIManager.cpp", extra_cflags=["-O4,p"]), Object(Matching, "keyboard/tiGUIManager.cpp", extra_cflags=["-O4,p"]),
Object(NonMatching, "keyboard/tiHKBManager.cpp", extra_cflags=["-O4,p"]), Object(Matching, "keyboard/tiHKBManager.cpp", extra_cflags=["-O4,p"]),
Object(Matching, "keyboard/tiHwKeyboard.cpp", extra_cflags=["-O4,p"]), Object(Matching, "keyboard/tiHwKeyboard.cpp", extra_cflags=["-O4,p"]),
Object(Matching, "keyboard/tiLayout.cpp", extra_cflags=["-O4,p"]), Object(Matching, "keyboard/tiLayout.cpp", extra_cflags=["-O4,p"]),
Object(Matching, "keyboard/tiLayoutGather.cpp", extra_cflags=["-O4,p"]), Object(Matching, "keyboard/tiLayoutGather.cpp", extra_cflags=["-O4,p"]),
@@ -989,7 +989,7 @@ config.libs = [
Object(NonMatching, "clib/zi8cgetc.c"), Object(NonMatching, "clib/zi8cgetc.c"),
Object(Matching, "clib/zi8cinfo.c"), Object(Matching, "clib/zi8cinfo.c"),
Object(Matching, "clib/zi8copy.c"), Object(Matching, "clib/zi8copy.c"),
Object(NonMatching, "clib/zi8dawg.c"), Object(Matching, "clib/zi8dawg.c"),
Object(Matching, "clib/zi8getc.c"), Object(Matching, "clib/zi8getc.c"),
Object(NonMatching, "clib/zi8getc2.c"), Object(NonMatching, "clib/zi8getc2.c"),
Object(Matching, "clib/zi8getSW.c"), Object(Matching, "clib/zi8getSW.c"),
@@ -1005,7 +1005,7 @@ config.libs = [
Object(Matching, "clib/zi8ZHuwd.c"), Object(Matching, "clib/zi8ZHuwd.c"),
Object(NonMatching, "clib/zidawg1.c"), Object(NonMatching, "clib/zidawg1.c"),
Object(Matching, "clib/zikorean.c"), Object(Matching, "clib/zikorean.c"),
Object(NonMatching, "clib/ziswordw.c"), Object(Matching, "clib/ziswordw.c"),
Object(NonMatching, "clib/zkokeyp.c"), Object(NonMatching, "clib/zkokeyp.c"),
Object(Matching, "clib/zierror.c"), Object(Matching, "clib/zierror.c"),
Object(NonMatching, "clib/zmtkey.c"), Object(NonMatching, "clib/zmtkey.c"),
@@ -1045,7 +1045,7 @@ config.libs = [
Object(Matching, "net/crc.c"), Object(Matching, "net/crc.c"),
Object(NonMatching, "net/md5.c"), Object(NonMatching, "net/md5.c"),
Object(Matching, "net/sha1.c"), Object(Matching, "net/sha1.c"),
Object(NonMatching, "net/hmac.c"), Object(Matching, "net/hmac.c"),
Object(Matching, "net/neterrorcode.c"), Object(Matching, "net/neterrorcode.c"),
Object(Matching, "net/NETVersion.c"), Object(Matching, "net/NETVersion.c"),
Object(NonMatching, "net/aes.c"), Object(NonMatching, "net/aes.c"),
@@ -1060,9 +1060,9 @@ config.libs = [
Object(NonMatching, "nhttp/NHTTP_recvbuf.c"), Object(NonMatching, "nhttp/NHTTP_recvbuf.c"),
Object(Matching, "nhttp/NHTTP_request.c"), Object(Matching, "nhttp/NHTTP_request.c"),
Object(Matching, "nhttp/NHTTP_response.c"), Object(Matching, "nhttp/NHTTP_response.c"),
Object(NonMatching, "nhttp/NHTTP_socket_RVL.c"), Object(Matching, "nhttp/NHTTP_socket_RVL.c"),
Object(NonMatching, "nhttp/NHTTP_stdlib_RVL.c"), Object(NonMatching, "nhttp/NHTTP_stdlib_RVL.c"),
Object(NonMatching, "nhttp/NHTTP_thread.c"), Object(Matching, "nhttp/NHTTP_thread.c"),
Object(Matching, "nhttp/d_nhttp_private.c"), Object(Matching, "nhttp/d_nhttp_private.c"),
Object(Matching, "nhttp/d_nhttp.c"), Object(Matching, "nhttp/d_nhttp.c"),
Object(Matching, "nhttp/d_nhttp_common.c"), Object(Matching, "nhttp/d_nhttp_common.c"),
@@ -1075,12 +1075,12 @@ config.libs = [
Object(Matching, "nwc24/NWC24Utils.c"), Object(Matching, "nwc24/NWC24Utils.c"),
Object(Matching, "nwc24/NWC24Manage.c"), Object(Matching, "nwc24/NWC24Manage.c"),
Object(Matching, "nwc24/NWC24MsgObj.c"), Object(Matching, "nwc24/NWC24MsgObj.c"),
Object(NonMatching, "nwc24/NWC24MBoxCtrl.c"), Object(Matching, "nwc24/NWC24MBoxCtrl.c"),
Object(NonMatching, "nwc24/NWC24Mime.c"), Object(Matching, "nwc24/NWC24Mime.c"),
Object(Matching, "nwc24/NWC24Stream.c"), Object(Matching, "nwc24/NWC24Stream.c"),
Object(Matching, "nwc24/NWC24Parser.c"), Object(Matching, "nwc24/NWC24Parser.c"),
Object(NonMatching, "nwc24/NWC24MsgCommit.c"), Object(Matching, "nwc24/NWC24MsgCommit.c"),
Object(NonMatching, "nwc24/NWC24MsgRead.c"), Object(Matching, "nwc24/NWC24MsgRead.c"),
Object(NonMatching, "nwc24/NWC24MsgSubject.c"), Object(NonMatching, "nwc24/NWC24MsgSubject.c"),
Object(Matching, "nwc24/NWC24Schedule.c"), Object(Matching, "nwc24/NWC24Schedule.c"),
Object(NonMatching, "nwc24/NWC24DateParser.c"), Object(NonMatching, "nwc24/NWC24DateParser.c"),
@@ -1097,8 +1097,8 @@ config.libs = [
RevoEXLib("so", [ RevoEXLib("so", [
Object(Matching, "so/SOCommon.c"), Object(Matching, "so/SOCommon.c"),
Object(NonMatching, "so/SOBasic.c"), Object(NonMatching, "so/SOBasic.c"),
Object(NonMatching, "so/SOInformation.c"), Object(Matching, "so/SOInformation.c"),
Object(NonMatching, "so/SOOption.c"), Object(Matching, "so/SOOption.c"),
] ]
), ),
RevoEXLib("ssl", [ RevoEXLib("ssl", [
@@ -1212,7 +1212,7 @@ config.libs = [
Object(NonMatching, "exif/exif_parse.c"), Object(NonMatching, "exif/exif_parse.c"),
Object(Matching, "reschange/iqdec_resolution_change_a3.c"), Object(Matching, "reschange/iqdec_resolution_change_a3.c"),
Object(NonMatching, "reschange/idct_resolution_change_var.c"), Object(Matching, "reschange/idct_resolution_change_var.c"),
Object(NonMatching, "texturecvtr/Texture_MCUtoY8U8V8.c"), Object(NonMatching, "texturecvtr/Texture_MCUtoY8U8V8.c"),
Object(NonMatching, "texturecvtr/Texture_MCUtoRGB565.c"), Object(NonMatching, "texturecvtr/Texture_MCUtoRGB565.c"),
@@ -1453,7 +1453,7 @@ config.libs = [
Object(Matching, "axfx/AXFXReverbStd.c"), Object(Matching, "axfx/AXFXReverbStd.c"),
Object(Matching, "axfx/AXFXReverbStdExp.c"), Object(Matching, "axfx/AXFXReverbStdExp.c"),
Object(Matching, "axfx/AXFXChorus.c"), Object(Matching, "axfx/AXFXChorus.c"),
Object(NonMatching, "axfx/AXFXChorusExp.c"), Object(Matching, "axfx/AXFXChorusExp.c"),
Object(Matching, "axfx/AXFXLfoTable.c"), Object(Matching, "axfx/AXFXLfoTable.c"),
Object(Matching, "axfx/AXFXSrcCoef.c"), Object(Matching, "axfx/AXFXSrcCoef.c"),
Object(Matching, "axfx/AXFXHooks.c"), Object(Matching, "axfx/AXFXHooks.c"),
@@ -1692,19 +1692,19 @@ config.libs = [
Object(Matching, "fa/pdm_disk.c"), Object(Matching, "fa/pdm_disk.c"),
Object(NonMatching, "fa/pdm_partition.c"), Object(NonMatching, "fa/pdm_partition.c"),
Object(NonMatching, "fa/pf_cache.c"), Object(NonMatching, "fa/pf_cache.c"),
Object(NonMatching, "fa/pf_cluster.c"), Object(Matching, "fa/pf_cluster.c"),
Object(NonMatching, "fa/pf_dir.c"), Object(Matching, "fa/pf_dir.c"),
Object(Matching, "fa/pf_entry.c"), Object(Matching, "fa/pf_entry.c"),
Object(NonMatching, "fa/pf_entry_iterator.c"), Object(Matching, "fa/pf_entry_iterator.c"),
Object(NonMatching, "fa/pf_fat.c"), Object(Matching, "fa/pf_fat.c"),
Object(NonMatching, "fa/pf_fat12.c"), Object(Matching, "fa/pf_fat12.c"),
Object(Matching, "fa/pf_fat16.c"), Object(Matching, "fa/pf_fat16.c"),
Object(Matching, "fa/pf_fat32.c"), Object(Matching, "fa/pf_fat32.c"),
Object(Matching, "fa/pf_fatfs.c"), Object(Matching, "fa/pf_fatfs.c"),
Object(NonMatching, "fa/pf_file.c"), Object(Matching, "fa/pf_file.c"),
Object(NonMatching, "fa/pf_path.c"), Object(Matching, "fa/pf_path.c"),
Object(Matching, "fa/pf_sector.c"), Object(Matching, "fa/pf_sector.c"),
Object(NonMatching, "fa/pf_volume.c"), Object(Matching, "fa/pf_volume.c"),
Object(Matching, "fa/pf_volume_apiadd.c"), Object(Matching, "fa/pf_volume_apiadd.c"),
Object(Matching, "fa/pf_cp932.c"), Object(Matching, "fa/pf_cp932.c"),
Object(Matching, "fa/pf_api_util.c"), Object(Matching, "fa/pf_api_util.c"),
@@ -1860,7 +1860,7 @@ config.libs = [
Object(Matching, "fa/msc/puh_msc.c"), Object(Matching, "fa/msc/puh_msc.c"),
Object(Matching, "fa/msc/puh_msc_cmd.c"), Object(Matching, "fa/msc/puh_msc_cmd.c"),
Object(NonMatching, "fa/msc/puh_msc_blk.c"), Object(Matching, "fa/msc/puh_msc_blk.c"),
] ]
), ),
RVLSDKLib("sdi", [ RVLSDKLib("sdi", [
@@ -1869,7 +1869,7 @@ config.libs = [
), ),
RVLSDKLib("nup", [ RVLSDKLib("nup", [
Object(NonMatching, "nup/nup.cpp"), Object(NonMatching, "nup/nup.cpp"),
Object(NonMatching, "nup/nup_nhttp.cpp"), Object(Matching, "nup/nup_nhttp.cpp"),
Object(Matching, "nup/nup_mem.cpp"), Object(Matching, "nup/nup_mem.cpp"),
] ]
), ),
@@ -1892,7 +1892,7 @@ config.libs = [
] ]
), ),
RVLSDKLib("kpr", [ RVLSDKLib("kpr", [
Object(NonMatching, "kpr/kpr_lib.c"), Object(Matching, "kpr/kpr_lib.c"),
] ]
), ),
RVLSDKLib("usbkbd", [ RVLSDKLib("usbkbd", [

View File

@@ -37,8 +37,16 @@ namespace ipl {
u8 unk_0x06; // 0x06 u8 unk_0x06; // 0x06
u8 unk_0x07; // 0x07 u8 unk_0x07; // 0x07
u8 iconFmt[8]; // 0x08 u8 iconFmt[8]; // 0x08
u16 anmFrameBits; // 0x10 #ifdef IPL_MEMORY_CARD_MANAGER_CPP
volatile u16 anmFrameBits;
#else
u16 anmFrameBits;
#endif
#ifdef IPL_MEMORY_CARD_MANAGER_CPP
volatile s16 anmMax;
#else
s16 anmMax; // 0x12 s16 anmMax; // 0x12
#endif
u32 bannerOffset; // 0x14 u32 bannerOffset; // 0x14
u32 bannerTlutOffset; // 0x18 u32 bannerTlutOffset; // 0x18
u32 iconOffset[8]; // 0x1C u32 iconOffset[8]; // 0x1C

View File

@@ -92,7 +92,11 @@ namespace textinput {
virtual void setSaveData(savedata::MemoSetting memoSetting) { virtual void setSaveData(savedata::MemoSetting memoSetting) {
mMemoSetting = memoSetting; mMemoSetting = memoSetting;
} }
#ifdef IPL_KEYBOARD_MEMO_GET_SAVE_DATA
virtual savedata::MemoSetting getSaveData();
#else
virtual savedata::MemoSetting getSaveData() { return mMemoSetting; } virtual savedata::MemoSetting getSaveData() { return mMemoSetting; }
#endif
virtual void changeState(StateTimeLine stateTimeLine); virtual void changeState(StateTimeLine stateTimeLine);
virtual State* getState() { return mpCurrentState; } virtual State* getState() { return mpCurrentState; }

View File

@@ -109,10 +109,23 @@ namespace textinput {
HKBManager* manager; HKBManager* manager;
}; };
HKBManager() __attribute__((never_inline)); HKBManager() __attribute__((never_inline));
~HKBManager();
static HKBManager& getInstance() { return sInstance; } static HKBManager& getInstance() { return sInstance; }
void Initialize(); void Initialize();
void ClearState(); void ClearState();
u32 FilterCharacter(u32 code) const {
if (allowedCharacters == 0) return code;
u32 count = allowedCharacterCount;
if (count == 0) return code;
for (u32 index = 0; index < count; index++) {
if (static_cast<u16>(code) == allowedCharacters[index]) return code;
}
return 0;
}
void DetachDevice(KBDDevEvent* event) {
u8 device = event->device;
attached[device] = 0;
states[device].Clear();
}
u32 GetModifierState() const; u32 GetModifierState() const;
void SetCountry(u8 country); void SetCountry(u8 country);
void SetModifierState(u32 state, u32 mask); void SetModifierState(u32 state, u32 mask);

View File

@@ -197,6 +197,7 @@ namespace textinput {
bool mbMaintainCursorCache; bool mbMaintainCursorCache;
#elif defined(MYTIINPUTFORM_IMPLEMENTATION) #elif defined(MYTIINPUTFORM_IMPLEMENTATION)
protected: protected:
void setDrawScrollY(const f32& scroll) { mfDrawScrollY = scroll; }
u8 mDrawState[0x27]; u8 mDrawState[0x27];
f32 mfDrawScrollY; f32 mfDrawScrollY;
u8 mDrawCacheState[0x14]; u8 mDrawCacheState[0x14];

View File

@@ -55,7 +55,7 @@ namespace textinput {
public: public:
Animation() : mfAnimationTime(0.0f), mbInAnimation(false), mbSE(false), mpAnimObserver(NULL) {} Animation() : mfAnimationTime(0.0f), mbInAnimation(false), mbSE(false), mpAnimObserver(NULL) {}
#ifdef TIINPUTFORM_IMPLEMENTATION #if defined(TIINPUTFORM_IMPLEMENTATION) || defined(MYTIMANAGER_IMPLEMENTATION)
virtual void startAnm(f32 start, f32 end, f32 duration, AnimObserver* observer, void* data); virtual void startAnm(f32 start, f32 end, f32 duration, AnimObserver* observer, void* data);
#else #else
virtual void startAnm(AnimObserver*, f32, f32, f32, void*); virtual void startAnm(AnimObserver*, f32, f32, f32, void*);

View File

@@ -34,14 +34,14 @@ namespace gui {
virtual void draw(Mtx& mtx) {} // 0x14 (0x05) virtual void draw(Mtx& mtx) {} // 0x14 (0x05)
virtual void draw() {} // 0x18 (0x06) virtual void draw() {} // 0x18 (0x06)
#if defined(IPL_CHANNEL_TITLE_NOVTABLE) || defined(IPL_GC_SAVEDATA_NOVTABLE) || defined(IPL_MEMORY_CARD_NOVTABLE) #if defined(IPL_GC_SAVEDATA_NOVTABLE) || defined(IPL_MEMORY_CARD_NOVTABLE)
virtual ~Interface(); // 0x1C (0x07) virtual ~Interface(); // 0x1C (0x07)
#else #else
virtual ~Interface() {} // 0x1C (0x07) virtual ~Interface() {} // 0x1C (0x07)
#endif #endif
}; };
#if defined(IPL_CHANNEL_TITLE_NOVTABLE) || defined(IPL_GC_WINDOW_NOVTABLE) || defined(IPL_GC_SAVEDATA_NOVTABLE) || defined(IPL_MEMORY_CARD_NOVTABLE) #if defined(IPL_GC_WINDOW_NOVTABLE) || defined(IPL_GC_SAVEDATA_NOVTABLE) || defined(IPL_MEMORY_CARD_NOVTABLE)
class __declspec(novtable) EventHandler { class __declspec(novtable) EventHandler {
#else #else
class EventHandler { class EventHandler {

View File

@@ -24,7 +24,7 @@ namespace ipl {
mbDisableCon(bDisableCon) {} mbDisableCon(bDisableCon) {}
#endif #endif
#if defined(IPL_CHANNEL_TITLE_NOVTABLE) || defined(IPL_GC_SAVEDATA_NOVTABLE) || defined(IPL_MEMORY_CARD_NOVTABLE) #if defined(IPL_GC_SAVEDATA_NOVTABLE) || defined(IPL_MEMORY_CARD_NOVTABLE)
virtual ~PaneManager(); virtual ~PaneManager();
#else #else
virtual ~PaneManager() {} virtual ~PaneManager() {}

View File

@@ -7,6 +7,10 @@
#include "utility/iplFrameController.h" #include "utility/iplFrameController.h"
#ifdef IPL_GC_WINDOW_CPP
#include "math/iplMathTypes.h"
#endif
#ifdef IPL_GCW_INTP_CTOR_OUT_OF_LINE #ifdef IPL_GCW_INTP_CTOR_OUT_OF_LINE
#include "global/decomp/utils.h" #include "global/decomp/utils.h"
#endif #endif
@@ -38,6 +42,33 @@ namespace ipl {
T mEnd; T mEnd;
}; };
#ifdef IPL_GC_WINDOW_CPP
template <>
class Interporation<VEC3> : public utility::FrameController {
public:
virtual ~Interporation();
void init(int playback, f32 maxFrame, f32 minFrame, const VEC3& start,
const VEC3& end, f32 speed = 1.0f) {
mStart = start;
mEnd = end;
utility::FrameController::init(playback, maxFrame, minFrame, speed);
}
const VEC3& getStart() { return mStart; }
const VEC3& getEnd() { return mEnd; }
void playBackwards() {
mAnmType = ANIM_TYPE_BACKWARD;
mState = ANIM_STATE_PLAY;
}
protected:
VEC3 mStart;
VEC3 mEnd;
};
#endif
template <typename T> template <typename T>
class LinearIntp : public Interporation<T> { class LinearIntp : public Interporation<T> {
public: public:
@@ -61,6 +92,16 @@ namespace ipl {
T get2() const { return (((mStart * (mMaxFrame - mFrame)) + (mEnd * mFrame)) / mMaxFrame); } T get2() const { return (((mStart * (mMaxFrame - mFrame)) + (mEnd * mFrame)) / mMaxFrame); }
}; };
#ifdef IPL_GC_WINDOW_CPP
template <>
class LinearIntp<VEC3> : public Interporation<VEC3> {
public:
LinearIntp();
virtual ~LinearIntp();
VEC3 get() const;
};
#endif
#ifdef IPL_CHANNEL_TITLE_NOVTABLE #ifdef IPL_CHANNEL_TITLE_NOVTABLE
template <typename T> template <typename T>

View File

@@ -143,7 +143,11 @@ namespace ipl {
#else #else
VEC3 operator-(const VEC3& rhs) const { return VEC3(x - rhs.x, y - rhs.y, z - rhs.z); } VEC3 operator-(const VEC3& rhs) const { return VEC3(x - rhs.x, y - rhs.y, z - rhs.z); }
#endif #endif
#ifdef IPL_FOCUS_OBJECT_CPP
VEC3 operator*(f32 val) const;
#else
VEC3 operator*(f32 val) const { return VEC3(x * val, y * val, z * val); } VEC3 operator*(f32 val) const { return VEC3(x * val, y * val, z * val); }
#endif
VEC3 operator*(f64 val) const { VEC3 operator*(f64 val) const {
nw4r::math::VEC3 vecOut; nw4r::math::VEC3 vecOut;
VEC3Scale(&vecOut, this, (f32)val); VEC3Scale(&vecOut, this, (f32)val);

View File

@@ -53,24 +53,7 @@ namespace ipl {
mBScroller.init(); mBScroller.init();
} }
BOOL calc(bool canScroll) __attribute__((never_inline)) /*for now*/ { BOOL calc(bool canScroll);
BOOL result = FALSE;
if (canScroll) {
if (mBScroller.calc()) {
result = TRUE;
}
}
mScroller.calc();
f32 movable = mScroller.movable_pos(mBScroller.getSpeed());
mScroller.addScroll(movable);
mBScroller.addSoundFreq(movable);
return result;
}
BOOL is_busy() const { BOOL is_busy() const {
BOOL result = TRUE; BOOL result = TRUE;

View File

@@ -18,11 +18,11 @@ namespace ipl {
class line_collision { class line_collision {
public: public:
line_collision() : unk_0x00(0.0f), unk_0x04(0.0f), unk_0x08(0.0f) {} line_collision() : mLeft(0.0f), mRight(0.0f), mY(0.0f) {}
f32 unk_0x00; f32 mLeft;
f32 unk_0x04; f32 mRight;
f32 unk_0x08; f32 mY;
nw4r::ut::Link mLinkList; // 0x0C nw4r::ut::Link mLinkList; // 0x0C
}; };
@@ -31,9 +31,9 @@ namespace ipl {
url_collision(); url_collision();
~url_collision(); ~url_collision();
int unk_0x00; int mTagNo;
wchar_t* unk_0x04; wchar_t* mpStart;
wchar_t* unk_0x08; wchar_t* mpEnd;
nw4r::ut::Link mLinkList; // 0x0C nw4r::ut::Link mLinkList; // 0x0C
nw4r::ut::List mLineCollisions; // 0x14 nw4r::ut::List mLineCollisions; // 0x14
}; };
@@ -53,19 +53,19 @@ namespace ipl {
void parse(nw4r::ut::PrintContext<wchar_t>* context); void parse(nw4r::ut::PrintContext<wchar_t>* context);
BOOL is_focused() const; BOOL is_focused() const;
void select(int unk); void select(int tagNo);
int get_focused_tagno(int chan) const; int get_focused_tagno(int chan) const;
url_collision* get_selected_col(); url_collision* get_selected_col();
void get_url(char* urlOut, u32 urlLen); void get_url(char* urlOut, u32 urlLen);
void setUnk_0x40(f32 val) { unk_0x40 = val; } void setHitYOffset(f32 val) { mHitYOffset = val; }
void setUnk_0x44(f32 val) { unk_0x44 = val; } void setMemoTranslateY(f32 val) { mMemoTranslateY = val; }
void setUnk_0x53(bool val) { unk_0x53 = val; } void setFocusEnabled(bool val) { mbFocusEnabled = val; }
u8 getUnk_0x50() const { return unk_0x50; } u8 getColorPass() const { return mbColorPass; }
void setUnk_0x50(u8 val) { unk_0x50 = val; } void setColorPass(u8 val) { mbColorPass = val; }
private: private:
typedef struct { typedef struct {
@@ -75,14 +75,14 @@ namespace ipl {
con_data mConData[WPAD_MAX_CONTROLLERS]; // 0x00 con_data mConData[WPAD_MAX_CONTROLLERS]; // 0x00
nw4r::ut::List mUrlCollisions; // 0x34 nw4r::ut::List mUrlCollisions; // 0x34
f32 unk_0x40; f32 mHitYOffset;
f32 unk_0x44; f32 mMemoTranslateY;
int unk_0x48; int mCurTagNo;
int unk_0x4C; int mSelectedTagNo;
u8 unk_0x50; u8 mbColorPass;
u8 unk_0x51; u8 mbInTag;
u8 unk_0x52; u8 mbHoverOffset;
u8 unk_0x53; u8 mbFocusEnabled;
}; };
} // namespace scene } // namespace scene
} // namespace ipl } // namespace ipl

View File

@@ -65,7 +65,11 @@ namespace ipl {
virtual BOOL isReady() const { return FALSE; } virtual BOOL isReady() const { return FALSE; }
/** @brief If the user can power off/reset the system */ /** @brief If the user can power off/reset the system */
#ifdef IPL_SD_CHANNEL_TITLE_CPP
virtual BOOL isResetAcceptable() { return TRUE; }
#else
virtual BOOL isResetAcceptable() const { return TRUE; } virtual BOOL isResetAcceptable() const { return TRUE; }
#endif
/** @brief The scene running code when powering off/resetting the system */ /** @brief The scene running code when powering off/resetting the system */
virtual void startResetting() {} virtual void startResetting() {}
/** @brief If the scene has finished its powering off/resetting task */ /** @brief If the scene has finished its powering off/resetting task */

View File

@@ -102,12 +102,7 @@ namespace ipl {
static const char* getButtonName(int button) { return smButtonName[button]; } static const char* getButtonName(int button) { return smButtonName[button]; }
#endif #endif
#ifdef IPL_SD_CHANNEL_SELECT_CPP void setEventHandler(::gui::EventHandler * event);
void setEventHandler(::gui::EventHandler * event,
::gui::EventHandler * optOutEvent = NULL);
#else
void setEventHandler(::gui::EventHandler * event, ::gui::EventHandler * optOutEvent);
#endif
void setText(const char* paneName, u32 msgId); void setText(const char* paneName, u32 msgId);
void setText(const char* paneName, const wchar_t* text); void setText(const char* paneName, const wchar_t* text);
@@ -150,7 +145,7 @@ namespace ipl {
ANIM_MAX, ANIM_MAX,
}; };
int unk_0x54; int mAnimWait;
layout::Object* mpLayout; // 0x58 layout::Object* mpLayout; // 0x58
nand::LayoutFile* mpLayoutFile; // 0x5C nand::LayoutFile* mpLayoutFile; // 0x5C

View File

@@ -203,9 +203,9 @@ namespace ipl {
bool enqueueLoadNotice(); bool enqueueLoadNotice();
bool enqueuePageNotice(); bool enqueuePageNotice();
bool enqueueResultNotice(u32 result); bool enqueueResultNotice(u32 result);
bool enqueueChannelNotice(u32 controller, u32 page, u32 index, u32 value); bool enqueueChannelNotice(u64 titleId, u32 value);
bool enqueueMoveNotice(u32 controller, u32 page, u32 index); bool enqueueMoveNotice(u32 controller, u32 page, u32 index);
bool enqueueStateNotice(u32 controller, u32 page, u32 index, u32 state); bool enqueueStateNotice(u64 titleId, u32 state);
bool enqueueErrorNotice(u32 page, u32 index); bool enqueueErrorNotice(u32 page, u32 index);
bool enqueueCommandNotice(u32 page, u32 index, u32 command); bool enqueueCommandNotice(u32 page, u32 index, u32 command);
bool enqueueDeleteNotice(u32 controller, u32 page, u32 index); bool enqueueDeleteNotice(u32 controller, u32 page, u32 index);

View File

@@ -62,17 +62,17 @@ namespace ipl {
void start_left_event(const char* paneName); void start_left_event(const char* paneName);
void start_trig_event(const char* paneName); void start_trig_event(const char* paneName);
typedef struct Unk { typedef struct CmdEntry {
int command; // 0x00 int command; // 0x00
u32 msgID; // 0x04 u32 msgID; // 0x04
} Unk; } CmdEntry;
Unk unk_0x64[64]; CmdEntry mCmdQueue[64];
int unk_0x264; int mQueueCapacity;
int unk_0x268; int mQueueCount;
int unk_0x26C; int mQueueRead;
int unk_0x270; int mQueueWrite;
int mSettingArg; // 0x274 int mSettingArg; // 0x274

View File

@@ -89,10 +89,10 @@ namespace ipl {
int mIPLState; // 0x04 int mIPLState; // 0x04
volatile BS2State mState; // 0x08 volatile BS2State mState; // 0x08
bool unk_0x0C; bool mbTickEnabled; // 0x0C
bool unk_0x0D; bool mbUpdateRequested; // 0x0D
bool unk_0x0E; bool mbAbortRequested; // 0x0E
bool unk_0x0F; bool mbRestartRequested; // 0x0F
bool mbIsDiagDisc; // 0x10 bool mbIsDiagDisc; // 0x10
bool mbIncludesSeatTitles; // 0x11 bool mbIncludesSeatTitles; // 0x11
u8* mpBannerBuffer; // 0x14 u8* mpBannerBuffer; // 0x14

View File

@@ -118,26 +118,26 @@ namespace ipl {
public: public:
Base(int chan, KPADStatus& status) { Base(int chan, KPADStatus& status) {
mButton = 0; mButton = 0;
unk_0x08 = 0; mDecideHoldCount = 0;
mLastRumbleTime = 0; mLastRumbleTime = 0;
mRumbleType = -1; mRumbleType = -1;
mChan = chan; mChan = chan;
mType = 2; mType = 2;
unk_0x1C = 0; mbForceInvalid = 0;
KPADEnableDPD(chan); KPADEnableDPD(chan);
unk_0x1D = 0; mbPinch = 0;
unk_0x1E = 0; mbPrevPinch = 0;
unk_0x20 = &status; mpStatus = &status;
} }
Base(int chan, int type, KPADStatus& status) { Base(int chan, int type, KPADStatus& status) {
mButton = 0; mButton = 0;
unk_0x08 = 0; mDecideHoldCount = 0;
mLastRumbleTime = 0; mLastRumbleTime = 0;
mRumbleType = -1; mRumbleType = -1;
mChan = chan; mChan = chan;
mType = type; mType = type;
unk_0x1C = 0; mbForceInvalid = 0;
KPADEnableDPD(chan); KPADEnableDPD(chan);
} }
@@ -152,15 +152,15 @@ namespace ipl {
protected: protected:
u8 mButton; u8 mButton;
u32 unk_0x08; u32 mDecideHoldCount;
OSTick mLastRumbleTime; OSTick mLastRumbleTime;
s32 mRumbleType; s32 mRumbleType;
u32 mChan; u32 mChan;
u32 mType; u32 mType;
u8 unk_0x1C; u8 mbForceInvalid;
u8 unk_0x1D; u8 mbPinch;
u8 unk_0x1E; u8 mbPrevPinch;
KPADStatus* unk_0x20; KPADStatus* mpStatus;
}; };
class Revolution : public Base { class Revolution : public Base {
@@ -206,8 +206,8 @@ namespace ipl {
virtual BOOL isValidDpdClassic() const; virtual BOOL isValidDpdClassic() const;
private: private:
math::VEC2 unk_0x24; math::VEC2 mClassicCursor;
int unk_0x2C; int mClassicCursorTimer;
}; };
class Master : public Interface { class Master : public Interface {
@@ -264,18 +264,18 @@ namespace ipl {
public: public:
Base(int chan, KPADStatus& arg1) { Base(int chan, KPADStatus& arg1) {
mButton = 0; mButton = 0;
unk_0x08 = 0; mDecideHoldCount = 0;
mLastRumbleTime = 0; mLastRumbleTime = 0;
mRumbleType = -1; mRumbleType = -1;
mChan = chan; mChan = chan;
mType = 2; mType = 2;
unk_0x1C = 0; mbForceInvalid = 0;
KPADEnableDPD(chan); KPADEnableDPD(chan);
unk_0x1D = 0; mbPinch = 0;
unk_0x1E = 0; mbPrevPinch = 0;
unk_0x20 = &arg1; mpStatus = &arg1;
} }
virtual ~Base(); // 0x08 virtual ~Base(); // 0x08
@@ -326,15 +326,15 @@ namespace ipl {
// protected: // protected:
u8 mButton; // 0x4 u8 mButton; // 0x4
u32 unk_0x08; // 0x8 u32 mDecideHoldCount; // 0x8
OSTick mLastRumbleTime; // 0xC OSTick mLastRumbleTime; // 0xC
s32 mRumbleType; // 0x10 s32 mRumbleType; // 0x10
u32 mChan; // 0x14 u32 mChan; // 0x14
u32 mType; // 0x18 u32 mType; // 0x18
u8 unk_0x1C; u8 mbForceInvalid;
u8 unk_0x1D; // 0x1D u8 mbPinch; // 0x1D
u8 unk_0x1E; // 0x1E u8 mbPrevPinch; // 0x1E
KPADStatus* unk_0x20; // 0x20 KPADStatus* mpStatus; // 0x20
}; };
class Interface : public Base { class Interface : public Base {
@@ -446,8 +446,8 @@ namespace ipl {
virtual BOOL isValidDpdClassic() const; // 0x8C virtual BOOL isValidDpdClassic() const; // 0x8C
private: private:
math::VEC2 unk_0x24; math::VEC2 mClassicCursor;
int unk_0x2C; int mClassicCursorTimer;
}; };
class Manager { class Manager {

View File

@@ -60,9 +60,9 @@ namespace ipl {
int mMessageID; // 0x08 int mMessageID; // 0x08
int unk_0x0C; int mArg2;
int unk_0x10; int mArg3;
char unk_0x14[4]; char mArg1[4];
u8* mpArcData; // 0x18 u8* mpArcData; // 0x18
u32 mArcSize; // 0x1C u32 mArcSize; // 0x1C

View File

@@ -145,6 +145,13 @@ namespace ipl {
mpCommonFile = commonFile; mpCommonFile = commonFile;
mpLangFile = langFile; mpLangFile = langFile;
} }
#ifdef IPL_CHANNEL_TITLE_NOVTABLE
virtual ~LangFile() {}
virtual void read() {}
virtual bool isFinished() { return false; }
virtual int checkData() { return 0; }
virtual bool isFatalError() { return false; }
#else
virtual ~LangFile(); // 0x08 virtual ~LangFile(); // 0x08
virtual void read(); // 0x0C virtual void read(); // 0x0C
@@ -152,6 +159,7 @@ namespace ipl {
virtual bool isFinished(); // 0x14 virtual bool isFinished(); // 0x14
virtual int checkData(); // 0x18 virtual int checkData(); // 0x18
virtual bool isFatalError(); // 0x1C virtual bool isFatalError(); // 0x1C
#endif
File* getCmnFile() const { return mpCommonFile; } File* getCmnFile() const { return mpCommonFile; }
File* getLangFile() const { return mpLangFile; } File* getLangFile() const { return mpLangFile; }
@@ -165,7 +173,11 @@ namespace ipl {
public: public:
LayoutFile(EGG::Heap* heap, const char* dirName, const char* fileName, ARCHandle* arc, bool bIsNandFile); LayoutFile(EGG::Heap* heap, const char* dirName, const char* fileName, ARCHandle* arc, bool bIsNandFile);
LayoutFile(File* commonFile, File* langFile = NULL) : LangFile(commonFile, langFile) {} LayoutFile(File* commonFile, File* langFile = NULL) : LangFile(commonFile, langFile) {}
#ifdef IPL_CHANNEL_TITLE_NOVTABLE
virtual ~LayoutFile() {} // 0x08
#else
virtual ~LayoutFile(); // 0x08 virtual ~LayoutFile(); // 0x08
#endif
}; };
} // namespace nand } // namespace nand
} // namespace ipl } // namespace ipl

View File

@@ -139,7 +139,7 @@ namespace ipl {
bool received() { return mbReviecedMsg; } bool received() { return mbReviecedMsg; }
void prepNextReceive() { mbReviecedMsg = false; } void prepNextReceive() { mbReviecedMsg = false; }
volatile bool isUnk0xA31() { return unk_0xA31 == false; } volatile bool isReceivingIdle() { return mbReceiving == false; }
BOOL isAppDlEnableLock(u32 appId) { BOOL isAppDlEnableLock(u32 appId) {
utility::autoMutexLock lock(mAutoLock); utility::autoMutexLock lock(mAutoLock);
@@ -175,9 +175,9 @@ namespace ipl {
OSMutex mAutoLock; // 0xA18 OSMutex mAutoLock; // 0xA18
bool mbReviecedMsg; bool mbReviecedMsg;
bool unk_0xA31; bool mbReceiving;
bool mbReceivePaused; // 0xA32 bool mbReceivePaused; // 0xA32
bool unk_0xA33; bool mbNewTitleTblReady;
static Arg smArg; static Arg smArg;

View File

@@ -38,6 +38,19 @@ namespace EGG {
virtual void calc(); // 0x30 virtual void calc(); // 0x30
#ifdef EGG_AUDIO_EXPMGR_NO_INLINE_VIRTUALS
virtual bool startSound(nw4r::snd::SoundHandle* pHandle, u32 id); // 0x34
virtual bool startSound(nw4r::snd::SoundHandle* pHandle, unsigned int id); // 0x38
virtual bool startSound(nw4r::snd::SoundHandle* pHandle, const char* pName); // 0x3C
virtual bool prepareSound(nw4r::snd::SoundHandle* pHandle, u32 id); // 0x44
virtual bool prepareSound(nw4r::snd::SoundHandle* pHandle, unsigned int id); // 0x44
virtual bool prepareSound(nw4r::snd::SoundHandle* pHandle, const char* pName); // 0x48
virtual bool holdSound(nw4r::snd::SoundHandle* pHandle, u32 id); // 0x50
virtual bool holdSound(nw4r::snd::SoundHandle* pHandle, unsigned int id); // 0x50
virtual bool holdSound(nw4r::snd::SoundHandle* pHandle, const char* pName); // 0x58
#else
virtual bool startSound(nw4r::snd::SoundHandle* pHandle, u32 id) { return mSoundArchivePlayer.StartSound(pHandle, id); } // 0x34 virtual bool startSound(nw4r::snd::SoundHandle* pHandle, u32 id) { return mSoundArchivePlayer.StartSound(pHandle, id); } // 0x34
virtual bool startSound(nw4r::snd::SoundHandle* pHandle, unsigned int id) { return mSoundArchivePlayer.StartSound(pHandle, id); } // 0x38 virtual bool startSound(nw4r::snd::SoundHandle* pHandle, unsigned int id) { return mSoundArchivePlayer.StartSound(pHandle, id); } // 0x38
virtual bool startSound(nw4r::snd::SoundHandle* pHandle, const char* pName) NO_INLINE { virtual bool startSound(nw4r::snd::SoundHandle* pHandle, const char* pName) NO_INLINE {
@@ -66,6 +79,7 @@ namespace EGG {
u32 id = changeNameToId(pName); u32 id = changeNameToId(pName);
return mSoundArchivePlayer.HoldSound(pHandle, id); return mSoundArchivePlayer.HoldSound(pHandle, id);
} // 0x58 } // 0x58
#endif
u32 changeNameToId(const char* pName) { return mpArchive->ConvertLabelStringToSoundId(pName); } u32 changeNameToId(const char* pName) { return mpArchive->ConvertLabelStringToSoundId(pName); }
const char* changeIdToName(u32 id) { return mpArchive->GetSoundLabelString(id); } const char* changeIdToName(u32 id) { return mpArchive->GetSoundLabelString(id); }

View File

@@ -19,6 +19,10 @@ namespace EGG {
~SoundHeapMgr() { destroySoundHeap(); } ~SoundHeapMgr() { destroySoundHeap(); }
#ifdef EGG_AUDIO_EXPMGR_NO_INLINE_VIRTUALS
virtual bool loadState(s32 id); // 0x08
virtual s32 getCurrentLevel(); // 0x0C
#else
virtual bool loadState(s32 id) { virtual bool loadState(s32 id) {
#ifdef IPL_SOUND_MATCHING #ifdef IPL_SOUND_MATCHING
if (id > 0 && mHeap.GetCurrentLevel() >= id) { if (id > 0 && mHeap.GetCurrentLevel() >= id) {
@@ -35,6 +39,7 @@ namespace EGG {
} // 0x08 } // 0x08
virtual s32 getCurrentLevel() { return mHeap.GetCurrentLevel(); } // 0x0C virtual s32 getCurrentLevel() { return mHeap.GetCurrentLevel(); } // 0x0C
#endif
s32 saveState() { return mHeap.SaveState(); } s32 saveState() { return mHeap.SaveState(); }

View File

@@ -1,3 +1,5 @@
#define EGG_AUDIO_EXPMGR_NO_INLINE_VIRTUALS
#include <egg/core.h> #include <egg/core.h>
namespace EGG { namespace EGG {

View File

@@ -1120,6 +1120,7 @@ static int __wpformatter(void* (*write_proc)(void*, const wchar_t*, size_t),
case 's': case 's':
if (format.argument_options == wchar_argument) { if (format.argument_options == wchar_argument) {
wchar_t* wcs_ptr = va_arg(args, wchar_t*); wchar_t* wcs_ptr = va_arg(args, wchar_t*);
int wideLength;
if (wcs_ptr == NULL) { if (wcs_ptr == NULL) {
wcs_ptr = L""; wcs_ptr = L"";
@@ -1127,22 +1128,24 @@ static int __wpformatter(void* (*write_proc)(void*, const wchar_t*, size_t),
if (format.alternate_form) { if (format.alternate_form) {
wchar_t first = *wcs_ptr++; wchar_t first = *wcs_ptr++;
num_chars = (unsigned char)first; wideLength = (unsigned char)first;
if (format.precision_specified && num_chars > format.precision) { if (format.precision_specified && wideLength > format.precision) {
num_chars = format.precision; wideLength = format.precision;
} }
} else if (format.precision_specified) { } else if (format.precision_specified) {
num_chars = format.precision; wideLength = format.precision;
if ((string_end = wmemchr((wchar_t*)wcs_ptr, 0, num_chars)) != 0) { if ((string_end = wmemchr((wchar_t*)wcs_ptr, 0, wideLength)) != 0) {
num_chars = string_end - wcs_ptr; wideLength = string_end - wcs_ptr;
} }
} else { } else {
num_chars = wcslen(wcs_ptr); wideLength = wcslen(wcs_ptr);
} }
num_chars = wideLength;
buff_ptr = wcs_ptr; buff_ptr = wcs_ptr;
break; break;
} else { } else {

View File

@@ -1,32 +1,45 @@
// Yes, versions other than 4.3U align by 8.
#if defined(VERSION_43U) #if defined(VERSION_43U)
#pragma function_align 32 #pragma function_align 32
#else #else
#pragma function_align 8 #pragma function_align 8
#endif // VERSION_43U #endif
#include <TRK_Hollywood_Revolution.h> #include <TRK_Hollywood_Revolution.h>
#pragma force_active on #pragma force_active on
// Encapsulating function to get the file to align properly // clang-format off
asm void __targsupp() { asm DSIOResult TRKAccessFile(MessageCommandID cmd, unsigned int handle, int* count, unsigned char* buffer) {
// clang-format off #ifdef __MWERKS__
#ifdef __MWERKS__
nofralloc nofralloc
entry TRKAccessFile twi 31, r0, 0
twi 31, r0, 0 blr
blr #endif
entry TRKOpenFile
twi 31, r0, 0
blr
entry TRKCloseFile
twi 31, r0, 0
blr
entry TRKPositionFile
twi 31, r0, 0
blr
#endif // __MWERKS__
// clang-format on
} }
#pragma function_align 8
asm DSIOResult TRKOpenFile() {
#ifdef __MWERKS__
nofralloc
twi 31, r0, 0
blr
#endif
}
asm DSIOResult TRKCloseFile() {
#ifdef __MWERKS__
nofralloc
twi 31, r0, 0
blr
#endif
}
asm DSIOResult TRKPositionFile() {
#ifdef __MWERKS__
nofralloc
twi 31, r0, 0
blr
#endif
}
// clang-format on

View File

@@ -19,8 +19,13 @@ namespace nw4r {
template <typename T> template <typename T>
class AutoLock : private NonCopyable { class AutoLock : private NonCopyable {
public: public:
#ifdef EGG_AUDIO_EXPMGR_NO_INLINE_VIRTUALS
explicit AutoLock(T& rLockObj);
~AutoLock();
#else
explicit AutoLock(T& rLockObj) : mLockObj(rLockObj) { Lock(rLockObj); } explicit AutoLock(T& rLockObj) : mLockObj(rLockObj) { Lock(rLockObj); }
~AutoLock() { Unlock(mLockObj); } ~AutoLock() { Unlock(mLockObj); }
#endif
private: private:
T& mLockObj; // 0x00 T& mLockObj; // 0x00

View File

@@ -1,13 +1,13 @@
#include <nw4r/db/assert.h> #include <nw4r/db/assert.h>
extern "C" const u8 scLytFatalColorR = 255; extern "C" const u8 scLytFatalColorR;
extern "C" const u8 scLytFatalColorG = 255; extern "C" const u8 scLytFatalColorG;
extern "C" const u8 scLytFatalColorB = 255; extern "C" const u8 scLytFatalColorB;
extern "C" const u8 scLytFatalColorA = 0; extern "C" const u8 scLytFatalColorA;
extern "C" char scLytFatalMsg[] = "Error#004\nAn error has occurred.\nThe system files are corrupted."; extern "C" char scLytFatalMsg[] = "Error#004\nAn error has occurred.\nThe system files are corrupted.";
#undef NW4R_ASSERT #undef NW4R_ASSERT
#define NW4R_ASSERT(x) \ #define NW4R_GLOBAL_ASSERT(x) \
{ \ { \
if (!(x)) { \ if (!(x)) { \
GXColor front = {*((volatile const u8*)&::scLytFatalColorR), *((volatile const u8*)&::scLytFatalColorG), \ GXColor front = {*((volatile const u8*)&::scLytFatalColorR), *((volatile const u8*)&::scLytFatalColorG), \
@@ -17,6 +17,15 @@ extern "C" char scLytFatalMsg[] = "Error#004\nAn error has occurred.\nThe system
} \ } \
} }
#define NW4R_ASSERT(x) \
{ \
if (!(x)) { \
GXColor front = {255, 255, 255, 0}; \
GXColor back = {0, 0, 0, 0}; \
OSFatal((GXColor)front, (GXColor)back, ::scLytFatalMsg); \
} \
}
#include <nw4r/lyt/window.h> #include <nw4r/lyt/window.h>
#include <nw4r/lyt/common.h> #include <nw4r/lyt/common.h>
@@ -488,7 +497,7 @@ namespace nw4r {
} }
Material* Window::GetFrameMaterial(u32 frameIdx) const { Material* Window::GetFrameMaterial(u32 frameIdx) const {
NW4R_ASSERT(frameIdx < WINDOWFRAME_MAX); NW4R_GLOBAL_ASSERT(frameIdx < WINDOWFRAME_MAX);
if (frameIdx >= mFrameNum) { if (frameIdx >= mFrameNum) {
return NULL; return NULL;
} }
@@ -501,3 +510,8 @@ namespace nw4r {
} }
} // namespace lyt } // namespace lyt
} // namespace nw4r } // namespace nw4r
extern "C" const u8 scLytFatalColorR = 255;
extern "C" const u8 scLytFatalColorG = 255;
extern "C" const u8 scLytFatalColorB = 255;
extern "C" const u8 scLytFatalColorA = 0;

View File

@@ -314,7 +314,7 @@ namespace nw4r {
ArchiveFontBase::ConstructState ArchiveFontBase::ConstructOpAnalyzeGLGR(ConstructContext* ctx, CachedStreamReader* reader) { ArchiveFontBase::ConstructState ArchiveFontBase::ConstructOpAnalyzeGLGR(ConstructContext* ctx, CachedStreamReader* reader) {
u32 glgrInnerLen; u32 glgrInnerLen;
HeaderedGlyphGroups* pGlgr; HeaderedGlyphGroups* pGlgr;
ArchiveFontBinaryLayout* font; const ArchiveFontBinaryLayout* font;
u8* glgrEnd; u8* glgrEnd;
u32 expectedMaxSize; u32 expectedMaxSize;
@@ -337,7 +337,7 @@ namespace nw4r {
// Copy the glgr to work // Copy the glgr to work
{ {
pGlgr = &font->glgr; pGlgr = (HeaderedGlyphGroups*)&font->glgr;
glgrEnd = (u8*)pGlgr + (u32)ctx->mNextBlockHdr.size; glgrEnd = (u8*)pGlgr + (u32)ctx->mNextBlockHdr.size;
memcpy(pGlgr, &ctx->mNextBlockHdr, sizeof(BinaryBlockHeader)); memcpy(pGlgr, &ctx->mNextBlockHdr, sizeof(BinaryBlockHeader));
@@ -368,21 +368,21 @@ namespace nw4r {
u32 sheetOffsetsScratchSize; u32 sheetOffsetsScratchSize;
dataBlockCount = font->hdr.dataBlocks; // 0x0E
sheetGlyphCount = font->glgr.inner.sheetGlyphCount; // 0x1C sheetGlyphCount = font->glgr.inner.sheetGlyphCount; // 0x1C
dataBlockCount = font->hdr.dataBlocks; // 0x0E
// countName = font->glgr.inner.nameCount; // countName = font->glgr.inner.nameCount;
countSheet = font->glgr.inner.sheetCount; countSheet = font->glgr.inner.sheetCount;
// count0A = font->glgr.inner.smthCount_0x0a; // count0A = font->glgr.inner.smthCount_0x0a;
// count0C = font->glgr.inner.smthCount_0x0c; // count0C = font->glgr.inner.smthCount_0x0c;
sheetOffsetsSize = ROUNDUP(countSheet * sizeof(u16), 4);
sheetOffsetsScratch = (u16*)ROUNDDOWN((u32)((u8*)font + ctx->remWorkSpace()) - sheetOffsetsSize, 2);
stepSheetFlags = detail::CalcSizeFlagSet(countSheet); stepSheetFlags = detail::CalcSizeFlagSet(countSheet);
flagsSheetsOff = detail::CalcOffsetSheetFlags(font->glgr.inner.nameCount, countSheet, font->glgr.inner.smthCount_0x0a, flagsSheetsOff = detail::CalcOffsetSheetFlags(font->glgr.inner.nameCount, countSheet, font->glgr.inner.smthCount_0x0a,
font->glgr.inner.smthCount_0x0c); font->glgr.inner.smthCount_0x0c);
flagsSheets = (const u32*)font + (flagsSheetsOff >> 2); flagsSheets = (const u32*)font + (flagsSheetsOff >> 2);
pGlgr = &font->glgr; sheetOffsetsSize = ROUNDUP(countSheet * sizeof(u16), 4);
sheetOffsetsScratch = (u16*)ROUNDDOWN((u32)((u8*)font + ctx->remWorkSpace()) - sheetOffsetsSize, 2);
pGlgr = (HeaderedGlyphGroups*)&font->glgr;
ENSURE_WORK_HAS_SIZE(ctx, glgrEnd - (u8*)font + sheetOffsetsSize); ENSURE_WORK_HAS_SIZE(ctx, glgrEnd - (u8*)font + sheetOffsetsSize);
// if (ctx->pWorkEnd - workCurr < fontSizeToEndOfGlgr + sheetOffsetsSize) { // if (ctx->pWorkEnd - workCurr < fontSizeToEndOfGlgr + sheetOffsetsSize) {
// return CONSTRUCT_STATE_FATAL_ERR; // return CONSTRUCT_STATE_FATAL_ERR;

View File

@@ -63,7 +63,7 @@ typedef struct {
u8 mcuYRem; // 0x0F u8 mcuYRem; // 0x0F
u16 mcuYCount; // 0x10 u16 mcuYCount; // 0x10
u16 mcuXCount2; // 0x12 u16 mcuXCount2; // 0x12
u32 unk_0x14; u32 mcuTotal; // 0x14
u8 remX; // 0x18 u8 remX; // 0x18
u8 remY; // 0x19 u8 remY; // 0x19
u8 compCount; // 0x1A u8 compCount; // 0x1A
@@ -142,7 +142,7 @@ struct TMCCJPEGDecWork_t {
u8 mcuYRem; // 0x17FF u8 mcuYRem; // 0x17FF
u16 mcuYCount; // 0x1800 u16 mcuYCount; // 0x1800
u16 mcuXCount2; // 0x1802 u16 mcuXCount2; // 0x1802
u32 unk_0x1804; u32 mcuTotal; // 0x1804
u8 remX; // 0x1808 u8 remX; // 0x1808
u8 remY; // 0x1809 u8 remY; // 0x1809
u8 compCount; // 0x180A u8 compCount; // 0x180A

View File

@@ -10,14 +10,12 @@ static TMCHuffmanEntry readHuffmanEntry(const TMCHuffmanEntry* entries, u32 inde
return entries[index]; return entries[index];
} }
static TMCHuffmanEntry readHuffmanLimit(const TMCHuffmanEntry* entries) { static void readHuffmanLimit(const TMCHuffmanEntry* entries, TMCHuffmanEntry* limit) {
TMCHuffmanEntry limit; limit->bitLength = entries->bitLength;
limit.bitLength = entries->bitLength; limit->symbol = entries->symbol;
limit.symbol = entries->symbol;
return limit;
} }
static inline s32 decodeLongHuffman(s32 bitCount, const TMCHuffmanEntry* table, const u8* symbols, TMCCJPEGDecWork* work) { static inline s32 decodeLongHuffman(s32 bitCount, const TMCHuffmanEntry* table, const u8* symbols, TMCCJPEGDecWork* work, TMCHuffmanEntry* limit, TMCHuffmanEntry* decoded) {
u32 bitData; u32 bitData;
u32 code; u32 code;
u32 length; u32 length;
@@ -51,17 +49,21 @@ static inline s32 decodeLongHuffman(s32 bitCount, const TMCHuffmanEntry* table,
code |= (bitData >> bitCount) & 1; code |= (bitData >> bitCount) & 1;
read_entry: read_entry:
{ {
TMCHuffmanEntry decoded = readHuffmanLimit(entry); readHuffmanLimit(entry, limit);
if (code > (u32)decoded.bitLength) { *decoded = *limit;
if (code > (u32)decoded->bitLength) {
continue; continue;
} }
code = code - entry->bitLength + entry->symbol; {
return symbols[code & 0xFF]; u32 relativeCode = code - entry->bitLength;
u32 symbolIndex = relativeCode + entry->symbol;
return symbols[symbolIndex & 0xFF];
}
} }
} }
} }
static inline s32 decodeACHuffman(s32 bitCount, const TMCHuffmanEntry* entry, const u8* symbols, TMCCJPEGDecWork* work) { static inline s32 decodeACHuffman(s32 bitCount, const TMCHuffmanEntry* entry, const u8* symbols, TMCCJPEGDecWork* work, TMCHuffmanEntry* limit, TMCHuffmanEntry* decoded) {
u32 bitData; u32 bitData;
u32 code; u32 code;
u32 length; u32 length;
@@ -94,33 +96,41 @@ static inline s32 decodeACHuffman(s32 bitCount, const TMCHuffmanEntry* entry, co
code |= (bitData >> bitCount) & 1; code |= (bitData >> bitCount) & 1;
read_entry: read_entry:
{ {
TMCHuffmanEntry decoded = readHuffmanLimit(entry); readHuffmanLimit(entry, limit);
if (code > (u32)decoded.bitLength) { *decoded = *limit;
if (code > (u32)decoded->bitLength) {
continue; continue;
} }
code = code - entry->bitLength + entry->symbol; {
return symbols[code & 0xFF]; u32 relativeCode = code - entry->bitLength;
u32 symbolIndex = relativeCode + entry->symbol;
return symbols[symbolIndex & 0xFF];
}
} }
} }
} }
s32 TMCJPEGDEC_decode_iquant(s32* block, u8* conv_row_ptr, u32* dc_predict_row_ptr, TMCCJPEGDecWork* work) { s32 TMCJPEGDEC_decode_iquant(s32* block, u8* conv_row_ptr, u32* dc_predict_row_ptr, TMCCJPEGDecWork* work) {
TMCHuffmanEntry dcEntry; TMCHuffmanEntry dcEntry;
TMCHuffmanEntry acEntry; TMCHuffmanEntry dcDecoded;
const TMCHuffmanEntry* ac_fast; TMCHuffmanEntry dcLimit;
TMCHuffmanEntry acDecoded;
TMCHuffmanEntry acLimit;
u8* huff_sym; u8* huff_sym;
const TMCHuffmanEntry* ac_fast;
s32 idx;
u32* huff_tbl; u32* huff_tbl;
s32 bit_pos; s32 bit_pos;
u32 bit_data; u32 bit_data;
const TMCHuffmanEntry* dc_fast; u32 tmp;
s32 r; s32 r;
s32 blk0; s32 blk0;
s32 idx; TMCHuffmanEntry acEntry;
s32 extra; s32 extra;
s32 t; s32 t;
s32 zz; s32 zz;
s32 q; s32 q;
u32 tmp; const TMCHuffmanEntry* dc_fast;
const u8* zztbl; const u8* zztbl;
bit_pos = work->bitCount; bit_pos = work->bitCount;
@@ -135,22 +145,19 @@ s32 TMCJPEGDEC_decode_iquant(s32* block, u8* conv_row_ptr, u32* dc_predict_row_p
bit_pos = work->bitCount; bit_pos = work->bitCount;
bit_data = work->bitBuf; bit_data = work->bitBuf;
tmp = bit_pos - 8;
tmp = ((bit_data >> tmp) & 0xFF) << 2;
{ {
dcEntry = readHuffmanEntry(dc_fast, tmp >> 2); dcEntry = readHuffmanEntry(dc_fast, (bit_data >> (bit_pos - 8)) & 0xFF);
r = dcEntry.bitLength; r = dcEntry.bitLength;
extra = dcEntry.symbol; extra = dcEntry.symbol;
} }
if (r != 0) { if (r != 0) {
bit_pos -= r; work->bitCount = bit_pos - r;
work->bitCount = bit_pos;
r = extra; r = extra;
} else { } else {
huff_sym = work->pDCHuffSym; huff_sym = work->pDCHuffSym;
huff_tbl = work->pDCHuffTbl; huff_tbl = work->pDCHuffTbl;
r = decodeLongHuffman(bit_pos, (const TMCHuffmanEntry*)huff_tbl, huff_sym, work); r = decodeLongHuffman(bit_pos, (const TMCHuffmanEntry*)huff_tbl, huff_sym, work, &dcLimit, &dcDecoded);
if (r < 0) { if (r < 0) {
return r; return r;
} }
@@ -210,7 +217,7 @@ s32 TMCJPEGDEC_decode_iquant(s32* block, u8* conv_row_ptr, u32* dc_predict_row_p
r = acEntry.symbol; r = acEntry.symbol;
} else { } else {
bit_pos = work->bitCount; bit_pos = work->bitCount;
r = decodeACHuffman(bit_pos, (const TMCHuffmanEntry*)huff_tbl, huff_sym, work); r = decodeACHuffman(bit_pos, (const TMCHuffmanEntry*)huff_tbl, huff_sym, work, &acLimit, &acDecoded);
if (r < 0) { if (r < 0) {
return r; return r;
} }

View File

@@ -16,7 +16,7 @@ static u16 readU16(const u8* p, u16 byteOrder) {
} }
static u16 readExifU16(const u8* data, u16 byteOrder) { static u16 readExifU16(const u8* data, u16 byteOrder) {
u32 value = data[0] | data[1] << 8; u16 value = data[0] | data[1] << 8;
if (byteOrder == 0x4949) { if (byteOrder == 0x4949) {
return (u16)value; return (u16)value;
} }
@@ -246,9 +246,9 @@ static s32 TMCJPEGDEC_exif_parse(const u8* data, u32 size, TMCCJPEGDecExifData*
u32 ifdOffset; u32 ifdOffset;
const u8* entries; const u8* entries;
u16 remaining; u16 remaining;
u16 count;
s32 entriesSize;
u16 index; u16 index;
s32 entriesSize;
u16 count;
pInfo->thumbnailData = (u8*)data; pInfo->thumbnailData = (u8*)data;
pInfo->dataEnd = (u8*)data + size; pInfo->dataEnd = (u8*)data + size;
pInfo->nextIfdOffset = 0; pInfo->nextIfdOffset = 0;
@@ -339,7 +339,7 @@ static s32 TMCJPEGDEC_exif_parse(const u8* data, u32 size, TMCCJPEGDecExifData*
} }
static void TMCJPEGDEC_IFD0_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder, const u8* entry) { static void TMCJPEGDEC_IFD0_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder, const u8* entry) {
u16 tag; s32 tag;
u16 type; u16 type;
tag = readU16(entry, byteOrder); tag = readU16(entry, byteOrder);

View File

@@ -51,7 +51,7 @@ s32 TMCJPEGDEC_Setsize(TMCCJPEGDecWork* work) {
} }
state->componentCount = work->componentCount; state->componentCount = work->componentCount;
state->result = work->unk_0x1804; state->result = work->mcuTotal;
state->maxX = work->mcuYCount; state->maxX = work->mcuYCount;
state->maxY = work->mcuXCount2; state->maxY = work->mcuXCount2;

View File

@@ -567,7 +567,7 @@ s32 TMCJPEGDEC_scan_varinit(TMCCJPEGDecWork* work) {
p->mcuYCount = p->mcuYCount + ((u8)remX != 0 ? 1 : 0); p->mcuYCount = p->mcuYCount + ((u8)remX != 0 ? 1 : 0);
p->mcuXCount2 = p->mcuXCount2 + ((u8)remY != 0 ? 1 : 0); p->mcuXCount2 = p->mcuXCount2 + ((u8)remY != 0 ? 1 : 0);
p->unk_0x14 = (u32)p->mcuYCount * (u32)p->mcuXCount2; p->mcuTotal = (u32)p->mcuYCount * (u32)p->mcuXCount2;
for (idx = 0; idx < (s32)p->scanCompCount; idx++) { for (idx = 0; idx < (s32)p->scanCompCount; idx++) {
u8 compId; u8 compId;
@@ -1929,7 +1929,7 @@ static s32 TMCJPEGDEC_parse_sof(TMCCJPEGDecWork* work) {
mcuCountY += yr; mcuCountY += yr;
frameInfo->mcuYCount = mcuCountX; frameInfo->mcuYCount = mcuCountX;
frameInfo->mcuXCount2 = mcuCountY; frameInfo->mcuXCount2 = mcuCountY;
work->unk_0x1804 = (u32)mcuCountX * (u32)mcuCountY; work->mcuTotal = (u32)mcuCountX * (u32)mcuCountY;
} }
compCount2 = frameInfo->compCount; compCount2 = frameInfo->compCount;

View File

@@ -15,9 +15,13 @@ static s8 clampS8(s32 v) {
void TMCJPEGDEC_IdctBlock4x4(s32* block, u8* conv_row_ptr, u16 pitch, s32 zigzag) { void TMCJPEGDEC_IdctBlock4x4(s32* block, u8* conv_row_ptr, u16 pitch, s32 zigzag) {
s32 bd; s32 bd;
s32 d;
s32 c; s32 c;
s32 a; s32 a;
s32 cd;
s32 oddrot;
s32 evsum;
s32 rot;
s32 d;
s32 b; s32 b;
s32* sp; s32* sp;
@@ -26,57 +30,41 @@ void TMCJPEGDEC_IdctBlock4x4(s32* block, u8* conv_row_ptr, u16 pitch, s32 zigzag
s32 tmp[64]; s32 tmp[64];
s32 i; s32 i;
s32 evsum, rot, oddrot, cd;
sp = block + 24; sp = block + 24;
dp = tmp + 24; dp = tmp + 24;
for (i = 0; i < 2; i++) { for (i = 0; i < 4; i++) {
a = sp[0]; // 0x0 s32 a, b, c, d;
b = sp[1]; // 0x4 s32 odddiff, bd, evsum, cd, rot, oddrot;
c = sp[2]; // 0x8 a = sp[0];
d = sp[3]; // 0xc b = sp[1];
c = sp[2];
d = sp[3];
odddiff = b - d;
bd = b + d; bd = b + d;
evsum = a + c; evsum = a + c;
cd = a - c;
oddrot = (0xB5 * (sp[1] - sp[3]) >> 8) + bd; rot = (odddiff * 0xB5) >> 8;
rot = (0xB5 * (sp[1] - sp[3])) >> 8;
dp[1] = (a - c) + rot;
dp[2] = (a - c) - rot;
dp[3] = evsum - oddrot;
dp[0] = evsum + oddrot;
b = sp[-7]; // -0x1c
d = sp[-5]; // -0x14
bd = b + d;
rot = ((b - d) * 0xB5) >> 8;
oddrot = rot + bd; oddrot = rot + bd;
dp[0] = evsum + oddrot;
a = sp[-8]; // -0x20 dp[1] = cd + rot;
c = sp[-6]; // -0x18 dp[2] = cd - rot;
dp[3] = evsum - oddrot;
dp[-8] = (a + c) + oddrot; sp -= 8;
dp[-7] = (a - c) + rot; dp -= 8;
dp[-6] = (a - c) - rot;
dp[-5] = (a + c) - oddrot;
sp -= 16;
dp -= 16;
} }
{ {
u32 idx = 3; u32 idx = 3;
sp = tmp + 3;
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
u8* bp = conv_row_ptr + idx; u8* bp = conv_row_ptr + idx;
a = sp[0] + 0x40000; a = tmp[idx] + 0x40000;
b = sp[8]; b = tmp[idx + 8];
d = sp[24]; d = tmp[idx + 24];
c = sp[16]; c = tmp[idx + 16];
evsum = a + c; evsum = a + c;
cd = a - c; cd = a - c;
@@ -90,7 +78,6 @@ void TMCJPEGDEC_IdctBlock4x4(s32* block, u8* conv_row_ptr, u16 pitch, s32 zigzag
bp[pitch * 2] = clampU8((cd - rot) >> 11); bp[pitch * 2] = clampU8((cd - rot) >> 11);
bp[pitch * 4 - pitch] = clampU8((evsum - oddrot) >> 11); bp[pitch * 4 - pitch] = clampU8((evsum - oddrot) >> 11);
sp--;
idx -= 1; idx -= 1;
} }
} }
@@ -131,38 +118,37 @@ void TMCJPEGDEC_IdctBlock4x4_Col(s32* sp, u8* conv_row_ptr, u16 pitch, s32 zigza
s32 a, b, c, d; s32 a, b, c, d;
s32 evsum, evdiff, oddsum, odddiff, rot, oddrot; s32 evsum, evdiff, oddsum, odddiff, rot, oddrot;
for (i = 0; i < 2; i++) { for (i = 0; i < 4; i++) {
s32 a0 = src[0], b0 = src[1], c0 = src[2], d0 = src[3]; a = src[0];
s32 a1 = src[-8], b1 = src[-7], c1 = src[-6], d1 = src[-5]; b = src[1];
c = src[2];
s32 odddiff0 = b0 - d0; d = src[3];
s32 oddsum0 = b0 + d0; odddiff = b - d;
s32 evsum0 = a0 + c0; oddsum = b + d;
s32 evdiff0 = a0 - c0; evsum = a + c;
s32 rot0 = (odddiff0 * 0xB5) >> 8; evdiff = a - c;
rot = (odddiff * 0xB5) >> 8;
s32 odddiff1 = b1 - d1; oddrot = rot + oddsum;
s32 oddsum1 = b1 + d1; dst[0] = evsum + oddrot;
s32 evsum1 = a1 + c1; dst[1] = evdiff + rot;
s32 evdiff1 = a1 - c1; dst[2] = evdiff - rot;
s32 rot1 = (odddiff1 * 0xB5) >> 8; dst[3] = evsum - oddrot;
src -= 8;
dst[0] = evsum0 + (oddsum0 + rot0); dst -= 8;
dst[1] = evdiff0 + rot0;
dst[2] = evdiff0 - rot0;
dst[3] = evsum0 - (oddsum0 + rot0);
dst[-8] = evsum1 + (oddsum1 + rot1);
dst[-7] = evdiff1 + rot1;
dst[-6] = evdiff1 - rot1;
dst[-5] = evsum1 - (oddsum1 + rot1);
src -= 16;
dst -= 16;
} }
src = tmp + 3; src = tmp + 3;
for (i = 3; i >= 0; i--) { for (i = 3; i >= 0; i--) {
s32 evdiff;
s32 a;
s32 c;
s32 b;
s32 evsum;
s32 d;
s32 oddsum;
s32 odddiff;
s32 rot;
s32 oddrot;
u8* out = conv_row_ptr + i; u8* out = conv_row_ptr + i;
a = src[0]; a = src[0];
b = src[8]; b = src[8];
@@ -170,7 +156,7 @@ void TMCJPEGDEC_IdctBlock4x4_Col(s32* sp, u8* conv_row_ptr, u16 pitch, s32 zigza
d = src[24]; d = src[24];
odddiff = b - d; odddiff = b - d;
oddsum = b + d; oddsum = d + b;
evsum = a + c; evsum = a + c;
evdiff = a - c; evdiff = a - c;
rot = odddiff * 0xB5 >> 8; rot = odddiff * 0xB5 >> 8;

View File

@@ -166,23 +166,23 @@ s32 TMCJPEGDEC_set_converterRGBA8(TMCCJPEGDecWork* work) {
} }
static void TMCJPEGDEC_converterYUV411toRGBA8(TMCCJPEGDecWork* work, s32 x, s32 y) { static void TMCJPEGDEC_converterYUV411toRGBA8(TMCCJPEGDecWork* work, s32 x, s32 y) {
s8 crValue; s32 red;
u8* luminance; u8* luminance;
u8* cb; u8* cb;
u8* cr; u8* cr;
TMCCJPEGDecState* state; TMCCJPEGDecState* state;
u8* texture; u8* texture;
s32 height; s32 height;
s32 yEnd; s32 column;
s32 xEnd; s32 xEnd;
s32 green; s32 green;
s32 column; s32 yEnd;
s32 tileWidth; s32 tileWidth;
s32 blueOffset; s32 blueOffset;
u16* output; u16* output;
s32 tileRow; s32 tileRow;
s32 lumaSkip; s32 lumaSkip;
s32 red; s8 crValue;
s32 chromaSkip; s32 chromaSkip;
s32 width; s32 width;
s32 cbValue; s32 cbValue;
@@ -216,7 +216,7 @@ static void TMCJPEGDEC_converterYUV411toRGBA8(TMCCJPEGDecWork* work, s32 x, s32
cbValue = (s8)*cb++; cbValue = (s8)*cb++;
crValue = (s8)*cr++; crValue = (s8)*cr++;
redOffset = (crValue * 359) >> 8; redOffset = (crValue * 359) >> 8;
greenOffset = -(cbValue * 88 + crValue * 183) >> 8; greenOffset = -(crValue * 183 + cbValue * 88) >> 8;
blueOffset = (cbValue * 454) >> 8; blueOffset = (cbValue * 454) >> 8;
} }
{ {
@@ -224,7 +224,7 @@ static void TMCJPEGDEC_converterYUV411toRGBA8(TMCCJPEGDecWork* work, s32 x, s32
green = value + greenOffset; green = value + greenOffset;
red = value + redOffset; red = value + redOffset;
blue = value + blueOffset; blue = value + blueOffset;
if ((blue | green | red) >> 8) { if ((red | green | blue) >> 8) {
blue = blue > 255 ? 255 : blue < 0 ? 0 : blue; blue = blue > 255 ? 255 : blue < 0 ? 0 : blue;
green = green > 255 ? 255 : green < 0 ? 0 : green; green = green > 255 ? 255 : green < 0 ? 0 : green;
red = red > 255 ? 255 : red < 0 ? 0 : red; red = red > 255 ? 255 : red < 0 ? 0 : red;
@@ -238,7 +238,7 @@ static void TMCJPEGDEC_converterYUV411toRGBA8(TMCCJPEGDecWork* work, s32 x, s32
green = value + greenOffset; green = value + greenOffset;
red = value + redOffset; red = value + redOffset;
blue = value + blueOffset; blue = value + blueOffset;
if ((blue | green | red) >> 8) { if ((red | green | blue) >> 8) {
blue = blue > 255 ? 255 : blue < 0 ? 0 : blue; blue = blue > 255 ? 255 : blue < 0 ? 0 : blue;
green = green > 255 ? 255 : green < 0 ? 0 : green; green = green > 255 ? 255 : green < 0 ? 0 : green;
red = red > 255 ? 255 : red < 0 ? 0 : red; red = red > 255 ? 255 : red < 0 ? 0 : red;
@@ -252,7 +252,7 @@ static void TMCJPEGDEC_converterYUV411toRGBA8(TMCCJPEGDecWork* work, s32 x, s32
green = value + greenOffset; green = value + greenOffset;
red = value + redOffset; red = value + redOffset;
blue = value + blueOffset; blue = value + blueOffset;
if ((blue | green | red) >> 8) { if ((red | green | blue) >> 8) {
blue = blue > 255 ? 255 : blue < 0 ? 0 : blue; blue = blue > 255 ? 255 : blue < 0 ? 0 : blue;
green = green > 255 ? 255 : green < 0 ? 0 : green; green = green > 255 ? 255 : green < 0 ? 0 : green;
red = red > 255 ? 255 : red < 0 ? 0 : red; red = red > 255 ? 255 : red < 0 ? 0 : red;
@@ -266,7 +266,7 @@ static void TMCJPEGDEC_converterYUV411toRGBA8(TMCCJPEGDecWork* work, s32 x, s32
green = value + greenOffset; green = value + greenOffset;
red = value + redOffset; red = value + redOffset;
blue = value + blueOffset; blue = value + blueOffset;
if ((blue | green | red) >> 8) { if ((red | green | blue) >> 8) {
blue = blue > 255 ? 255 : blue < 0 ? 0 : blue; blue = blue > 255 ? 255 : blue < 0 ? 0 : blue;
green = green > 255 ? 255 : green < 0 ? 0 : green; green = green > 255 ? 255 : green < 0 ? 0 : green;
red = red > 255 ? 255 : red < 0 ? 0 : red; red = red > 255 ? 255 : red < 0 ? 0 : red;
@@ -285,20 +285,20 @@ static void TMCJPEGDEC_converterYUV411toRGBA8(TMCCJPEGDecWork* work, s32 x, s32
} }
static void TMCJPEGDEC_converterYUV411toRGBA8edge(TMCCJPEGDecWork* work, s32 x, s32 y) { static void TMCJPEGDEC_converterYUV411toRGBA8edge(TMCCJPEGDecWork* work, s32 x, s32 y) {
s32 column;
u8* luminance;
u8* cb;
u8* cr;
TMCCJPEGDecState* state;
s32 tileWidth;
u8* texture;
s32 width;
s32 height;
s32 xEnd;
s32 yEnd;
s32 lumaSkip;
s32 chromaSkip; s32 chromaSkip;
s32 tileRow; s32 tileRow;
s32 xEnd;
u8* texture;
TMCCJPEGDecState* state;
u8* luminance;
u8* cb;
s32 width;
s32 height;
u8* cr;
s32 column;
s32 lumaSkip;
s32 yEnd;
s32 tileWidth;
u16* output; u16* output;
s32 cbValue; s32 cbValue;
s8 crValue; s8 crValue;
@@ -345,7 +345,7 @@ static void TMCJPEGDEC_converterYUV411toRGBA8edge(TMCCJPEGDecWork* work, s32 x,
red = blue + redOffset; red = blue + redOffset;
green = blue + greenOffset; green = blue + greenOffset;
blue = blue + blueOffset; blue = blue + blueOffset;
if ((blue | red | green) >> 8) { if ((green | red | blue) >> 8) {
blue = blue > 255 ? 255 : blue < 0 ? 0 : blue; blue = blue > 255 ? 255 : blue < 0 ? 0 : blue;
green = green > 255 ? 255 : green < 0 ? 0 : green; green = green > 255 ? 255 : green < 0 ? 0 : green;
red = red > 255 ? 255 : red < 0 ? 0 : red; red = red > 255 ? 255 : red < 0 ? 0 : red;
@@ -366,11 +366,11 @@ static void TMCJPEGDEC_converterYUV411toRGBA8edge(TMCCJPEGDecWork* work, s32 x,
static void TMCJPEGDEC_converterYUV422toRGBA8(TMCCJPEGDecWork* work, s32 x, s32 y) { static void TMCJPEGDEC_converterYUV422toRGBA8(TMCCJPEGDecWork* work, s32 x, s32 y) {
s32 chromaSkip; s32 chromaSkip;
s32 blue; s32 lumaSkip;
s32 cbValue; s32 cbValue;
s32 tileWidth; s32 tileWidth;
TMCCJPEGDecState* state; TMCCJPEGDecState* state;
s32 xEnd; u16* output;
u8* texture; u8* texture;
s32 width; s32 width;
s32 height; s32 height;
@@ -379,7 +379,7 @@ static void TMCJPEGDEC_converterYUV422toRGBA8(TMCCJPEGDecWork* work, s32 x, s32
s32 red; s32 red;
u8* cr; u8* cr;
s32 column; s32 column;
u16* output; s32 xEnd;
s32 yEnd; s32 yEnd;
s32 redOffset; s32 redOffset;
s32 tileRow; s32 tileRow;
@@ -387,7 +387,7 @@ static void TMCJPEGDEC_converterYUV422toRGBA8(TMCCJPEGDecWork* work, s32 x, s32
s32 blueOffset; s32 blueOffset;
s32 value; s32 value;
s32 green; s32 green;
s32 lumaSkip; s32 blue;
s32 crValue; s32 crValue;
luminance = work->convBuf + 4; luminance = work->convBuf + 4;
@@ -415,7 +415,7 @@ static void TMCJPEGDEC_converterYUV422toRGBA8(TMCCJPEGDecWork* work, s32 x, s32
green = value + greenOffset; green = value + greenOffset;
red = value + redOffset; red = value + redOffset;
blue = value + blueOffset; blue = value + blueOffset;
if ((blue | red | green) >> 8) { if ((red | green | blue) >> 8) {
blue = blue > 255 ? 255 : blue < 0 ? 0 : blue; blue = blue > 255 ? 255 : blue < 0 ? 0 : blue;
green = green > 255 ? 255 : green < 0 ? 0 : green; green = green > 255 ? 255 : green < 0 ? 0 : green;
red = red > 255 ? 255 : red < 0 ? 0 : red; red = red > 255 ? 255 : red < 0 ? 0 : red;
@@ -426,7 +426,7 @@ static void TMCJPEGDEC_converterYUV422toRGBA8(TMCCJPEGDecWork* work, s32 x, s32
green = value + greenOffset; green = value + greenOffset;
red = value + redOffset; red = value + redOffset;
blue = value + blueOffset; blue = value + blueOffset;
if ((blue | red | green) >> 8) { if ((red | green | blue) >> 8) {
blue = blue > 255 ? 255 : blue < 0 ? 0 : blue; blue = blue > 255 ? 255 : blue < 0 ? 0 : blue;
green = green > 255 ? 255 : green < 0 ? 0 : green; green = green > 255 ? 255 : green < 0 ? 0 : green;
red = red > 255 ? 255 : red < 0 ? 0 : red; red = red > 255 ? 255 : red < 0 ? 0 : red;
@@ -441,21 +441,21 @@ static void TMCJPEGDEC_converterYUV422toRGBA8(TMCCJPEGDecWork* work, s32 x, s32
} }
static void TMCJPEGDEC_converterYUV422toRGBA8edge(TMCCJPEGDecWork* work, s32 x, s32 y) { static void TMCJPEGDEC_converterYUV422toRGBA8edge(TMCCJPEGDecWork* work, s32 x, s32 y) {
s32 column; s32 blue;
u8* luminance; u16* output;
u8* cb; s32 xEnd;
u8* cr; u8* cr;
TMCCJPEGDecState* state; TMCCJPEGDecState* state;
s32 tileWidth; s32 tileWidth;
u8* texture; u8* luminance;
s32 width; s32 width;
s32 height; s32 height;
s32 xEnd; u8* cb;
s32 yEnd; u8* texture;
s32 lumaSkip; s32 column;
s32 chromaSkip; s32 chromaSkip;
s32 yEnd;
s32 tileRow; s32 tileRow;
u16* output;
s32 cbValue; s32 cbValue;
s32 crValue; s32 crValue;
s32 redOffset; s32 redOffset;
@@ -463,7 +463,7 @@ static void TMCJPEGDEC_converterYUV422toRGBA8edge(TMCCJPEGDecWork* work, s32 x,
s32 blueOffset; s32 blueOffset;
s32 value; s32 value;
s32 red; s32 red;
s32 blue; s32 lumaSkip;
s32 green; s32 green;
luminance = work->convBuf + 4; luminance = work->convBuf + 4;
@@ -502,7 +502,7 @@ static void TMCJPEGDEC_converterYUV422toRGBA8edge(TMCCJPEGDecWork* work, s32 x,
red = value + redOffset; red = value + redOffset;
blue = value + blueOffset; blue = value + blueOffset;
green = value + greenOffset; green = value + greenOffset;
if ((blue | red | green) >> 8) { if ((red | green | blue) >> 8) {
blue = blue > 255 ? 255 : blue < 0 ? 0 : blue; blue = blue > 255 ? 255 : blue < 0 ? 0 : blue;
green = green > 255 ? 255 : green < 0 ? 0 : green; green = green > 255 ? 255 : green < 0 ? 0 : green;
red = red > 255 ? 255 : red < 0 ? 0 : red; red = red > 255 ? 255 : red < 0 ? 0 : red;
@@ -517,19 +517,19 @@ static void TMCJPEGDEC_converterYUV422toRGBA8edge(TMCCJPEGDecWork* work, s32 x,
} }
static void TMCJPEGDEC_converterYUV420toRGBA8(TMCCJPEGDecWork* work, s32 x, s32 y) { static void TMCJPEGDEC_converterYUV420toRGBA8(TMCCJPEGDecWork* work, s32 x, s32 y) {
s32 blue; s32 tileRow;
s8 crValue; s8 crValue;
s32 chromaSkip; s32 chromaSkip;
u8* luminance; u8* luminance;
TMCCJPEGDecState* state; TMCCJPEGDecState* state;
s32 xEnd; u8* texture;
s32 width; s32 width;
s32 height; s32 height;
s32 blueOffset; s32 green;
u8* texture; s32 blue;
s32 lumaSkip; s32 lumaSkip;
s32 yEnd; s32 yEnd;
s32 tileRow; s32 xEnd;
s32 value; s32 value;
s32 column; s32 column;
u8* cr; u8* cr;
@@ -538,7 +538,7 @@ static void TMCJPEGDEC_converterYUV420toRGBA8(TMCCJPEGDecWork* work, s32 x, s32
s32 redOffset; s32 redOffset;
u8* cb; u8* cb;
u16* output; u16* output;
s32 green; s32 blueOffset;
s32 red; s32 red;
s32 cbValue; s32 cbValue;
@@ -578,7 +578,7 @@ static void TMCJPEGDEC_converterYUV420toRGBA8(TMCCJPEGDecWork* work, s32 x, s32
if ((blue | green | red) >> 8) { if ((red | green | blue) >> 8) {
blue = blue > 255 ? 255 : blue < 0 ? 0 : blue; blue = blue > 255 ? 255 : blue < 0 ? 0 : blue;
green = green > 255 ? 255 : green < 0 ? 0 : green; green = green > 255 ? 255 : green < 0 ? 0 : green;
red = red > 255 ? 255 : red < 0 ? 0 : red; red = red > 255 ? 255 : red < 0 ? 0 : red;
@@ -593,7 +593,7 @@ static void TMCJPEGDEC_converterYUV420toRGBA8(TMCCJPEGDecWork* work, s32 x, s32
green = value + greenOffset; green = value + greenOffset;
red = value + redOffset; red = value + redOffset;
blue = value + blueOffset; blue = value + blueOffset;
if ((blue | green | red) >> 8) { if ((red | green | blue) >> 8) {
blue = blue > 255 ? 255 : blue < 0 ? 0 : blue; blue = blue > 255 ? 255 : blue < 0 ? 0 : blue;
green = green > 255 ? 255 : green < 0 ? 0 : green; green = green > 255 ? 255 : green < 0 ? 0 : green;
red = red > 255 ? 255 : red < 0 ? 0 : red; red = red > 255 ? 255 : red < 0 ? 0 : red;
@@ -620,11 +620,11 @@ static void TMCJPEGDEC_converterYUV420toRGBA8(TMCCJPEGDecWork* work, s32 x, s32
static void TMCJPEGDEC_converterYUV420toRGBA8edge(TMCCJPEGDecWork* work, s32 x, s32 y) { static void TMCJPEGDEC_converterYUV420toRGBA8edge(TMCCJPEGDecWork* work, s32 x, s32 y) {
u8* luminance = work->convBuf + 4; u8* luminance = work->convBuf + 4;
u8* cb = work->convBuf + 260; u8* cb = work->convBuf + 260;
u8* cr = work->convBuf + 324; s32 width;
TMCCJPEGDecState* state = work->pState; TMCCJPEGDecState* state = work->pState;
s32 tileWidth = (state->convWidth >> 2) << 1; s32 tileWidth = (state->convWidth >> 2) << 1;
u8* texture = state->pTexBuffer; u8* texture = state->pTexBuffer;
s32 width; u8* cr = work->convBuf + 324;
s32 height; s32 height;
if (state->dataSizeX == (u32)x) { if (state->dataSizeX == (u32)x) {
width = state->stepXExt; width = state->stepXExt;
@@ -660,7 +660,7 @@ static void TMCJPEGDEC_converterYUV420toRGBA8edge(TMCCJPEGDecWork* work, s32 x,
s32 green = value + greenOffset; s32 green = value + greenOffset;
s32 red = value + redOffset; s32 red = value + redOffset;
s32 blue = value + blueOffset; s32 blue = value + blueOffset;
if ((blue | red | green) >> 8) { if ((green | red | blue) >> 8) {
blue = blue > 255 ? 255 : blue < 0 ? 0 : blue; blue = blue > 255 ? 255 : blue < 0 ? 0 : blue;
green = green > 255 ? 255 : green < 0 ? 0 : green; green = green > 255 ? 255 : green < 0 ? 0 : green;
red = red > 255 ? 255 : red < 0 ? 0 : red; red = red > 255 ? 255 : red < 0 ? 0 : red;
@@ -686,7 +686,7 @@ static void TMCJPEGDEC_converterYUV420toRGBA8edge(TMCCJPEGDecWork* work, s32 x,
static void TMCJPEGDEC_converterYUV211toRGBA8(TMCCJPEGDecWork* work, s32 x, s32 y) { static void TMCJPEGDEC_converterYUV211toRGBA8(TMCCJPEGDecWork* work, s32 x, s32 y) {
u16* output; u16* output;
s32 column; s32 tileRow;
s32 redOffset; s32 redOffset;
TMCCJPEGDecState* state; TMCCJPEGDecState* state;
s32 lumaSkip; s32 lumaSkip;
@@ -695,7 +695,7 @@ static void TMCJPEGDEC_converterYUV211toRGBA8(TMCCJPEGDecWork* work, s32 x, s32
u8* cb; u8* cb;
u8* cr; u8* cr;
s32 height; s32 height;
s32 tileRow; s32 column;
s32 chromaSkip; s32 chromaSkip;
s32 width; s32 width;
s32 xEnd; s32 xEnd;
@@ -742,7 +742,7 @@ static void TMCJPEGDEC_converterYUV211toRGBA8(TMCCJPEGDecWork* work, s32 x, s32
green = value + greenOffset; green = value + greenOffset;
red = value + redOffset; red = value + redOffset;
blue = value + blueOffset; blue = value + blueOffset;
if ((blue | red | green) >> 8) { if ((red | green | blue) >> 8) {
blue = blue > 255 ? 255 : blue < 0 ? 0 : blue; blue = blue > 255 ? 255 : blue < 0 ? 0 : blue;
green = green > 255 ? 255 : green < 0 ? 0 : green; green = green > 255 ? 255 : green < 0 ? 0 : green;
red = red > 255 ? 255 : red < 0 ? 0 : red; red = red > 255 ? 255 : red < 0 ? 0 : red;
@@ -770,7 +770,7 @@ static void TMCJPEGDEC_converterYUV211toRGBA8edge(TMCCJPEGDecWork* work, s32 x,
u16* output; u16* output;
s32 lumaSkip; s32 lumaSkip;
s32 blue; s32 blue;
s32 tileRow; u8* texture;
u8* luminance; u8* luminance;
u8* cb; u8* cb;
u8* cr; u8* cr;
@@ -783,7 +783,7 @@ static void TMCJPEGDEC_converterYUV211toRGBA8edge(TMCCJPEGDecWork* work, s32 x,
s32 greenOffset; s32 greenOffset;
s32 yEnd; s32 yEnd;
s32 cbValue; s32 cbValue;
u8* texture; s32 tileRow;
s32 blueOffset; s32 blueOffset;
s32 red; s32 red;
s8 crValue; s8 crValue;
@@ -831,7 +831,7 @@ static void TMCJPEGDEC_converterYUV211toRGBA8edge(TMCCJPEGDecWork* work, s32 x,
green = value + greenOffset; green = value + greenOffset;
red = value + redOffset; red = value + redOffset;
blue = value + blueOffset; blue = value + blueOffset;
if ((blue | red | green) >> 8) { if ((red | green | blue) >> 8) {
blue = blue > 255 ? 255 : blue < 0 ? 0 : blue; blue = blue > 255 ? 255 : blue < 0 ? 0 : blue;
green = green > 255 ? 255 : green < 0 ? 0 : green; green = green > 255 ? 255 : green < 0 ? 0 : green;
red = red > 255 ? 255 : red < 0 ? 0 : red; red = red > 255 ? 255 : red < 0 ? 0 : red;
@@ -856,20 +856,20 @@ static void TMCJPEGDEC_converterYUV211toRGBA8edge(TMCCJPEGDecWork* work, s32 x,
static void TMCJPEGDEC_converterYUV444toRGBA8(TMCCJPEGDecWork* work, s32 x, s32 y) { static void TMCJPEGDEC_converterYUV444toRGBA8(TMCCJPEGDecWork* work, s32 x, s32 y) {
u16* output; u16* output;
s32 tileWidth;
s32 tileRow; s32 tileRow;
s32 xEnd; s32 rowSkip;
u8* texture;
u8* luminance; u8* luminance;
u8* cb; u8* cb;
u8* cr; u8* cr;
TMCCJPEGDecState* state; TMCCJPEGDecState* state;
s8 crValue; s32 crValue;
s32 height; s32 height;
s32 width; s32 width;
s32 column; s32 column;
s32 rowSkip; s32 xEnd;
s32 yEnd; s32 yEnd;
u8* texture; s32 tileWidth;
s32 row; s32 row;
s32 red; s32 red;
s32 cbValue; s32 cbValue;
@@ -899,7 +899,7 @@ static void TMCJPEGDEC_converterYUV444toRGBA8(TMCCJPEGDecWork* work, s32 x, s32
green = value + (-(cbValue * 88 + crValue * 183) >> 8); green = value + (-(cbValue * 88 + crValue * 183) >> 8);
red = value + ((crValue * 359) >> 8); red = value + ((crValue * 359) >> 8);
blue = value + ((cbValue * 454) >> 8); blue = value + ((cbValue * 454) >> 8);
if ((blue | red | green) >> 8) { if ((red | green | blue) >> 8) {
blue = blue > 255 ? 255 : blue < 0 ? 0 : blue; blue = blue > 255 ? 255 : blue < 0 ? 0 : blue;
green = green > 255 ? 255 : green < 0 ? 0 : green; green = green > 255 ? 255 : green < 0 ? 0 : green;
red = red > 255 ? 255 : red < 0 ? 0 : red; red = red > 255 ? 255 : red < 0 ? 0 : red;

View File

@@ -171,9 +171,7 @@ s32 TMCJPEGDEC_set_converterY8U8V8(TMCCJPEGDecWork* work) {
static void TMCJPEG_814EFEAC(TMCCJPEGDecWork* work, s32 x, s32 y) { static void TMCJPEG_814EFEAC(TMCCJPEGDecWork* work, s32 x, s32 y) {
s32 rowSkip; s32 rowSkip;
u8* output; u8* output;
s32 chromaXEnd;
u32 tileRow; u32 tileRow;
u32 chromaTileWidth;
s32 chromaYEnd; s32 chromaYEnd;
u8* lumaTexture; u8* lumaTexture;
TMCCJPEGDecState* state; TMCCJPEGDecState* state;
@@ -216,17 +214,17 @@ static void TMCJPEG_814EFEAC(TMCCJPEGDecWork* work, s32 x, s32 y) {
} }
luminance += rowSkip; luminance += rowSkip;
} }
chromaTileWidth = state->chromaWidth >> 3; tileWidth = state->chromaWidth >> 3;
x = (u32)x >> 2; x = (u32)x >> 2;
width = 8 / state->scaleFactor; width = 8 / state->scaleFactor;
height = 8 / state->scaleFactor; height = 8 / state->scaleFactor;
chromaXEnd = x + width; xEnd = x + width;
chromaYEnd = y + height; chromaYEnd = y + height;
for (; y < chromaYEnd; y++) { for (; y < chromaYEnd; y++) {
for (column = x; column < chromaXEnd; column += 1) { for (column = x; column < xEnd; column += 1) {
(cbTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * chromaTileWidth) << 5)] = *cb + 128; (cbTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * tileWidth) << 5)] = *cb + 128;
cb++; cb++;
(crTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * chromaTileWidth) << 5)] = *cr + 128; (crTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * tileWidth) << 5)] = *cr + 128;
cr++; cr++;
} }
cb += 8 - width; cb += 8 - width;
@@ -235,7 +233,6 @@ static void TMCJPEG_814EFEAC(TMCCJPEGDecWork* work, s32 x, s32 y) {
} }
static void TMCJPEG_814F043C(TMCCJPEGDecWork* work, s32 x, s32 y) { static void TMCJPEG_814F043C(TMCCJPEGDecWork* work, s32 x, s32 y) {
u32 chromaTileWidth;
TMCCJPEGDecState* state; TMCCJPEGDecState* state;
u8* lumaTexture; u8* lumaTexture;
u8* luminance; u8* luminance;
@@ -250,9 +247,9 @@ static void TMCJPEG_814F043C(TMCCJPEGDecWork* work, s32 x, s32 y) {
u8* output; u8* output;
u8* cb; u8* cb;
u8* cr; u8* cr;
s32 xEnd;
s32 tileOffset;
s32 width; s32 width;
s32 tileOffset;
s32 xEnd;
u32 tileWidth; u32 tileWidth;
luminance = work->convBuf + 4; luminance = work->convBuf + 4;
@@ -287,13 +284,13 @@ static void TMCJPEG_814F043C(TMCCJPEGDecWork* work, s32 x, s32 y) {
x = (u32)x >> 2; x = (u32)x >> 2;
width = (width + 3) >> 2; width = (width + 3) >> 2;
xEnd = x + width; xEnd = x + width;
chromaTileWidth = state->chromaWidth >> 3; tileWidth = state->chromaWidth >> 3;
chromaEnd = y + height; chromaEnd = y + height;
for (; y < chromaEnd; y++) { for (; y < chromaEnd; y++) {
for (column = x; column < xEnd; column += 1) { for (column = x; column < xEnd; column += 1) {
(cbTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * chromaTileWidth) << 5)] = *cb + 128; (cbTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * tileWidth) << 5)] = *cb + 128;
cb++; cb++;
(crTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * chromaTileWidth) << 5)] = *cr + 128; (crTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * tileWidth) << 5)] = *cr + 128;
cr++; cr++;
} }
cb += 8 - width; cb += 8 - width;
@@ -306,9 +303,7 @@ static void TMCJPEG_814F0A58(TMCCJPEGDecWork* work, s32 x, s32 y) {
u8* lumaTexture; u8* lumaTexture;
u8* luminance; u8* luminance;
s32 column; s32 column;
s32 chromaXEnd;
s32 row; s32 row;
u32 chromaTileWidth;
TMCCJPEGDecState* state; TMCCJPEGDecState* state;
s32 width; s32 width;
s32 height; s32 height;
@@ -319,7 +314,6 @@ static void TMCJPEG_814F0A58(TMCCJPEGDecWork* work, s32 x, s32 y) {
u8* cb; u8* cb;
u32 tileWidth; u32 tileWidth;
u8* cr; u8* cr;
s32 chromaRowSkip;
row = y; row = y;
luminance = work->convBuf + 4; luminance = work->convBuf + 4;
@@ -344,24 +338,22 @@ static void TMCJPEG_814F0A58(TMCCJPEGDecWork* work, s32 x, s32 y) {
x = (u32)x >> 1; x = (u32)x >> 1;
width = 8 / state->scaleFactor; width = 8 / state->scaleFactor;
height = 8 / state->scaleFactor; height = 8 / state->scaleFactor;
chromaXEnd = x + width; xEnd = x + width;
chromaYEnd = y + height; chromaYEnd = y + height;
chromaTileWidth = state->chromaWidth >> 3; tileWidth = state->chromaWidth >> 3;
chromaRowSkip = 8 - width; for (row = y; row < chromaYEnd; row++) {
for (; y < chromaYEnd; y++) { for (column = x; column < xEnd; column += 1) {
for (column = x; column < chromaXEnd; column += 1) { (cbTexture + ((row & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (row >> 2) * tileWidth) << 5)] = *cb + 128;
(cbTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * chromaTileWidth) << 5)] = *cb + 128;
cb++; cb++;
(crTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * chromaTileWidth) << 5)] = *cr + 128; (crTexture + ((row & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (row >> 2) * tileWidth) << 5)] = *cr + 128;
cr++; cr++;
} }
cb += chromaRowSkip; cb += 8 - width;
cr += 8 - width; cr += 8 - width;
} }
} }
static void TMCJPEG_814F11C4(TMCCJPEGDecWork* work, s32 x, s32 y) { static void TMCJPEG_814F11C4(TMCCJPEGDecWork* work, s32 x, s32 y) {
u32 chromaTileWidth;
TMCCJPEGDecState* state; TMCCJPEGDecState* state;
u8* lumaTexture; u8* lumaTexture;
u8* luminance; u8* luminance;
@@ -376,9 +368,9 @@ static void TMCJPEG_814F11C4(TMCCJPEGDecWork* work, s32 x, s32 y) {
u8* output; u8* output;
u8* cb; u8* cb;
u8* cr; u8* cr;
s32 xEnd;
s32 tileOffset;
s32 width; s32 width;
s32 tileOffset;
s32 xEnd;
u32 tileWidth; u32 tileWidth;
luminance = work->convBuf + 4; luminance = work->convBuf + 4;
@@ -413,13 +405,13 @@ static void TMCJPEG_814F11C4(TMCCJPEGDecWork* work, s32 x, s32 y) {
x = (u32)x >> 1; x = (u32)x >> 1;
width = (width + 1) >> 1; width = (width + 1) >> 1;
xEnd = x + width; xEnd = x + width;
chromaTileWidth = state->chromaWidth >> 3; tileWidth = state->chromaWidth >> 3;
chromaEnd = y + height; chromaEnd = y + height;
for (; y < chromaEnd; y++) { for (; y < chromaEnd; y++) {
for (column = x; column < xEnd; column += 1) { for (column = x; column < xEnd; column += 1) {
(cbTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * chromaTileWidth) << 5)] = *cb + 128; (cbTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * tileWidth) << 5)] = *cb + 128;
cb++; cb++;
(crTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * chromaTileWidth) << 5)] = *cr + 128; (crTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * tileWidth) << 5)] = *cr + 128;
cr++; cr++;
} }
cb += 8 - width; cb += 8 - width;
@@ -428,23 +420,21 @@ static void TMCJPEG_814F11C4(TMCCJPEGDecWork* work, s32 x, s32 y) {
} }
static void TMCJPEG_814F17E0(TMCCJPEGDecWork* work, s32 x, s32 y) { static void TMCJPEG_814F17E0(TMCCJPEGDecWork* work, s32 x, s32 y) {
s32 height;
s32 chromaYEnd; s32 chromaYEnd;
s32 column;
u8* lumaTexture; u8* lumaTexture;
s32 chromaXEnd; s32 height;
u8* luminance; u8* luminance;
u32 chromaTileWidth; s32 column;
u8* cbTexture; u8* cbTexture;
s32 width; s32 row;
u8* crTexture; u8* crTexture;
u32 tileWidth; s32 xEnd;
u8* cb; u8* cb;
TMCCJPEGDecState* state; TMCCJPEGDecState* state;
s32 yEnd; s32 yEnd;
s32 xEnd; s32 width;
u8* cr; u8* cr;
s32 row; u32 tileWidth;
row = y; row = y;
luminance = work->convBuf + 4; luminance = work->convBuf + 4;
@@ -470,14 +460,14 @@ static void TMCJPEG_814F17E0(TMCCJPEGDecWork* work, s32 x, s32 y) {
y = (u32)y >> 1; y = (u32)y >> 1;
width = 8 / state->scaleFactor; width = 8 / state->scaleFactor;
height = 8 / state->scaleFactor; height = 8 / state->scaleFactor;
chromaXEnd = x + width; xEnd = x + width;
chromaYEnd = y + height; chromaYEnd = y + height;
chromaTileWidth = state->chromaWidth >> 3; tileWidth = state->chromaWidth >> 3;
for (; y < chromaYEnd; y++) { for (; y < chromaYEnd; y++) {
for (column = x; column < chromaXEnd; column += 1) { for (column = x; column < xEnd; column += 1) {
(cbTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * chromaTileWidth) << 5)] = *cb + 128; (cbTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * tileWidth) << 5)] = *cb + 128;
cb++; cb++;
(crTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * chromaTileWidth) << 5)] = *cr + 128; (crTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * tileWidth) << 5)] = *cr + 128;
cr++; cr++;
} }
cb += 8 - width; cb += 8 - width;
@@ -486,7 +476,6 @@ static void TMCJPEG_814F17E0(TMCCJPEGDecWork* work, s32 x, s32 y) {
} }
static void TMCJPEG_814F1F48(TMCCJPEGDecWork* work, s32 x, s32 y) { static void TMCJPEG_814F1F48(TMCCJPEGDecWork* work, s32 x, s32 y) {
u32 chromaTileWidth;
TMCCJPEGDecState* state; TMCCJPEGDecState* state;
u8* lumaTexture; u8* lumaTexture;
u8* luminance; u8* luminance;
@@ -497,13 +486,13 @@ static void TMCJPEG_814F1F48(TMCCJPEGDecWork* work, s32 x, s32 y) {
u8* crTexture; u8* crTexture;
u32 tileRow; u32 tileRow;
s32 height; s32 height;
s32 yEnd; s32 width;
u8* output; u8* output;
u8* cb; u8* cb;
u8* cr; u8* cr;
s32 xEnd; s32 xEnd;
s32 tileOffset; s32 tileOffset;
s32 width; s32 yEnd;
u32 tileWidth; u32 tileWidth;
luminance = work->convBuf + 4; luminance = work->convBuf + 4;
@@ -539,13 +528,13 @@ static void TMCJPEG_814F1F48(TMCCJPEGDecWork* work, s32 x, s32 y) {
x = (u32)x >> 1; x = (u32)x >> 1;
width = (width + 1) >> 1; width = (width + 1) >> 1;
xEnd = x + width; xEnd = x + width;
chromaTileWidth = state->chromaWidth >> 3; tileWidth = state->chromaWidth >> 3;
chromaEnd = y + ((height + 1) >> 1); chromaEnd = y + ((height + 1) >> 1);
for (; y < chromaEnd; y++) { for (; y < chromaEnd; y++) {
for (column = x; column < xEnd; column += 1) { for (column = x; column < xEnd; column += 1) {
(cbTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * chromaTileWidth) << 5)] = *cb + 128; (cbTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * tileWidth) << 5)] = *cb + 128;
cb++; cb++;
(crTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * chromaTileWidth) << 5)] = *cr + 128; (crTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * tileWidth) << 5)] = *cr + 128;
cr++; cr++;
} }
cb += 8 - width; cb += 8 - width;
@@ -554,9 +543,8 @@ static void TMCJPEG_814F1F48(TMCCJPEGDecWork* work, s32 x, s32 y) {
} }
static void TMCJPEG_814F2570(TMCCJPEGDecWork* work, s32 x, s32 y) { static void TMCJPEG_814F2570(TMCCJPEGDecWork* work, s32 x, s32 y) {
u32 chromaTileWidth;
TMCCJPEGDecState* state;
u8* lumaTexture; u8* lumaTexture;
TMCCJPEGDecState* state;
u8* luminance; u8* luminance;
s32 column; s32 column;
s32 row; s32 row;
@@ -596,13 +584,13 @@ static void TMCJPEG_814F2570(TMCCJPEGDecWork* work, s32 x, s32 y) {
luminance += 8 - width; luminance += 8 - width;
} }
y = (u32)y >> 1; y = (u32)y >> 1;
chromaTileWidth = state->chromaWidth >> 3; tileWidth = state->chromaWidth >> 3;
chromaEnd = y + 8 / state->scaleFactor; chromaEnd = y + 8 / state->scaleFactor;
for (; y < chromaEnd; y++) { for (; y < chromaEnd; y++) {
for (column = x; column < xEnd; column += 1) { for (column = x; column < xEnd; column += 1) {
(cbTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * chromaTileWidth) << 5)] = *cb + 128; (cbTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * tileWidth) << 5)] = *cb + 128;
cb++; cb++;
(crTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * chromaTileWidth) << 5)] = *cr + 128; (crTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * tileWidth) << 5)] = *cr + 128;
cr++; cr++;
} }
cb += 8 - width; cb += 8 - width;

View File

@@ -205,12 +205,12 @@ typedef struct _ziUwdNode {
struct __zi8_work_data_s { struct __zi8_work_data_s {
ziU8 unk_0x00; ziU8 unk_0x00;
ziU8 unk_0x01; ziU8 countOnly; // 0x01
ziU8 unk_0x02[2]; ziU8 unk_0x02[2];
ziLanguageEntry* langEntries; // 0x04 ziLanguageEntry* langEntries; // 0x04
ziU8 unk_0x08; ziU8 unk_0x08;
ziU8 unk_0x09; ziU8 unk_0x09;
ziU8 unk_0x0A; ziU8 maxWordLength;
ziU8 unk_0x0B; ziU8 unk_0x0B;
ziU32 unk_0x0C; ziU32 unk_0x0C;
ziU32 unk_0x10; ziU32 unk_0x10;
@@ -219,7 +219,7 @@ struct __zi8_work_data_s {
ziU8 unk_0x17; ziU8 unk_0x17;
ziU8 subLanguage; // 0x18 ziU8 subLanguage; // 0x18
ziU8 unk_0x19; ziU8 unk_0x19;
ziU16 unk_0x1A; ziU16 separator; // 0x1A
ziU8 unk_0x1C[3]; ziU8 unk_0x1C[3];
ziU8 unk_0x1F; ziU8 unk_0x1F;
ziU16 unk_0x20[0x40]; ziU16 unk_0x20[0x40];
@@ -265,25 +265,25 @@ struct __zi8_work_data_s {
ziPtr unk_0x11FC; ziPtr unk_0x11FC;
ziPtr userKeys[0x83]; // 0x1200 ziPtr userKeys[0x83]; // 0x1200
ziU8 unk_0x140C[4]; ziU8 unk_0x140C[4];
ziU32 unk_0x1410; ziU32 formats; // 0x1410
ziU8 unk_0x1414[4]; ziU8 unk_0x1414[4];
ziU8 unk_0x1418; ziU8 formatCount;
ziU8 unk_0x1419; ziU8 unk_0x1419;
ziU16 unk_0x141A; ziU16 capacity; // 0x141A
ziU8 unk_0x141C; ziU8 unk_0x141C;
ziU8 unk_0x141D; ziU8 unk_0x141D;
ziU8 unk_0x141E; ziU8 graphTableId; // 0x141E
ziU8 unk_0x141F; ziU8 maxCnt; // 0x141F
ziU8 unk_0x1420[4]; ziU8 unk_0x1420[4];
zi8DawgCtx dawgCtx; // 0x1424 zi8DawgCtx dawgCtx; // 0x1424
ziU8 unk_0x1760[4]; // 0x1760 ziU8 unk_0x1760[4]; // 0x1760
ziU8* unk_0x1764; // 0x1764 ziU8* groupPtr; // 0x1764
ziU8 unk_0x1768; ziU8 unk_0x1768;
ziU8 unk_0x1769[0x81]; ziU8 unk_0x1769[0x81];
ziU16 unk_0x17EA; ziU16 matchOffset; // 0x17EA
ziU8 unk_0x17EC; ziU8 unk_0x17EC;
ziU8 unk_0x17ED[3]; ziU8 unk_0x17ED[3];
ziU8* unk_0x17F0; ziU8* dawgGroup; // 0x17F0
ziWChar unk_0x17F4[0x40]; // 0x17F4..0x1874 ziWChar unk_0x17F4[0x40]; // 0x17F4..0x1874
ziU16 unk_0x1874; ziU16 unk_0x1874;
ziU8 unk_0x1876; ziU8 unk_0x1876;

View File

@@ -27,11 +27,11 @@ ziPtr Zi8GetTableAddress(ziU8, ziU8 ZI_NEED_WORK);
ziWChar Zi8ConvertUC2UserKey(ziChar, ziU8 ZI_NEED_WORK); ziWChar Zi8ConvertUC2UserKey(ziChar, ziU8 ZI_NEED_WORK);
ziWChar Zi8ConvertUC2WC(ziChar character, ziU8 language ZI_NEED_WORK) { ziWChar Zi8ConvertUC2WC(ziChar character, ziU8 language ZI_NEED_WORK) {
ziU8* table; const ziConversionTables* defaults;
ziWChar* mapped; ziWChar* mapped;
ziU8* cursor; ziU8* cursor;
ziU16 first, last; ziU16 first, last;
const ziConversionTables* defaults; ziU8* table;
if (character == 0) { if (character == 0) {
Zi8LogError(0x133, __zi8_work_data); Zi8LogError(0x133, __zi8_work_data);
return 0; return 0;

View File

@@ -796,11 +796,11 @@ Zi8UInt Zi8Get1KeyPressSpelling(Zi8OneKeyParam *params,Zi8OneKeyOptions *options
if (remaining != 0) { if (remaining != 0) {
remaining--; remaining--;
} else { } else {
totalCandidates++; totalCandidates = totalCandidates + 1;
if (options->countOnly == '\0') { if (options->countOnly == '\0') {
*output++ = spellingBuffer[spellingIndex]; *output++ = spellingBuffer[spellingIndex];
*output++ = 0; *output++ = 0;
candidateCount++; candidateCount = candidateCount + 1;
} }
else if ((int)totalCandidates >= options->maxCount) goto finishSpelling; else if ((int)totalCandidates >= options->maxCount) goto finishSpelling;
if (candidateCount >= params->maxCandidates) goto finishSpelling; if (candidateCount >= params->maxCandidates) goto finishSpelling;
@@ -940,8 +940,7 @@ Zi8UInt Zi8Get1KeyPressSpelling(Zi8OneKeyParam *params,Zi8OneKeyOptions *options
for (tableIndex = 0; tableIndex < params->count;) { for (tableIndex = 0; tableIndex < params->count;) {
while (*output != 0) { while (*output != 0) {
if (*output != 0x27) { if (*output != 0x27) {
*output |= 0xf300; *output++ |= 0xf300;
output++;
} else { } else {
*output++ = 0xf360; *output++ = 0xf360;
} }
@@ -1001,10 +1000,10 @@ Zi8UInt Zi8Get1KeyPressSpelling(Zi8OneKeyParam *params,Zi8OneKeyOptions *options
} }
if (Zi8IsDupWordW(output,(ziU8)phoneticIndex,work) == 0) { if (Zi8IsDupWordW(output,(ziU8)phoneticIndex,work) == 0) {
if (remaining == 0) { if (remaining == 0) {
totalCandidates++; totalCandidates = totalCandidates + 1;
if (options->countOnly == 0) { if (options->countOnly == 0) {
output += phoneticIndex + 1; output += phoneticIndex + 1;
candidateCount++; ++candidateCount;
} else if ((int)totalCandidates >= options->maxCount) goto finishSpelling; } else if ((int)totalCandidates >= options->maxCount) goto finishSpelling;
if (candidateCount >= params->maxCandidates) goto finishSpelling; if (candidateCount >= params->maxCandidates) goto finishSpelling;
} else { } else {

View File

@@ -285,9 +285,9 @@ static ziBool ZiIsLetterHyphen(ziWChar character ZI_NEED_WORK) {
else return ZI8_FALSE; else return ZI8_FALSE;
} }
void Zi8ChangeWordCase(ziWChar* word, ziU8 language, ziPtr work) { void Zi8ChangeWordCase(ziWChar* word, ziU8 language, ZiAlphaWork* work) {
enum { LOWER_CASE, UPPER_CASE } upper = LOWER_CASE; enum { LOWER_CASE, UPPER_CASE } upper = LOWER_CASE;
if (((ZiAlphaWork*)work)->caseMode == 3) { if (work->caseMode == 3) {
Zi8ChangeCharCase(1, word++, language, work); Zi8ChangeCharCase(1, word++, language, work);
} else if (((ZiAlphaWork*)work)->caseMode == 1) { } else if (((ZiAlphaWork*)work)->caseMode == 1) {
upper = UPPER_CASE; upper = UPPER_CASE;

View File

@@ -18,7 +18,7 @@ static Zi8UInt Zi8SetFindCand(ziU8* foundCandidates, Zi8UInt ordinal, ziPtr work
} }
ziWChar* ZiGetNextPhonetic(ziWChar* spelling, ziWChar* end ZI_NEED_WORK) { ziWChar* ZiGetNextPhonetic(ziWChar* spelling, ziWChar* end ZI_NEED_WORK) {
while (*spelling && *spelling != ZI_WORK->unk_0x1A && *spelling != 0xF360 && spelling < end) { while (*spelling && *spelling != ZI_WORK->separator && *spelling != 0xF360 && spelling < end) {
++spelling; ++spelling;
} }
if (!*spelling || spelling == end) { if (!*spelling || spelling == end) {
@@ -37,8 +37,8 @@ int ZiPartialMatch(ziWChar* spelling, ziWChar* spellingEnd,
if (spelling == spellingEnd || candidate == candidateEnd || !*spelling || !*candidate) { if (spelling == spellingEnd || candidate == candidateEnd || !*spelling || !*candidate) {
return 1; return 1;
} }
while (*spelling != ZI_WORK->unk_0x1A && *spelling != 0xF360) { while (*spelling != ZI_WORK->separator && *spelling != 0xF360) {
if (*candidate == ZI_WORK->unk_0x1A || *candidate == 0xF360) { if (*candidate == ZI_WORK->separator || *candidate == 0xF360) {
break; break;
} }
if (*spelling != *candidate) { if (*spelling != *candidate) {
@@ -753,8 +753,7 @@ static int zi8InternalGetZH(ziGetParam* request, ZiChineseOptions* options, ziPt
if (!componentTable) { if (!componentTable) {
componentCount = Zi8GetTableCount(1, 7, work); componentCount = Zi8GetTableCount(1, 7, work);
componentOrdinals = (ziU8*)Zi8GetTableAddress(1, 7, work); componentOrdinals = (ziU8*)Zi8GetTableAddress(1, 7, work);
componentCursor = (ziU8*)Zi8GetTableAddress(1, 2, work); componentTable = componentCursor = (ziU8*)Zi8GetTableAddress(1, 2, work);
componentTable = componentCursor;
componentCursor += 8; componentCursor += 8;
--componentCount; --componentCount;
componentIndex = componentCount; componentIndex = componentCount;
@@ -2869,7 +2868,7 @@ ziU8 Zi8GetElementCount(ziWChar* elements, ziU8 elementCount, ziU8 charCount ZI_
ziU8 count; ziU8 count;
ziWChar spacedElements[256]; ziWChar spacedElements[256];
struct { ziWChar separator; } savedState; struct { ziWChar separator; } savedState;
savedState.separator = ZI_WORK->unk_0x1A; savedState.separator = ZI_WORK->separator;
if (elementCount <= 1 || !charCount) { if (elementCount <= 1 || !charCount) {
return elementCount; return elementCount;
} }
@@ -2882,9 +2881,9 @@ ziU8 Zi8GetElementCount(ziWChar* elements, ziU8 elementCount, ziU8 charCount ZI_
if (spacedIndex == elementCount) { if (spacedIndex == elementCount) {
return elementCount; return elementCount;
} }
ZI_WORK->unk_0x1A = 0xF360; ZI_WORK->separator = 0xF360;
Zi8ZHaddSpace(elements, elementCount, spacedElements, 256, __zi8_work_data); Zi8ZHaddSpace(elements, elementCount, spacedElements, 256, __zi8_work_data);
ZI_WORK->unk_0x1A = savedState.separator; ZI_WORK->separator = savedState.separator;
spacedIndex = elementIndex = count = 0; spacedIndex = elementIndex = count = 0;
while (charCount && elementIndex < elementCount) { while (charCount && elementIndex < elementCount) {
if (spacedElements[spacedIndex] == 0xF360) { if (spacedElements[spacedIndex] == 0xF360) {

View File

@@ -39,10 +39,10 @@ ziU32 Zi8MatchROMdata0(ziWChar* elements, ziU8 count, ziU8 language,
} }
if (mode == 1) acceptPrefix = 0; if (mode == 1) acceptPrefix = 0;
} else { } else {
if (ZI_WORK->unk_0x141E != 0 && graphTable == 0xc && if (ZI_WORK->graphTableId != 0 && graphTable == 0xc &&
Zi8GetTableSize(language, ZI_WORK->unk_0x141E, ZI_WORK) != 0) { Zi8GetTableSize(language, ZI_WORK->graphTableId, ZI_WORK) != 0) {
graphData = (ziU8*)Zi8GetTableAddress(language, ZI_WORK->unk_0x141E, ZI_WORK); graphData = (ziU8*)Zi8GetTableAddress(language, ZI_WORK->graphTableId, ZI_WORK);
keyTable = ZI_WORK->unk_0x141E + 1; keyTable = ZI_WORK->graphTableId + 1;
} else { } else {
if (Zi8GetTableSize(language, graphTable, ZI_WORK) == 0) { if (Zi8GetTableSize(language, graphTable, ZI_WORK) == 0) {
Zi8LogError(0x961, ZI_WORK); Zi8LogError(0x961, ZI_WORK);
@@ -136,7 +136,7 @@ descend:
records[context->cnt].node = ZiDAWGGetChild(records[context->cnt - 1].node); records[context->cnt].node = ZiDAWGGetChild(records[context->cnt - 1].node);
if (records[context->cnt].node == (ziU8*)0) goto next_sibling; if (records[context->cnt].node == (ziU8*)0) goto next_sibling;
context->cnt++; context->cnt++;
if (ZI_WORK->unk_0x141F < context->cnt) ZI_WORK->unk_0x141F = context->cnt; if (ZI_WORK->maxCnt < context->cnt) ZI_WORK->maxCnt = context->cnt;
goto update_current; goto update_current;
next_sibling: next_sibling:
while (context->cnt != 0) { while (context->cnt != 0) {
@@ -184,37 +184,36 @@ unsigned int Zi8MatchROMdata1(ziWChar *elements, ziU8 count, ziU8 language, ziWC
result = 0; result = 0;
if (status == 0) { if (status == 0) {
ZI_WORK->unk_0x1764 = (ziU8*)group; ZI_WORK->groupPtr = (ziU8*)group;
if (ZI_WORK->unk_0x1764 == 0) { if (ZI_WORK->groupPtr == 0) {
if (Zi8GetTableSize(language & 0xff,0xb,ZI_WORK) != 0) { if (Zi8GetTableSize(language & 0xff,0xb,ZI_WORK) != 0) {
tableAddress = Zi8GetTableAddress(language & 0xff,0xb,ZI_WORK); ZI_WORK->groupPtr = (ziU8*)(tableAddress = Zi8GetTableAddress(language & 0xff,0xb,ZI_WORK));
ZI_WORK->unk_0x1764 = (ziU8*)tableAddress;
} }
} }
if (ZI_WORK->unk_0x1764 != 0) { if (ZI_WORK->groupPtr != 0) {
for (; (*ZI_WORK->unk_0x1764 != 0xff && ((groupIndex & 0xff) != 0)); for (; (*ZI_WORK->groupPtr != 0xff && ((groupIndex & 0xff) != 0));
groupIndex = groupIndex - 1) { groupIndex = groupIndex - 1) {
while (*ZI_WORK->unk_0x1764 != 0xff) { while (*ZI_WORK->groupPtr != 0xff) {
ZI_WORK->unk_0x1764 += 2; ZI_WORK->groupPtr += 2;
} }
ZI_WORK->unk_0x1764++; ZI_WORK->groupPtr++;
} }
} }
} }
if (ZI_WORK->unk_0x1764 == 0) { if (ZI_WORK->groupPtr == 0) {
result = Zi8MatchROMdata0(elements,count,language & 0xff,output,capacity & 0xffff, result = Zi8MatchROMdata0(elements,count,language & 0xff,output,capacity & 0xffff,
mode & 0xff,status & 0xff,0,1,acceptPrefix,0,&ZI_WORK->dawgCtx, mode & 0xff,status & 0xff,0,1,acceptPrefix,0,&ZI_WORK->dawgCtx,
ZI_WORK->unk_0x1760,ZI_WORK); ZI_WORK->unk_0x1760,ZI_WORK);
} }
else { else {
while (*ZI_WORK->unk_0x1764 != 0xff) { while (*ZI_WORK->groupPtr != 0xff) {
result = Zi8MatchROMdata0(elements,count,language & 0xff,output, result = Zi8MatchROMdata0(elements,count,language & 0xff,output,
capacity & 0xffff,mode & 0xff,status & 0xff, capacity & 0xffff,mode & 0xff,status & 0xff,
*ZI_WORK->unk_0x1764, *ZI_WORK->groupPtr,
ZI_WORK->unk_0x1764[1],acceptPrefix,0, ZI_WORK->groupPtr[1],acceptPrefix,0,
&ZI_WORK->dawgCtx,ZI_WORK->unk_0x1760,ZI_WORK); &ZI_WORK->dawgCtx,ZI_WORK->unk_0x1760,ZI_WORK);
if ((result & 0xff) != 0) break; if ((result & 0xff) != 0) break;
ZI_WORK->unk_0x1764 += 2; ZI_WORK->groupPtr += 2;
status = 0; status = 0;
} }
} }
@@ -231,31 +230,31 @@ unsigned int Zi8MatchROMdata2(ziWChar* elements, ziU8 count, ziU8 language,
if (reservedMode != 0) return 0; if (reservedMode != 0) return 0;
if (status == 0) { if (status == 0) {
ZI_WORK->unk_0x1768 = 0; ZI_WORK->unk_0x1768 = 0;
ZI_WORK->unk_0x17EA = 0; ZI_WORK->matchOffset = 0;
if (group != 0 && *group == 0xc && language == 10 && ZI_WORK->unk_0x141C != 0) { if (group != 0 && *group == 0xc && language == 10 && ZI_WORK->unk_0x141C != 0) {
ZI_WORK->unk_0x141E = 0x10; ZI_WORK->graphTableId = 0x10;
} else { } else {
ZI_WORK->unk_0x141E = 0; ZI_WORK->graphTableId = 0;
} }
} }
search_segment: search_segment:
ZI_WORK->unk_0x141F = 1; ZI_WORK->maxCnt = 1;
result = Zi8MatchROMdata1(elements + ZI_WORK->unk_0x17EA, result = Zi8MatchROMdata1(elements + ZI_WORK->matchOffset,
count - ZI_WORK->unk_0x17EA, language, count - ZI_WORK->matchOffset, language,
&ZI_WORK->unk_0x17F4[ZI_WORK->unk_0x17EA], capacity, &ZI_WORK->unk_0x17F4[ZI_WORK->matchOffset], capacity,
mode, status, ZI_WORK->unk_0x1768, (char*)group, mode, status, ZI_WORK->unk_0x1768, (char*)group,
acceptPrefix, ZI_WORK); acceptPrefix, ZI_WORK);
if ((ziU8)result != 0) { if ((ziU8)result != 0) {
for (index = (ziU8)(ZI_WORK->unk_0x17EA + result); index != 0; index--) { for (index = (ziU8)(ZI_WORK->matchOffset + result); index != 0; index--) {
output[index - 1] = ZI_WORK->unk_0x17F4[index - 1]; output[index - 1] = ZI_WORK->unk_0x17F4[index - 1];
} }
result = (ziU8)(result + ZI_WORK->unk_0x17EA); result = (ziU8)(result + ZI_WORK->matchOffset);
} else { } else {
if (status != 0 || count == 1) goto finish_segments; if (status != 0 || count == 1) goto finish_segments;
if (mode == 1 && ZI_WORK->unk_0x1768 == 0 && if (mode == 1 && ZI_WORK->unk_0x1768 == 0 &&
(ziU8)Zi8MatchROMdata1(elements + ZI_WORK->unk_0x17EA, (ziU8)Zi8MatchROMdata1(elements + ZI_WORK->matchOffset,
count - ZI_WORK->unk_0x17EA, language, count - ZI_WORK->matchOffset, language,
&ZI_WORK->unk_0x17F4[ZI_WORK->unk_0x17EA], capacity, &ZI_WORK->unk_0x17F4[ZI_WORK->matchOffset], capacity,
0, status, ZI_WORK->unk_0x1768, (char*)group, 0, status, ZI_WORK->unk_0x1768, (char*)group,
acceptPrefix, ZI_WORK) != 0) goto finish_segments; acceptPrefix, ZI_WORK) != 0) goto finish_segments;
if ((Zi8GetTableCount(language, 0x1f, ZI_WORK) & 4) == 0) { if ((Zi8GetTableCount(language, 0x1f, ZI_WORK) & 4) == 0) {
@@ -263,25 +262,25 @@ search_segment:
if (elements[index] == 0xeff1) goto finish_segments; if (elements[index] == 0xeff1) goto finish_segments;
} }
} }
if (ZI_WORK->unk_0x141F > capacity) goto finish_segments; if (ZI_WORK->maxCnt > capacity) goto finish_segments;
for (index = ZI_WORK->unk_0x141F; index != 0; index--) { for (index = ZI_WORK->maxCnt; index != 0; index--) {
result = Zi8MatchROMdata1(elements + ZI_WORK->unk_0x17EA, index, language, result = Zi8MatchROMdata1(elements + ZI_WORK->matchOffset, index, language,
&ZI_WORK->unk_0x17F4[ZI_WORK->unk_0x17EA], capacity, &ZI_WORK->unk_0x17F4[ZI_WORK->matchOffset], capacity,
1, 0, ZI_WORK->unk_0x1768, (char*)group, 1, 0, ZI_WORK->unk_0x1768, (char*)group,
acceptPrefix, ZI_WORK); acceptPrefix, ZI_WORK);
if ((ziU8)result != 0) { if ((ziU8)result != 0) {
ZI_WORK->unk_0x17EA += (ziU8)result; ZI_WORK->matchOffset += (ziU8)result;
if (ZI_WORK->unk_0x17EA == count) return 0; if (ZI_WORK->matchOffset == count) return 0;
ZI_WORK->unk_0x1768++; ZI_WORK->unk_0x1768++;
status = 0; status = 0;
ZI_WORK->unk_0x141E = 0; ZI_WORK->graphTableId = 0;
if (ZI_WORK->dawgCtx.key == 0 && language == 10) { if (ZI_WORK->dawgCtx.key == 0 && language == 10) {
for (index = 0; index < ZI_WORK->unk_0x17EA; index++) { for (index = 0; index < ZI_WORK->matchOffset; index++) {
switch (ZI_WORK->unk_0x17F4[index]) { switch (ZI_WORK->unk_0x17F4[index]) {
case 0x61: case 0x61:
case 0x6f: case 0x6f:
case 0x75: case 0x75:
ZI_WORK->unk_0x141E = 0x10; ZI_WORK->graphTableId = 0x10;
goto search_segment; goto search_segment;
} }
} }
@@ -307,7 +306,7 @@ ziU32 Zi8MatchROMdata(ziWChar* elements, ziU8 count, ziU8 language,
} else { } else {
if (status == 0) { if (status == 0) {
ZI_WORK->unk_0x17EC = 0; ZI_WORK->unk_0x17EC = 0;
ZI_WORK->unk_0x17F0 = NextDawgGroup(0, language, ZI_WORK); ZI_WORK->dawgGroup = NextDawgGroup(0, language, ZI_WORK);
} else if (ZI_WORK->unk_0x17EC != 0) { } else if (ZI_WORK->unk_0x17EC != 0) {
Zi8LogError(100, ZI_WORK); Zi8LogError(100, ZI_WORK);
goto finish_match; goto finish_match;
@@ -317,30 +316,30 @@ ziU32 Zi8MatchROMdata(ziWChar* elements, ziU8 count, ziU8 language,
result = Zi8MatchROMdata2(elements, count, language, output, capacity, result = Zi8MatchROMdata2(elements, count, language, output, capacity,
mode, status, reservedMode, 0, acceptPrefix, ZI_WORK); mode, status, reservedMode, 0, acceptPrefix, ZI_WORK);
} else { } else {
while (ZI_WORK->unk_0x17F0 != 0) { while (ZI_WORK->dawgGroup != 0) {
result = Zi8MatchROMdata2(elements, count, language, output, capacity, result = Zi8MatchROMdata2(elements, count, language, output, capacity,
mode, status, reservedMode, ZI_WORK->unk_0x17F0, mode, status, reservedMode, ZI_WORK->dawgGroup,
acceptPrefix, ZI_WORK); acceptPrefix, ZI_WORK);
if ((ziU8)result != 0) break; if ((ziU8)result != 0) break;
status = 0; status = 0;
if (count <= 1 && language == 0x36) break; if (count <= 1 && language == 0x36) break;
ZI_WORK->unk_0x17F0 = NextDawgGroup(ZI_WORK->unk_0x17F0, language, ZI_WORK); ZI_WORK->dawgGroup = NextDawgGroup(ZI_WORK->dawgGroup, language, ZI_WORK);
} }
} }
if ((ziU8)result == 0 && status == 0 && mode == 1 && count == 1 && capacity >= 1) { if ((ziU8)result == 0 && status == 0 && mode == 1 && count == 1 && capacity >= 1) {
mode = 0; mode = 0;
ZI_WORK->unk_0x17EC = 1; ZI_WORK->unk_0x17EC = 1;
if (tableSize != 0) { if (tableSize != 0) {
ZI_WORK->unk_0x17F0 = NextDawgGroup(0, language, ZI_WORK); ZI_WORK->dawgGroup = NextDawgGroup(0, language, ZI_WORK);
while (ZI_WORK->unk_0x17F0 != 0) { while (ZI_WORK->dawgGroup != 0) {
if ((ziU8)Zi8MatchROMdata2(elements, count, language, output, capacity, if ((ziU8)Zi8MatchROMdata2(elements, count, language, output, capacity,
mode, status, reservedMode, ZI_WORK->unk_0x17F0, mode, status, reservedMode, ZI_WORK->dawgGroup,
acceptPrefix, ZI_WORK) != 0) { acceptPrefix, ZI_WORK) != 0) {
*output = *elements; *output = *elements;
result = 1; result = 1;
break; break;
} }
ZI_WORK->unk_0x17F0 = NextDawgGroup(ZI_WORK->unk_0x17F0, language, ZI_WORK); ZI_WORK->dawgGroup = NextDawgGroup(ZI_WORK->dawgGroup, language, ZI_WORK);
} }
} else { } else {
if ((ziU8)Zi8MatchROMdata2(elements, count, language, output, capacity, if ((ziU8)Zi8MatchROMdata2(elements, count, language, output, capacity,

View File

@@ -50,11 +50,11 @@ ziBool Zi8ZHsetZYfuzzyPairs(ziFuzzyZYPairs pairs ZI_NEED_WORK) {
ziBool Zi8SetLatinSearchOrder(ziU8* searchArray, ziU8 searchSize ZI_NEED_WORK) { ziBool Zi8SetLatinSearchOrder(ziU8* searchArray, ziU8 searchSize ZI_NEED_WORK) {
if (searchArray == 0 || *searchArray == 0) { if (searchArray == 0 || *searchArray == 0) {
ZI_WORK->unk_0x1410 = (ziU32)Zi8SOdefaultArray; ZI_WORK->formats = (ziU32)Zi8SOdefaultArray;
ZI_WORK->unk_0x1418 = 9; ZI_WORK->formatCount = 9;
} else { } else {
ZI_WORK->unk_0x1410 = (ziU32)searchArray; ZI_WORK->formats = (ziU32)searchArray;
ZI_WORK->unk_0x1418 = searchSize; ZI_WORK->formatCount = searchSize;
} }
return 1; return 1;
} }
@@ -158,7 +158,7 @@ static ziBool Zi8AlphaSignature(ziGetParam* parameters, ziBool countOnly ZI_NEED
length = length - parameters->firstCandidate; length = length - parameters->firstCandidate;
if (countOnly != 0) { if (countOnly != 0) {
parameters->letters = length; parameters->letters = length;
ZI_WORK->unk_0x0A = 0xff; ZI_WORK->maxWordLength = 0xff;
return 1; return 1;
} }
if (parameters->maxCandidates < length) length = parameters->maxCandidates; if (parameters->maxCandidates < length) length = parameters->maxCandidates;
@@ -175,7 +175,7 @@ static ziBool Zi8AlphaSignature(ziGetParam* parameters, ziBool countOnly ZI_NEED
current = signatures.first; current = signatures.first;
length = signatures.length; length = signatures.length;
} }
if (length > ZI_WORK->unk_0x0A) length = ZI_WORK->unk_0x0A; if (length > ZI_WORK->maxWordLength) length = ZI_WORK->maxWordLength;
if ((parameters->elementCount < ZI_WORK->unk_0x140C[0] || if ((parameters->elementCount < ZI_WORK->unk_0x140C[0] ||
(parameters->getOptions & 0x7e) == 2) && length > parameters->elementCount) { (parameters->getOptions & 0x7e) == 2) && length > parameters->elementCount) {
length = parameters->elementCount; length = parameters->elementCount;
@@ -185,7 +185,7 @@ static ziBool Zi8AlphaSignature(ziGetParam* parameters, ziBool countOnly ZI_NEED
if (parameters->letters == 2) { if (parameters->letters == 2) {
current = signatures.second; current = signatures.second;
length = secondLength; length = secondLength;
if (length > ZI_WORK->unk_0x0A) length = ZI_WORK->unk_0x0A; if (length > ZI_WORK->maxWordLength) length = ZI_WORK->maxWordLength;
if ((parameters->elementCount < ZI_WORK->unk_0x140C[0] || if ((parameters->elementCount < ZI_WORK->unk_0x140C[0] ||
(parameters->getOptions & 0x7e) == 2) && length > parameters->elementCount) { (parameters->getOptions & 0x7e) == 2) && length > parameters->elementCount) {
length = parameters->elementCount; length = parameters->elementCount;
@@ -194,7 +194,7 @@ static ziBool Zi8AlphaSignature(ziGetParam* parameters, ziBool countOnly ZI_NEED
*output++ = 0; *output++ = 0;
} }
*output++ = 0; *output++ = 0;
ZI_WORK->unk_0x0A = 0xff; ZI_WORK->maxWordLength = 0xff;
return 1; return 1;
} }
@@ -226,7 +226,7 @@ static ziBool Zi8ZhSignature(ziGetParam* parameters, ziBool countOnly ZI_NEED_WO
length = length - parameters->firstCandidate; length = length - parameters->firstCandidate;
if (countOnly != 0) { if (countOnly != 0) {
parameters->letters = length; parameters->letters = length;
ZI_WORK->unk_0x0A = 0xff; ZI_WORK->maxWordLength = 0xff;
return 1; return 1;
} }
if (parameters->maxCandidates < length) length = parameters->maxCandidates; if (parameters->maxCandidates < length) length = parameters->maxCandidates;
@@ -279,13 +279,13 @@ static ziBool Zi8ZhSignature(ziGetParam* parameters, ziBool countOnly ZI_NEED_WO
ziU8 _Zi8GetCandidates(ziGetParam* parameters ZI_NEED_WORK) { ziU8 _Zi8GetCandidates(ziGetParam* parameters ZI_NEED_WORK) {
ZiCandidateOptions options = {0}; ZiCandidateOptions options = {0};
options.capacity = ZI_WORK->unk_0x141A; options.capacity = ZI_WORK->capacity;
return Zi8GetCandidatesOrCount(parameters, &options, ZI_WORK); return Zi8GetCandidatesOrCount(parameters, &options, ZI_WORK);
} }
ziU8 _Zi8CheckCandidates(ziGetParam* parameters ZI_NEED_WORK) { ziU8 _Zi8CheckCandidates(ziGetParam* parameters ZI_NEED_WORK) {
ZiCandidateOptions options = {0}; ZiCandidateOptions options = {0};
options.capacity = ZI_WORK->unk_0x141A; options.capacity = ZI_WORK->capacity;
options.flags = 1; options.flags = 1;
return Zi8GetCandidatesOrCount(parameters, &options, ZI_WORK); return Zi8GetCandidatesOrCount(parameters, &options, ZI_WORK);
} }
@@ -339,11 +339,11 @@ ziU32 Zi8GetCandidatesOrCount(ziGetParam* parameters, ZiCandidateOptions* option
if ((parameters->elementCount == 1) && (parameters->firstCandidate == 0)) { if ((parameters->elementCount == 1) && (parameters->firstCandidate == 0)) {
switch (parameters->language) { switch (parameters->language) {
case 1: case 1:
if ((ZI_WORK->unk_0x00 == '\0') || (ZI_WORK->unk_0x01 == options->countOnly)) { if ((ZI_WORK->unk_0x00 == '\0') || (ZI_WORK->countOnly == options->countOnly)) {
switch(ZI_WORK->unk_0x00) { switch(ZI_WORK->unk_0x00) {
case '\0': case '\0':
if (parameters->elements[0] == 0xEF04) { if (parameters->elements[0] == 0xEF04) {
ZI_WORK->unk_0x01 = options->countOnly; ZI_WORK->countOnly = options->countOnly;
ZI_WORK->unk_0x00 = '\x01'; ZI_WORK->unk_0x00 = '\x01';
} }
break; break;
@@ -400,11 +400,11 @@ ziU32 Zi8GetCandidatesOrCount(ziGetParam* parameters, ZiCandidateOptions* option
break; break;
case 0x11: case 0x11:
default: default:
if ((ZI_WORK->unk_0x00 == '\0') || (ZI_WORK->unk_0x01 == options->countOnly)) { if ((ZI_WORK->unk_0x00 == '\0') || (ZI_WORK->countOnly == options->countOnly)) {
switch(ZI_WORK->unk_0x00) { switch(ZI_WORK->unk_0x00) {
case '\0': case '\0':
if (parameters->elements[0] == 0xEFF2) { if (parameters->elements[0] == 0xEFF2) {
ZI_WORK->unk_0x01 = options->countOnly; ZI_WORK->countOnly = options->countOnly;
ZI_WORK->unk_0x00 = '\x01'; ZI_WORK->unk_0x00 = '\x01';
} }
break; break;
@@ -493,8 +493,8 @@ ziU32 Zi8GetCandidatesOrCount(ziGetParam* parameters, ZiCandidateOptions* option
ZI_WORK->subLanguage = parameters->subLanguage; ZI_WORK->subLanguage = parameters->subLanguage;
ZI_WORK->cangjieEnabled = Zi8GetFormatVersion(1,ZI_WORK) & 2; ZI_WORK->cangjieEnabled = Zi8GetFormatVersion(1,ZI_WORK) & 2;
options->maxCount = ZI_WORK->unk_0x10; options->maxCount = ZI_WORK->unk_0x10;
options->maxWordLength = ZI_WORK->unk_0x0A; options->maxWordLength = ZI_WORK->maxWordLength;
ZI_WORK->unk_0x0A = -1; ZI_WORK->maxWordLength = -1;
if ((ziU8)Zi8LangSupported(parameters->language,ZI_WORK) == 0) { if ((ziU8)Zi8LangSupported(parameters->language,ZI_WORK) == 0) {
Zi8LogError(0x163,ZI_WORK); Zi8LogError(0x163,ZI_WORK);
return 0; return 0;
@@ -711,6 +711,6 @@ void Zi8Memcpy(ziU8* destination, ziU8* source, ziS32 count) {
} }
ziBool Zi8SetMaxWordLength(ziU8 length ZI_NEED_WORK) { ziBool Zi8SetMaxWordLength(ziU8 length ZI_NEED_WORK) {
ZI_WORK->unk_0x0A = length; ZI_WORK->maxWordLength = length;
return 1; return 1;
} }

View File

@@ -18,10 +18,10 @@ ziU8 Zi8InitializeDynamic(ziLanguageEntry* langEntries ZI_NEED_WORK) {
Zi8Memset(__zi8_work_data, 0, 0x1B44); Zi8Memset(__zi8_work_data, 0, 0x1B44);
ZI_WORK->unk_0x08 = 1; ZI_WORK->unk_0x08 = 1;
ZI_WORK->unk_0x09 = 1; ZI_WORK->unk_0x09 = 1;
ZI_WORK->unk_0x0A = 0xFF; ZI_WORK->maxWordLength = 0xFF;
ZI_WORK->unk_0x10 = 0x64; ZI_WORK->unk_0x10 = 0x64;
*(ziU16*)&ZI_WORK->unk_0x0C = 0xFFFF; *(ziU16*)&ZI_WORK->unk_0x0C = 0xFFFF;
ZI_WORK->unk_0x1A = 0x20; ZI_WORK->separator = 0x20;
ZI_WORK->unk_0x1C[2] = 0; ZI_WORK->unk_0x1C[2] = 0;
ZI_WORK->unk_0x1B30 = 0; ZI_WORK->unk_0x1B30 = 0;
ZI_WORK->unk_0x1B3A = 0; ZI_WORK->unk_0x1B3A = 0;
@@ -44,7 +44,7 @@ ziU8 Zi8InitializeDynamic(ziLanguageEntry* langEntries ZI_NEED_WORK) {
ZI_WORK->unk_0x1874 = 0x2D; ZI_WORK->unk_0x1874 = 0x2D;
ZI_WORK->language = 0; ZI_WORK->language = 0;
ZI_WORK->unk_0x1C[3] = 0; ZI_WORK->unk_0x1C[3] = 0;
ZI_WORK->unk_0x141A = 0x100; ZI_WORK->capacity = 0x100;
Zi8SetLatinSearchOrder(0, 0, ZI_WORK); Zi8SetLatinSearchOrder(0, 0, ZI_WORK);
ZADP_Zi8SetPDremoveOpt(1, ZI_WORK); ZADP_Zi8SetPDremoveOpt(1, ZI_WORK);
ZI_WORK->unk_0x17 = 5; ZI_WORK->unk_0x17 = 5;

View File

@@ -49,39 +49,42 @@ void Zi8CopyZHSpelling(ziU8* source, ziWChar* output, ziU16 capacity, int size,
} }
} }
} }
ziU8 ZADP_Zi8SetPDremoveOpt(ziU8 option ZI_NEED_WORK) { ziU8 ZADP_Zi8SetPDremoveOpt(ziU8 option, struct __zi8_work_data_s* __zi8_work_data) {
ziU8 previous; ziU8 previous;
previous = ZI_WORK->pdRemoveOpt; previous = __zi8_work_data->pdRemoveOpt;
ZI_WORK->pdRemoveOpt = option; __zi8_work_data->pdRemoveOpt = option;
Zi8LogError(100, __zi8_work_data); Zi8LogError(100, __zi8_work_data);
return previous; return previous;
} }
ziU32 Zi8MatchPUDdata_ZHS(ziWChar* pattern, ziU8 length, ziU8 language, ziWChar* output, ziU16 capacity, ziWChar* spelling, ziU16 spellingCapacity, ziU8 complete, ziU8 continuation ZI_NEED_WORK) { ziU32 Zi8MatchPUDdata_ZHS(ziWChar* pattern, ziU8 length, ziU8 language, ziWChar* output, ziU16 capacity, ziWChar* spelling, ziU16 spellingCapacity, ziU8 complete, ziU8 continuation ZI_NEED_WORK) {
int fallback = 0;
ziU8* bytePattern;
ziWChar folded; ziWChar folded;
ziU32 entrySize, wordSize, copied; ziPudSection* section;
ziU8* entry; int wordSize;
int copied;
ziU8* word; ziU8* word;
int index; int index;
int fallback = 0; ziU32 entrySize;
ziPudHeader* table; ziPudHeader* table;
ziPudSection* section; ziU8* byteOutput;
if (!(ZI_WORK->pudCount <= 16 && ZI_WORK->pudCount != 0 && ZI_WORK->pudTable[ZI_WORK->pudCount - 1] != 0)) { if (!(ZI_WORK->pudCount <= 16 && ZI_WORK->pudCount != 0 && ZI_WORK->pudTable[ZI_WORK->pudCount - 1] != 0)) {
Zi8LogError(0x4B0, __zi8_work_data); Zi8LogError(0x4B0, __zi8_work_data);
return 0; return 0;
} }
if (language == 1) { if (language == 1) {
length &= 0x7F;
length *= 2; length *= 2;
} }
if (continuation == 0) { if (continuation == 0) {
table = (ziPudHeader*)ZI_WORK->pudTable[ZI_WORK->pudCount - 1]; table = (ziPudHeader*)ZI_WORK->pudTable[ZI_WORK->pudCount - 1];
index = 0;
section = table->sections; section = table->sections;
while (index < table->languageCount && section->language != language) { index = 0;
index++; while (index < table->languageCount) {
if (section->language == language) break;
section++; section++;
index++;
} }
if (table->languageCount <= index) { if (index >= table->languageCount) {
Zi8LogError(0x4F6, __zi8_work_data); Zi8LogError(0x4F6, __zi8_work_data);
return 0; return 0;
} }
@@ -90,90 +93,97 @@ ziU32 Zi8MatchPUDdata_ZHS(ziWChar* pattern, ziU8 length, ziU8 language, ziWChar*
ZI_WORK->unk_0x318 = 0; ZI_WORK->unk_0x318 = 0;
} }
for (;;) { for (;;) {
entry = (ziU8*)ZI_WORK->unk_0x310; word = (ziU8*)ZI_WORK->unk_0x310;
if (entry == 0) { if (word == 0) {
Zi8LogError(0x4B3, __zi8_work_data); Zi8LogError(0x4B3, __zi8_work_data);
return 0; return 0;
} }
while ((ziS32)ZI_WORK->unk_0x318 < (ziS32)ZI_WORK->unk_0x314) { while ((ziS32)ZI_WORK->unk_0x318 < (ziS32)ZI_WORK->unk_0x314) {
word = entry + 1; wordSize = *word++;
wordSize = *entry;
entrySize = wordSize; entrySize = wordSize;
if (language == 1) { if (language == 1) {
if (*word < ZI_WORK->unk_0x17) goto next; if (ZI_WORK->unk_0x17 > *word) goto next;
entrySize = wordSize - 1; wordSize--;
word = entry + 2; entrySize--;
word++;
wordSize = ZiGetZHWordSize((ziWChar*)word, entrySize); wordSize = ZiGetZHWordSize((ziWChar*)word, entrySize);
} else if (ZI_WORK->unk_0x31E != 0 && complete != 0 && wordSize > length && word[length] == 0x20) goto matchText; } else if (ZI_WORK->unk_0x31E != 0 && complete != 0 && length < wordSize && word[length] == 0x20) goto matchText;
if ((ziS32)length > (ziS32)wordSize || (complete != 0 && wordSize != length) || (complete == 0 && wordSize == length)) goto next; if ((ziS32)length > (ziS32)wordSize || (complete != 0 && wordSize != length) || (complete == 0 && wordSize == length)) {
if (language == 1) { next:
for (index = 0; index < length; index++) { ZI_WORK->unk_0x318++;
if (word[index] != ((ziU8*)pattern)[index]) goto next; word += entrySize;
}
goto matched;
}
matchText:
for (index = 0; index < length; index++) {
if (pattern[index] < 0xEFF1 || pattern[index] > 0xF37F) {
folded = Zi8ConvertUC2WC(word[index], language, __zi8_work_data);
if (folded != pattern[index] && (!ZI_WORK->unk_0x1F || !Zi8ChangeCharCase(0, &folded, language, __zi8_work_data) || folded != pattern[index])) goto next;
} else if (pattern[index] != Zi8ConvertUC2Key(word[index], language, __zi8_work_data)) goto next;
}
matched:
if (fallback) {
ZI_WORK->unk_0x310 = 0;
ZI_WORK->unk_0x318 = 0;
ZI_WORK->unk_0x314 = 0;
if (*pattern < 0xEFF1) *output = Zi8ConvertWC2Key(*pattern, language, __zi8_work_data);
else *output = *pattern;
return 1;
}
if (language == 1) {
index = 0;
for (copied = 0; index < (ziS32)wordSize && copied < capacity; copied++) {
((ziU8*)output)[index] = word[index];
((ziU8*)output)[index + 1] = word[index + 1];
index += 2;
}
Zi8CopyZHSpelling(word, spelling, spellingCapacity, entrySize, wordSize);
} else { } else {
for (copied = 0; copied < wordSize && copied < capacity; copied++) { if (language == 1) {
output[copied] = Zi8ConvertUC2WC(word[copied], language, __zi8_work_data); bytePattern = (ziU8*)pattern;
if (ZI_WORK->unk_0x31E != 0 && copied >= length && output[copied] == 0x20) { for (index = 0; index < length; index++) {
if (complete != 0 || copied >= length) break; if (word[index] != bytePattern[index]) goto next;
goto next; }
goto matched;
}
matchText:
for (index = 0; index < length; index++) {
if (pattern[index] >= 0xEFF1 && pattern[index] <= 0xF37F) {
if (pattern[index] != Zi8ConvertUC2Key(word[index], language, __zi8_work_data)) goto next;
} else {
folded = Zi8ConvertUC2WC(word[index], language, __zi8_work_data);
if (folded != pattern[index] && (!ZI_WORK->unk_0x1F || !Zi8ChangeCharCase(0, &folded, language, __zi8_work_data) || folded != pattern[index])) goto next;
} }
} }
matched:
if (fallback) {
ZI_WORK->unk_0x310 = 0;
ZI_WORK->unk_0x318 = 0;
ZI_WORK->unk_0x314 = 0;
if (*pattern >= 0xEFF1) *output = *pattern;
else *output = Zi8ConvertWC2Key(*pattern, language, __zi8_work_data);
return 1;
}
if (language == 1) {
byteOutput = (ziU8*)output;
for (index = copied = 0; index < (ziS32)wordSize && copied < capacity; copied++) {
byteOutput[index] = word[index];
index++;
byteOutput[index] = word[index];
index++;
}
Zi8CopyZHSpelling(word, spelling, spellingCapacity, entrySize, wordSize);
} else {
for (copied = 0; copied < wordSize && copied < capacity; copied++) {
output[copied] = Zi8ConvertUC2WC(word[copied], language, __zi8_work_data);
if (ZI_WORK->unk_0x31E != 0 && copied >= length && output[copied] == 0x20) {
if (complete != 0 || copied >= length) break;
goto next;
}
}
}
ZI_WORK->unk_0x318++;
ZI_WORK->unk_0x310 = (ziU32)(word + entrySize);
Zi8LogError(100, __zi8_work_data);
return (ziU8)copied;
} }
ZI_WORK->unk_0x318++;
ZI_WORK->unk_0x310 = (ziU32)(word + entrySize);
Zi8LogError(100, __zi8_work_data);
return (ziU8)copied;
next:
ZI_WORK->unk_0x318++;
entry = word + entrySize;
} }
if (length != 1 || complete == 0 || continuation != 0) { if (length == 1 && complete != 0 && continuation == 0) {
complete = 0;
fallback = 1;
ZI_WORK->unk_0x318 = 0;
} else {
ZI_WORK->unk_0x310 = 0; ZI_WORK->unk_0x310 = 0;
ZI_WORK->unk_0x318 = 0; ZI_WORK->unk_0x318 = 0;
ZI_WORK->unk_0x314 = 0; ZI_WORK->unk_0x314 = 0;
return 0; return 0;
} }
complete = 0;
fallback = 1;
ZI_WORK->unk_0x318 = 0;
} }
} }
ziU32 Zi8MatchPUDdata(ziWChar* pattern, ziU8 length, ziU8 language, ziWChar* output, ziU16 capacity, ziU8 complete, ziU8 continuation ZI_NEED_WORK) { ziU32 Zi8MatchPUDdata(ziWChar* pattern, ziU8 length, ziU8 language, ziWChar* output, ziU16 capacity, ziU8 complete, ziU8 continuation, struct __zi8_work_data_s* __zi8_work_data) {
ziU32 result; ziU32 result;
if (continuation == 0) ZI_WORK->pudCount = 1; if (continuation == 0) __zi8_work_data->pudCount = 1;
for (;;) { for (;;) {
result = Zi8_8147FD7C(pattern, length, language, output, capacity, complete, continuation, __zi8_work_data); result = Zi8_8147FD7C(pattern, length, language, output, capacity, complete, continuation, __zi8_work_data);
if ((ziU8)result != 0) break; if ((ziU8)result != 0) break;
if (++ZI_WORK->pudCount <= 16) { if (++__zi8_work_data->pudCount <= 16) {
continuation = 0; continuation = 0;
} else { } else {
ZI_WORK->pudCount = 1; __zi8_work_data->pudCount = 1;
break; break;
} }
} }

View File

@@ -68,7 +68,7 @@ ziU8 Zi8ZHaddSpace(ziWChar* src, ziU8 count, ziWChar* dst,
} }
if (pdst[k - 1] != 0xF360 && if (pdst[k - 1] != 0xF360 &&
(pdst[k - 1] < 0xF331 || pdst[k - 1] > 0xF335)) { (pdst[k - 1] < 0xF331 || pdst[k - 1] > 0xF335)) {
pdst[k++] = ZI_WORK->unk_0x1A; pdst[k++] = ZI_WORK->separator;
} }
psrc += i; psrc += i;
n -= i; n -= i;

View File

@@ -15,11 +15,11 @@ void Zi8Memset(ziPtr, ziU32, ziU32);
ziBool Zi8_81480224(ziUserWord* word ZI_NEED_WORK) { ziBool Zi8_81480224(ziUserWord* word ZI_NEED_WORK) {
ziU8 length; ziU8 length;
ziU8 position;
ziUwdNode* previous; ziUwdNode* previous;
ziUwdNode* current; ziUwdNode* current;
ziUwdNode* added; ziUwdNode* added;
ziUserWord* candidate; ziUserWord* candidate;
ziU8 position;
if (ZI_WORK->uwdCount >= 32) { if (ZI_WORK->uwdCount >= 32) {
Zi8LogError(0x19D, __zi8_work_data); Zi8LogError(0x19D, __zi8_work_data);
return 0; return 0;
@@ -41,7 +41,7 @@ ziBool Zi8_81480224(ziUserWord* word ZI_NEED_WORK) {
current = ZI_WORK->uwdList; current = ZI_WORK->uwdList;
while (current != 0) { while (current != 0) {
candidate = (ziUserWord*)current->word; candidate = (ziUserWord*)current->word;
if (ZI_WORK->unk_0x12E == 1 && word->priority > candidate->priority) break; if (ZI_WORK->unk_0x12E == 1 && candidate->priority < word->priority) break;
if (candidate->length == length) { if (candidate->length == length) {
position = 0; position = 0;
while (position < length) { while (position < length) {
@@ -56,8 +56,7 @@ ziBool Zi8_81480224(ziUserWord* word ZI_NEED_WORK) {
previous = current; previous = current;
current = current->next; current = current->next;
} }
length = ZI_WORK->uwdCount++; added = &ZI_WORK->uwdNodes[ZI_WORK->uwdCount++];
added = &ZI_WORK->uwdNodes[length];
if (previous == 0) { if (previous == 0) {
ZI_WORK->uwdList = added; ZI_WORK->uwdList = added;
added->next = current; added->next = current;
@@ -87,23 +86,24 @@ void Zi8_8148047C(ziPtr __zi8_work_data) {
ZI_WORK->uwdList = 0; ZI_WORK->uwdList = 0;
} }
ziU8 Zi8MatchUWDdata(ziWChar* pattern, ziU8 length, ziWChar* currentWord, ziU16 currentLength, ziU8 language, ziWChar* output, ziU16 capacity, ziU8 complete, ziU8 continuation ZI_NEED_WORK) { ziU8 Zi8MatchUWDdata(ziWChar* pattern, ziU8 length, ziWChar* currentWord, ziU16 currentLength, ziU8 language, ziWChar* output, ziU16 capacity, ziU8 complete, ziU8 continuation ZI_NEED_WORK) {
ziWChar folded; ziUserDictionary* dictionary;
int fallback = 0;
int visited = 0;
int prefixLength;
int position, previousOffset;
ziU32 size;
ziU8 entryLanguage;
ziU32 entryLength;
ziU8* cursor; ziU8* cursor;
ziU8* begin; ziU8* begin;
ziU8* boundary; ziU8* boundary;
ziU8* end; ziU8* end;
ziUserWord* candidate;
ziUserWord* previous; ziUserWord* previous;
ziUserWord* result;
ziUserDictionary* dictionary;
int firstSegment; int firstSegment;
ziU32 size;
int headerSize;
int entryLanguage;
volatile int entryLength;
int previousOffset;
int visited = 0;
int fallback = 0;
ziWChar folded;
ziU8* text;
int position;
int prefixLength;
Zi8LogError(100, __zi8_work_data); Zi8LogError(100, __zi8_work_data);
if (!(ZI_WORK->unk_0x138 <= 2 && ZI_WORK->unk_0x138 != 0 && ZI_WORK->unk_0x130[ZI_WORK->unk_0x138 - 1] != 0)) { if (!(ZI_WORK->unk_0x138 <= 2 && ZI_WORK->unk_0x138 != 0 && ZI_WORK->unk_0x130[ZI_WORK->unk_0x138 - 1] != 0)) {
Zi8ReplaceLastError(0x19C, __zi8_work_data); Zi8ReplaceLastError(0x19C, __zi8_work_data);
@@ -111,16 +111,17 @@ ziU8 Zi8MatchUWDdata(ziWChar* pattern, ziU8 length, ziWChar* currentWord, ziU16
} }
dictionary = ZI_WORK->unk_0x130[ZI_WORK->unk_0x138 - 1]; dictionary = ZI_WORK->unk_0x130[ZI_WORK->unk_0x138 - 1];
if (continuation != 0) { if (continuation != 0) {
result = Zi8_814803F4(__zi8_work_data); text = (ziU8*)Zi8_814803F4(__zi8_work_data);
entryLength = 0; entryLength = 0;
if (result != 0) { if (text != 0) {
entryLanguage = result->language; language = ((ziUserWord*)text)->language;
entryLength = result->length; entryLength = ((ziUserWord*)text)->length;
if (entryLength >= capacity) { if (entryLength >= capacity) {
Zi8_8148047C(__zi8_work_data); Zi8_8148047C(__zi8_work_data);
return 0; return 0;
} }
for (position = 0; position < (ziS32)entryLength; position++) output[position] = Zi8ConvertUC2WC(result->text[position], entryLanguage, __zi8_work_data); text = ((ziUserWord*)text)->text;
for (position = 0; position < (ziS32)entryLength; position++) output[position] = Zi8ConvertUC2WC(text[position], language, __zi8_work_data);
} }
return entryLength; return entryLength;
} }
@@ -130,17 +131,20 @@ ziU8 Zi8MatchUWDdata(ziWChar* pattern, ziU8 length, ziWChar* currentWord, ziU16
if (currentWord == 0 || currentLength == 0 || currentWord[currentLength - 1] != 0x20) ZI_WORK->unk_0x140 = 0; if (currentWord == 0 || currentLength == 0 || currentWord[currentLength - 1] != 0x20) ZI_WORK->unk_0x140 = 0;
else { else {
prefixLength = 0; prefixLength = 0;
for (position = currentLength - 2; currentWord[position] != 0x20 && position >= 0; position--) prefixLength++; for (position = currentLength - 2; position >= 0;) {
if (currentWord[position] == 0x20) break;
position--;
prefixLength++;
}
position++; position++;
if (prefixLength == 0 || prefixLength > 63) ZI_WORK->unk_0x140 = 0; if (prefixLength == 0 || prefixLength > 63) ZI_WORK->unk_0x140 = 0;
else { else {
ZI_WORK->unk_0x140 = 1; ZI_WORK->unk_0x140 = 1;
ZI_WORK->unk_0x141[0] = prefixLength + 5; ZI_WORK->unk_0x141[prefixLength + 4] = ZI_WORK->unk_0x141[0] = prefixLength + 5;
ZI_WORK->unk_0x141[prefixLength + 4] = prefixLength + 5;
ZI_WORK->unk_0x141[1] = language; ZI_WORK->unk_0x141[1] = language;
ZI_WORK->unk_0x141[2] = prefixLength; ZI_WORK->unk_0x141[2] = prefixLength;
previousOffset = 4; previousOffset = 4;
for (; prefixLength > 0; prefixLength--, position++) { while (prefixLength > 0) {
folded = currentWord[position]; folded = currentWord[position];
ZI_WORK->unk_0x141[previousOffset] = Zi8ConvertWC2UC(folded, language, __zi8_work_data); ZI_WORK->unk_0x141[previousOffset] = Zi8ConvertWC2UC(folded, language, __zi8_work_data);
ZI_WORK->unk_0x184[previousOffset] = 0; ZI_WORK->unk_0x184[previousOffset] = 0;
@@ -152,48 +156,56 @@ ziU8 Zi8MatchUWDdata(ziWChar* pattern, ziU8 length, ziWChar* currentWord, ziU16
ZI_WORK->unk_0x140 = 0; ZI_WORK->unk_0x140 = 0;
break; break;
} }
prefixLength--;
position++;
} }
} }
} }
if (ZI_WORK->unk_0x140 == 0 && length == 0) return 0; if (ZI_WORK->unk_0x140 == 0 && length == 0) return 0;
rescan: rescan:
begin = dictionary->entries + dictionary->current; cursor = begin = dictionary->entries + dictionary->current;
boundary = (ziU8*)dictionary + dictionary->boundary + 7; boundary = (ziU8*)dictionary + dictionary->boundary + 7;
end = (ziU8*)dictionary + dictionary->end + 7; end = (ziU8*)dictionary + dictionary->end + 7;
cursor = begin;
if (begin < boundary) firstSegment = 1; if (begin < boundary) firstSegment = 1;
else firstSegment = 0; else firstSegment = 0;
while (firstSegment ? cursor < boundary : cursor < end) { while ((cursor < boundary && firstSegment) || (cursor < end && !firstSegment)) {
size = *cursor; size = *cursor;
candidate = (ziUserWord*)cursor; if ((ziS32)ZI_WORK->unk_0x13C > visited++ || (((ziUserWord*)cursor)->size & 0xC0) != 0) {
position = visited++; next:
if ((ziS32)ZI_WORK->unk_0x13C <= position && (size & 0xC0) == 0) { if ((cursor += size) > end) {
if (firstSegment) break;
firstSegment = 1;
size = cursor - end - 1;
cursor = dictionary->entries + size;
}
} else {
previous = (ziUserWord*)(cursor + size); previous = (ziUserWord*)(cursor + size);
if ((ziU8*)previous > end) previous = (ziUserWord*)(cursor + ((ziU8*)dictionary - end) + 7); if ((ziU8*)previous > end) previous = (ziUserWord*)(dictionary->entries + (cursor - end - 1));
entryLanguage = candidate->language; text = cursor;
entryLength = candidate->length; headerSize = *text++;
if (entryLanguage == language && length <= entryLength && entryLength < capacity && (complete == 0 || entryLength == length) && (complete != 0 || entryLength != length)) { entryLanguage = *text++;
entryLength = *text++;
text++;
if (entryLanguage == language && entryLength >= length && entryLength < capacity && (complete == 0 || entryLength == length) && (complete != 0 || entryLength != length)) {
for (position = 0; position < length; position++) { for (position = 0; position < length; position++) {
if (pattern[position] < 0xEFF1 || pattern[position] > 0xF010) { if (pattern[position] >= 0xEFF1 && pattern[position] <= 0xF010) {
folded = Zi8ConvertUC2WC(candidate->text[position], language, __zi8_work_data); if (pattern[position] != Zi8ConvertUC2Key(text[position], language, __zi8_work_data)) goto next;
} else {
folded = Zi8ConvertUC2WC(text[position], language, __zi8_work_data);
if (folded != pattern[position] && (!ZI_WORK->unk_0x1F || !Zi8ChangeCharCase(0, &folded, language, __zi8_work_data) || folded != pattern[position])) goto next; if (folded != pattern[position] && (!ZI_WORK->unk_0x1F || !Zi8ChangeCharCase(0, &folded, language, __zi8_work_data) || folded != pattern[position])) goto next;
} else if (pattern[position] != Zi8ConvertUC2Key(candidate->text[position], language, __zi8_work_data)) goto next; }
} }
if (ZI_WORK->unk_0x140 != 0) { if (ZI_WORK->unk_0x140 != 0) {
if (ZI_WORK->unk_0x141[0] != previous->size || ZI_WORK->unk_0x141[1] != previous->language || ZI_WORK->unk_0x141[2] != previous->length) goto next; if (ZI_WORK->unk_0x141[0] != previous->size || ZI_WORK->unk_0x141[1] != previous->language || ZI_WORK->unk_0x141[2] != previous->length) goto next;
for (position = 4; position < ZI_WORK->unk_0x141[2] + 4; position++) { prefixLength = 4;
if (ZI_WORK->unk_0x141[position] != ((ziU8*)previous)[position] && ZI_WORK->unk_0x184[position] != ((ziU8*)previous)[position]) goto next; position = ZI_WORK->unk_0x141[2] + 4;
for (; prefixLength < position; prefixLength++) {
if (ZI_WORK->unk_0x141[prefixLength] != ((ziU8*)previous)[prefixLength] && ZI_WORK->unk_0x184[prefixLength] != ((ziU8*)previous)[prefixLength]) goto next;
} }
} }
Zi8_81480224(candidate, __zi8_work_data); Zi8_81480224((ziUserWord*)cursor, __zi8_work_data);
} }
} goto next;
next:
cursor += size;
if (end < cursor) {
if (firstSegment) break;
firstSegment = 1;
cursor = dictionary->entries + (cursor - end - 1);
} }
} }
if (ZI_WORK->unk_0x140 != 0 && length != 0) { if (ZI_WORK->unk_0x140 != 0 && length != 0) {
@@ -201,23 +213,24 @@ next:
visited = 0; visited = 0;
goto rescan; goto rescan;
} }
if (complete == 1 && length != 0 && continuation == 0) { if (length == 1 && complete != 0 && continuation == 0) {
complete = 0; complete = 0;
fallback = 1; fallback = 1;
visited = 0; visited = 0;
goto rescan; goto rescan;
} }
} }
result = Zi8_814803F4(__zi8_work_data); text = (ziU8*)Zi8_814803F4(__zi8_work_data);
entryLength = 0; if (text != 0) {
if (result != 0) { language = ((ziUserWord*)text)->language;
entryLanguage = result->language; entryLength = ((ziUserWord*)text)->length;
entryLength = result->length;
if (entryLength >= capacity) { if (entryLength >= capacity) {
Zi8_8148047C(__zi8_work_data); Zi8_8148047C(__zi8_work_data);
return 0; return 0;
} }
for (position = 0; position < (ziS32)entryLength; position++) output[position] = Zi8ConvertUC2WC(result->text[position], entryLanguage, __zi8_work_data); text = ((ziUserWord*)text)->text;
for (position = 0; position < (ziS32)entryLength; position++) output[position] = Zi8ConvertUC2WC(text[position], language, __zi8_work_data);
return entryLength;
} }
return entryLength; return 0;
} }

View File

@@ -1,7 +1,7 @@
#include <zi8clib/zierror.h> #include <zi8clib/zierror.h>
#include <zi8clib/zitypes.h> #include <zi8clib/zitypes.h>
extern ziU16 nodeHeaderTable[16]; extern const ziU16 nodeHeaderTable[16];
ziU32 ZiDAWGGetChild(ziU32 node) { ziU32 ZiDAWGGetChild(ziU32 node) {
ziU32 base; ziU32 base;
@@ -22,11 +22,10 @@ ziU32 ZiDAWGGetChild(ziU32 node) {
node += offset; node += offset;
if (((ziU32)header & 2) != 0) { if (((ziU32)header & 2) != 0) {
if ((*(ziU8*)node & 0x80) != 0) { if ((*(ziU8*)node & 0x80) != 0) {
offset = (*(ziU8*)node & 0x7f) * 0x10000 + ((ziU32)*((ziU8*)node + 1) & 0xffff) * 0x100 + 0x8000; offset = ((*(ziU8*)node & 0x7f) << 16) +
offset += *((ziU8*)node + 2); ((((ziU32)*((ziU8*)node + 1) & 0xffff) << 8) + *((ziU8*)node + 2)) + 0x8000;
} else { } else {
offset = ((ziU32)*(ziU8*)node & 0xffff) * 0x100; offset = (((ziU32)*(ziU8*)node & 0xffff) << 8) + (ziU32)*((ziU8*)node + 1);
offset += (ziU32)*((ziU8*)node + 1);
} }
} else if (((ziU32)header & 8) != 0) { } else if (((ziU32)header & 8) != 0) {
if ((*(ziU8*)node & 0x80) != 0) { if ((*(ziU8*)node & 0x80) != 0) {
@@ -42,41 +41,50 @@ ziU32 ZiDAWGGetChild(ziU32 node) {
return node; return node;
} }
ziU8* ZiDAWGGetSibling(ziU8* node) { typedef struct ziDawgLongOffset {
ziU16 header; ziU8 flags;
ziU8* cursor = node; ziU8 middle;
ziU8 low;
} ziDawgLongOffset;
typedef char ziDawgLongOffsetSizeCheck[(sizeof(ziDawgLongOffset) == 3) ? 1 : -1];
ziU8* ZiDAWGGetSibling(ziU8* cursor) {
ziS32 depth; ziS32 depth;
ziU8* node;
ziU16 header;
ziS32 offset; ziS32 offset;
depth = 0; depth = 0;
node = cursor;
offset = 0; offset = 0;
header = nodeHeaderTable[node[0] >> 4]; header = nodeHeaderTable[cursor[0] >> 4];
if ((header & 4) == 0) { if ((header & 4) == 0) {
node = 0; return 0;
} else { } else {
if ((header & 8) != 0) { if ((header & 8) != 0) {
if ((node[0] & 0xf) == 0xf) { if ((cursor[0] & 0xf) == 0xf) {
node += 2; cursor += 2;
} else { } else {
node += 1; cursor += 1;
} }
if ((header & 2) != 0) { if ((header & 2) != 0) {
if ((*node & 0x80) == 0) { if ((*cursor & 0x80) != 0) {
node += 2; cursor += 3;
} else { } else {
node += 3; cursor += 2;
} }
} }
if ((*node & 0x80) != 0) { if ((*cursor & 0x80) != 0) {
node += (*node & 0x7f) * 0x10000 + (ziU32)node[1] * 0x100 + node += (((const ziDawgLongOffset*)cursor)->flags & 0x7f) * 0x10000 +
(ziU32)node[2] + 0x8000; (((ziU32)(ziU16)cursor[1] << 8) +
((const ziDawgLongOffset*)cursor)->low) + 0x8000;
} else { } else {
node += (ziU16)*node * 0x100 + (ziU32)node[1]; node = cursor[1] + (node + (ziU16)*cursor * 0x100);
} }
return node;
} else { } else {
cursor = node;
do { do {
header = nodeHeaderTable[cursor[0] >> 4]; header = nodeHeaderTable[cursor[0] >> 4];
if ((cursor[0] & 0xf) == 0xf) { if ((cursor[0] & 0xf) == 0xf) {
@@ -88,14 +96,16 @@ ziU8* ZiDAWGGetSibling(ziU8* node) {
} }
if ((header & 1) != 0) { if ((header & 1) != 0) {
if ((header & 2) == 0) { if ((header & 2) != 0) {
depth++; if ((*cursor & 0x80) != 0) {
} else if ((*cursor & 0x80) != 0) { cursor += 3;
cursor += 3; offset += 3;
offset += 3; } else {
cursor += 2;
offset += 2;
}
} else { } else {
cursor += 2; depth++;
offset += 2;
} }
} }
@@ -113,18 +123,17 @@ ziU8* ZiDAWGGetSibling(ziU8* node) {
} }
} while (0 < depth); } while (0 < depth);
node += offset; return node + offset;
} }
} }
return node;
} }
ziU8 ZiDAWGgetEOWattribute(ziU32 node) { ziU8 ZiDAWGgetEOWattribute(ziU32 node) {
return (nodeHeaderTable[*(ziU8*)node >> 4] & 0x10) > 0; return (nodeHeaderTable[*(ziU8*)node >> 4] & 0x10) > 0;
} }
ziU32 ZiDAWGgetCHARattribute(ziPtr context, ziU32 node, ziPtr __zi8_work_data) { ziU32 ZiDAWGgetCHARattribute(zi8DawgCtx* context, ziU32 node, ziPtr __zi8_work_data) {
ziU8 key; ziU8 key;
ziU32 attribute; ziU32 attribute;
@@ -134,15 +143,15 @@ ziU32 ZiDAWGgetCHARattribute(ziPtr context, ziU32 node, ziPtr __zi8_work_data) {
key = (ziU32)*(ziU8*)node & 0xf; key = (ziU32)*(ziU8*)node & 0xf;
} }
if (key > ((zi8DawgCtx*)context)->cap) { if (key > context->cap) {
Zi8LogError(0x138b, __zi8_work_data); Zi8LogError(0x138b, __zi8_work_data);
return 0; return 0;
} }
attribute = key << 24; attribute = key << 24;
attribute |= ((ziU8*)((zi8DawgCtx*)context)->p0C)[key] << 16; attribute |= ((ziU8*)context->p0C)[key] << 16;
attribute += ((ziU32)((ziU8*)((zi8DawgCtx*)context)->p08)[key * 2] & 0xFFFF) << 8; attribute |= (((ziU32)((ziU8*)context->p08)[key * 2] & 0xFFFF) << 8) +
attribute += ((ziU8*)((zi8DawgCtx*)context)->p08)[key * 2 + 1]; ((ziU8*)context->p08 + key * 2)[1];
Zi8LogError(0x64, __zi8_work_data); Zi8LogError(0x64, __zi8_work_data);
return attribute; return attribute;
} }
@@ -155,60 +164,55 @@ ziU32 ZiDAWGGetGraph(ziPtr context) {
ziU32 ZiDAWGGetGraphInfo(zi8DawgCtx* context, ziU8* entry, ziU16* keys) { ziU32 ZiDAWGGetGraphInfo(zi8DawgCtx* context, ziU8* entry, ziU16* keys) {
ziU32 graph; ziU32 graph;
ziS32 result;
ziU32 end;
ziU8 depth; ziU8 depth;
ziU32 pair; ziU32 end;
ziS32 result;
graph = ZiDAWGGetGraph(context); graph = ZiDAWGGetGraph(context);
result = 0; result = 0;
pair = (((ziU16)entry[0] << 8) + entry[1]); if ((((ziU16)entry[0] << 8) + entry[1]) != 0 || (((ziU16)entry[2] << 8) + entry[3]) != 0) {
if (pair != 0) {
return 0; return 0;
} }
pair = (((ziU16)entry[2] << 8) + entry[3]); end = (ziU32)(entry + (((ziU16)entry[4] << 8) + entry[5] + 1) * 10);
if (pair == 0) { entry += 10;
end = (ziU32)(entry + (((ziU16)entry[4] << 8) + entry[5] + 1) * 10); depth = 0;
entry += 10; while ((depth < 2) && (*keys != 0)) {
depth = 0; if (*keys >= 0xeff1 && *keys <= 0xf010) {
while ((depth < 2) && (*keys != 0)) { goto checkEntry;
if ((*keys < 0xeff1) || (0xf010 < *keys)) {
break;
}
while (1) { while (1) {
if (*keys == (ziS32)(entry[3] + ((ziU16)entry[2] << 8))) { if (*keys == (ziS32)(((ziU16)entry[2] << 8) + entry[3])) {
break; break;
} }
entry += (entry[1] + ((ziU16)entry[0] << 8)) * 10 + 10; entry += (((ziU16)entry[0] << 8) + entry[1]) * 10 + 10;
checkEntry:
if (((ziU32)entry >= end) || if (((ziU32)entry >= end) ||
(*keys == (ziS32)(entry[3] + ((ziU16)entry[2] << 8)))) { (*keys == (ziS32)(((ziU16)entry[2] << 8) + entry[3]))) {
break; break;
} }
} }
} else {
if ((ziU32)entry >= end) { return 0;
return 0;
}
result = graph + (ziU32)entry[4] * 0x10000 + ((ziU16)entry[5] << 8) +
entry[6];
((zi8DawgCtx*)context)->unk_0x338 =
graph + (ziU32)entry[7] * 0x10000 + ((ziU16)entry[8] << 8) +
entry[9];
if (((zi8DawgCtx*)context)->unk_0x338 == graph) {
((zi8DawgCtx*)context)->unk_0x338 = 0;
}
if ((entry[1] + ((ziU16)entry[0] << 8)) == 0) {
break;
}
end = (ziU32)(entry + (entry[1] + ((ziU16)entry[0] << 8)) * 10 + 10);
entry += 10;
depth++;
keys++;
} }
if ((ziU32)entry >= end) {
return 0;
}
result = graph + (ziU32)entry[4] * 0x10000 + (((ziU16)entry[5] << 8) + entry[6]);
((zi8DawgCtx*)context)->unk_0x338 =
graph + (ziU32)entry[7] * 0x10000 + (((ziU16)entry[8] << 8) + entry[9]);
if (((zi8DawgCtx*)context)->unk_0x338 == graph) {
((zi8DawgCtx*)context)->unk_0x338 = 0;
}
if ((((ziU16)entry[0] << 8) + entry[1]) == 0) {
break;
}
end = (((ziU16)entry[0] << 8) + entry[1]) * 10 + ((ziU32)entry + 10);
entry += 10;
depth++;
keys++;
} }
return result; return result;

View File

@@ -20,127 +20,134 @@ typedef struct ziChineseEntry {
ziU8 offsetLow[2]; ziU8 offsetLow[2];
} ziChineseEntry; } ziChineseEntry;
ziU8 Zi8GetCandidatesOrCount(ziGetParam*, ziSearchState* ZI_NEED_WORK); ziU32 Zi8GetCandidatesOrCount(ziGetParam*, ziSearchState* ZI_NEED_WORK);
ziU8 Zi8GetFormatVersion(ziU8 ZI_NEED_WORK); ziU8 Zi8GetFormatVersion(ziU8 ZI_NEED_WORK);
ziPtr Zi8GetTableAddress(ziU8, ziU8 ZI_NEED_WORK); ziPtr Zi8GetTableAddress(ziU8, ziU8 ZI_NEED_WORK);
ziU16 Zi8Uni2Ord(ziWChar ZI_NEED_WORK); ziU16 Zi8Uni2Ord(ziWChar ZI_NEED_WORK);
typedef struct ziEncodedOrdinal {
ziU8 low;
ziU8 high;
} ziEncodedOrdinal;
typedef char ziEncodedOrdinalSizeCheck[(sizeof(ziEncodedOrdinal) == 2) ? 1 : -1];
ziBool Zi8IsWordW(ziWChar* word, ziU8 language ZI_NEED_WORK) { ziBool Zi8IsWordW(ziWChar* word, ziU8 language ZI_NEED_WORK) {
int count; ziChineseEntry* table = 0;
int offset; ziU8* baseData = 0;
ziU8 group; ziU8 group = 0;
ziU8 remaining; ziU8 remaining = 0;
ziU16 value; ziU16 value = 0;
ziWChar* cursor;
ziSearchState search;
ziGetParam request; ziGetParam request;
ziWChar ordinals[65]; ziWChar ordinals[65];
int length; int count;
int unmatched; int countLeft;
ziChineseEntry* entry; ziChineseEntry* entry;
ziWChar* cursor;
ziU8* data; ziU8* data;
ziU8 formats[8] = {1, 5, 0, 0, 0, 0, 0, 0}; ziU8 formats[8] = {1, 5, 0, 0, 0, 0, 0, 0};
ziU32 savedFormats = ZI_WORK->unk_0x1410; ziU32 savedFormats = ZI_WORK->formats;
ziU8 savedCount = ZI_WORK->unk_0x1418; ziU8 savedCount = ZI_WORK->formatCount;
search.flags = 0; ziSearchState search = {0};
search.word = 0;
search.length = 0;
search.position = 0;
search.capacity = 0;
search.options = 0;
Zi8LogError(100, __zi8_work_data); Zi8LogError(100, __zi8_work_data);
if (word == 0 || *word == 0) { if (word == 0 || *word == 0) {
Zi8ReplaceLastError(300, __zi8_work_data); Zi8ReplaceLastError(300, __zi8_work_data);
return 0; return 0;
} }
if (language != 1) { if (language != 1) {
for (length = 0; word[length] != 0; length++) { for (count = 0; word[count] != 0; count++) {
if (word[length] >= 0xEFF1 || length == 64) return 0; if (word[count] >= 0xEFF1 || count == 64) return 0;
} }
((ziU8*)&search.length)[0] = length; ((ziU8*)&search.length)[0] = count;
((ziU8*)&search.flags)[2] = 1; ((ziU8*)&search.flags)[2] = 1;
((ziU16*)&search.capacity)[0] = 64;
search.word = word; search.word = word;
((ziU16*)&search.capacity)[0] = 64;
request.language = language; request.language = language;
request.getMode = 0; request.getMode = 0;
request.subLanguage = 7; request.subLanguage = 7;
request.context = 1; request.context = 1;
request.getOptions = 0x81; request.getOptions = 0x81;
request.elements = word; request.elements = word;
request.elementCount = length; request.elementCount = count;
request.currentWord = 0; request.currentWord = 0;
request.wordCharCount = 0; request.wordCharCount = 0;
request.candidates = ordinals; request.candidates = ordinals;
request.maxCandidates = 1; request.maxCandidates = 1;
request.firstCandidate = 0; request.firstCandidate = 0;
ZI_WORK->unk_0x1410 = (ziU32)formats; ZI_WORK->formats = (ziU32)formats;
if (ZI_WORK->unk_0x1C[0] == 2) { if (ZI_WORK->unk_0x1C[0] == 2) {
ZI_WORK->unk_0x1418 = 0; ZI_WORK->formatCount = 0;
if (ZI_WORK->unk_0x09 & 1) formats[ZI_WORK->unk_0x1418++] = 1; if (ZI_WORK->unk_0x09 & 1) formats[ZI_WORK->formatCount++] = 1;
if (ZI_WORK->unk_0x09 & 4) formats[ZI_WORK->unk_0x1418++] = 2; if (ZI_WORK->unk_0x09 & 4) formats[ZI_WORK->formatCount++] = 2;
if (ZI_WORK->unk_0x09 & 2) formats[ZI_WORK->unk_0x1418++] = 3; if (ZI_WORK->unk_0x09 & 2) formats[ZI_WORK->formatCount++] = 3;
if (ZI_WORK->unk_0x09 & 8) formats[ZI_WORK->unk_0x1418++] = 4; if (ZI_WORK->unk_0x09 & 8) formats[ZI_WORK->formatCount++] = 4;
if (ZI_WORK->unk_0x09 & 1) formats[ZI_WORK->unk_0x1418++] = 5; if (ZI_WORK->unk_0x09 & 1) formats[ZI_WORK->formatCount++] = 5;
if (ZI_WORK->unk_0x09 & 4) formats[ZI_WORK->unk_0x1418++] = 6; if (ZI_WORK->unk_0x09 & 4) formats[ZI_WORK->formatCount++] = 6;
if (ZI_WORK->unk_0x09 & 2) formats[ZI_WORK->unk_0x1418++] = 7; if (ZI_WORK->unk_0x09 & 2) formats[ZI_WORK->formatCount++] = 7;
if (ZI_WORK->unk_0x09 & 8) formats[ZI_WORK->unk_0x1418++] = 8; if (ZI_WORK->unk_0x09 & 8) formats[ZI_WORK->formatCount++] = 8;
} else if (ZI_WORK->unk_0x1C[0] == 0) ZI_WORK->unk_0x1418 = 1; } else if (ZI_WORK->unk_0x1C[0] != 0) ZI_WORK->formatCount = 2;
else ZI_WORK->unk_0x1418 = 2; else ZI_WORK->formatCount = 1;
count = Zi8GetCandidatesOrCount(&request, &search, __zi8_work_data); count = Zi8GetCandidatesOrCount(&request, &search, __zi8_work_data);
ZI_WORK->unk_0x1410 = savedFormats; ZI_WORK->formats = savedFormats;
ZI_WORK->unk_0x1418 = savedCount; ZI_WORK->formatCount = savedCount;
if (count != 0) return 1; if (count != 0) return 1;
} }
if (language == 1) { if (language != 1) {
length = 0; Zi8ReplaceLastError(0x26C, __zi8_work_data);
do { return 0;
ordinals[length] = Zi8Uni2Ord(word[length], __zi8_work_data); }
if (ordinals[length] == 0xFFFF) return 0; {
length++; count = 0;
if (length == 64) return 0; while (word[count] != 0) {
} while (word[length] != 0); ordinals[count] = Zi8Uni2Ord(word[count], __zi8_work_data);
if (ordinals[count] == 0xFFFF) return 0;
count++;
if (count == 64) return 0;
}
{ {
if (length == 1) return 1; if (count-- == 1) return 1;
count = --length;
ordinals[count] |= 0x8000; ordinals[count] |= 0x8000;
ZI_WORK->cangjieEnabled = Zi8GetFormatVersion(1, __zi8_work_data) & 2; ZI_WORK->cangjieEnabled = Zi8GetFormatVersion(1, __zi8_work_data) & 2;
entry = (ziChineseEntry*)Zi8GetTableAddress(1, 0, __zi8_work_data) + ordinals[0]; table = (ziChineseEntry*)Zi8GetTableAddress(1, 0, __zi8_work_data);
data = (ziU8*)Zi8GetTableAddress(1, 1, __zi8_work_data) + ((entry->offsetHigh & 15) << 16 | ((entry->offsetLow[0] << 8) | entry->offsetLow[1])); entry = table + ordinals[0];
baseData = (ziU8*)Zi8GetTableAddress(1, 1, __zi8_work_data);
baseData += ((entry->offsetHigh & 15) << 16 | (entry->offsetLow[1] | (entry->offsetLow[0] << 8)));
data = baseData;
if (ZI_WORK->cangjieEnabled != 0) { if (ZI_WORK->cangjieEnabled != 0) {
switch (*data & 7) { switch (*data & 7) {
case 2: case 2:
offset = 2; countLeft = 2;
break; break;
case 3: case 3:
case 4: case 4:
offset = 3; countLeft = 3;
break; break;
case 5: case 5:
offset = 4; countLeft = 4;
break; break;
default: default:
offset = 1; countLeft = 1;
break; break;
} }
data += offset; data += countLeft;
} }
if ((*data & 0x80) == 0) return 0; if ((*data & 0x80) != 0) {
group = 0; group = 0;
data += ((*data & 0x7F) >> 4) + 1; data += ((*data & 0x7F) >> 4) + 1;
} else return 0;
while ((group & 0x80) == 0) { while ((group & 0x80) == 0) {
group = *data++; group = *data++;
for (remaining = group & 15; remaining != 0; remaining--) { for (remaining = group & 15; remaining != 0; remaining--) {
unmatched = count; countLeft = count;
cursor = ordinals; cursor = ordinals;
while (unmatched > 0) { while (countLeft > 0) {
value = data[0] | (data[1] << 8); value = ((ziU32)(ziU16)data[1] << 8) |
((const ziEncodedOrdinal*)data)->low;
data += 2; data += 2;
cursor++; if (value != *++cursor) break;
if (value != *cursor) break; countLeft--;
unmatched--;
if (value & 0x8000) break; if (value & 0x8000) break;
} }
if (unmatched == 0) return 1; if (countLeft == 0) return 1;
if (!(value & 0x8000)) { if (!(value & 0x8000)) {
data++; data++;
while (!(*data & 0x80)) data += 2; while (!(*data & 0x80)) data += 2;
@@ -151,7 +158,7 @@ ziBool Zi8IsWordW(ziWChar* word, ziU8 language ZI_NEED_WORK) {
Zi8LogError(0x2BD, __zi8_work_data); Zi8LogError(0x2BD, __zi8_work_data);
return 0; return 0;
} }
} else Zi8ReplaceLastError(0x26C, __zi8_work_data); }
return 0; return 0;
} }
ziWChar Zi8ConvertUC2UserKey(ziChar character, ziU8 language ZI_NEED_WORK) { ziWChar Zi8ConvertUC2UserKey(ziChar character, ziU8 language ZI_NEED_WORK) {

View File

@@ -30,8 +30,7 @@ ziU8 Zi8MatchOEMdata(ziWChar* pattern, ziU8 length, ziU8 language, ziWChar* word
index = ZI_WORK->oemIdx; index = ZI_WORK->oemIdx;
if ((ziS32)index >= ZI_WORK->oemLen) goto failed; if ((ziS32)index >= ZI_WORK->oemLen) goto failed;
if (ZI_WORK->oemMatch == 0) goto failed; if (ZI_WORK->oemMatch == 0) goto failed;
capacity--; if ((ziS32)length >= (ziS32)--capacity) {
if ((ziS32)length >= (ziS32)capacity) {
failed: failed:
return 0; return 0;
} }

View File

@@ -242,8 +242,8 @@ typedef struct WPADCB {
WPADCallback getInfoCB; // 0x988 WPADCallback getInfoCB; // 0x988
u8 getInfoBusy; // 0x98C u8 getInfoBusy; // 0x98C
u8 unk_0x98D; // 0x98D u8 encStatus; // 0x98D
u8 unk_0x98E; // 0x98E u8 continuous; // 0x98E
u8 unk_0x98F[0x9A0 - 0x990]; u8 unk_0x98F[0x9A0 - 0x990];
} WPADCB; } WPADCB;
@@ -261,7 +261,7 @@ void WPADiExcludeButton(s32 chan);
void WPADiCopyOut(s32 chan); void WPADiCopyOut(s32 chan);
BOOL WPADiSendSetPort(WPADCommandQueue* pQueue, u8 port, WPADCallback pCallback); BOOL WPADiSendSetPort(WPADCommandQueue* pQueue, u8 port, WPADCallback pCallback);
BOOL WPADiSendSetReportType(WPADCommandQueue* pQueue, s32 format, BOOL unk, WPADCallback pCallback); BOOL WPADiSendSetReportType(WPADCommandQueue* pQueue, s32 format, BOOL continuous, WPADCallback pCallback);
BOOL WPADiSendEnableDPD(WPADCommandQueue* pQueue, BOOL enable, WPADCallback pCallback); BOOL WPADiSendEnableDPD(WPADCommandQueue* pQueue, BOOL enable, WPADCallback pCallback);
BOOL WPADiSendEnableSpeaker(WPADCommandQueue* pQueue, BOOL enable, WPADCallback pCallback); BOOL WPADiSendEnableSpeaker(WPADCommandQueue* pQueue, BOOL enable, WPADCallback pCallback);
BOOL WPADiSendGetContStat(WPADCommandQueue* pQueue, WPADInfo* pInfo, WPADCallback pCallback); BOOL WPADiSendGetContStat(WPADCommandQueue* pQueue, WPADInfo* pInfo, WPADCallback pCallback);

View File

@@ -24,7 +24,7 @@ typedef struct WPADMemBlock {
int unk_0x04; // 0x04 int unk_0x04; // 0x04
s16 unk_0x08; // 0x08 s16 unk_0x08; // 0x08
int unk_0x0C; // 0x0C int unk_0x0C; // 0x0C
WPADCallback unk_0x10; // 0x10 WPADCallback callback; // 0x10
} WPADMemBlock; } WPADMemBlock;
typedef struct WPADGameInfo { typedef struct WPADGameInfo {

View File

@@ -72,7 +72,11 @@ struct DVDCommandBlock {
DVDCommandBlock* prev; // 0x04 DVDCommandBlock* prev; // 0x04
u32 command; // 0x08 u32 command; // 0x08
#ifdef BS2_MACH_VOLATILE_DVD_STATE
volatile s32 state;
#else
s32 state; // 0x0C s32 state; // 0x0C
#endif
u32 offset; // 0x10 u32 offset; // 0x10
u32 length; // 0x14 u32 length; // 0x14

View File

@@ -157,8 +157,20 @@ void AXFXChorusExpCallback(AXFX_BUFFERUPDATE* update, AXFX_CHORUS_EXP* fx) {
if (fx->delay.outPos >= fx->delay.sizeFP) fx->delay.outPos = 0; if (fx->delay.outPos >= fx->delay.sizeFP) fx->delay.outPos = 0;
} }
} }
static inline void chorus_gradient(AXFX_CHORUS_EXP_LFO* lfo, f32 depth, f32 step) {
depth /= step;
lfo->gradFactor = 65536.0f * depth;
}
static BOOL __InitParams(AXFX_CHORUS_EXP* fx) { static BOOL __InitParams(AXFX_CHORUS_EXP* fx) {
f32 delay, depth, step; f32 delay;
f32 depth;
f32 step;
u32 channel;
u32 sample;
s32 stepSamp;
s32 phaseAdd;
s32 depthSamp;
if (fx->delayTime < 0.1f || fx->delayTime > 50.0f) return FALSE; if (fx->delayTime < 0.1f || fx->delayTime > 50.0f) return FALSE;
if (fx->depth < 0.0f || fx->depth > 1.0f) return FALSE; if (fx->depth < 0.0f || fx->depth > 1.0f) return FALSE;
if (fx->rate < 0.1f || fx->rate > 2.0f) return FALSE; if (fx->rate < 0.1f || fx->rate > 2.0f) return FALSE;
@@ -168,61 +180,60 @@ static BOOL __InitParams(AXFX_CHORUS_EXP* fx) {
fx->lfo.table = __AXFXGetLfoSinTable(); fx->lfo.table = __AXFXGetLfoSinTable();
delay = 32.0f * fx->delayTime; delay = 32.0f * fx->delayTime;
depth = delay * fx->depth; depth = delay * fx->depth;
if (delay <= depth) { if (depth >= delay) {
depth -= 1.0f; depth -= 1.0f;
if (depth < 0.0f) depth = 0.0f; if (depth < 0.0f) depth = 0.0f;
} }
fx->lfo.depthSamp = 65536.0f * depth;
fx->lfo.phaseAdd = 65536.0f * (256.0f * fx->rate / 32000.0f);
step = (32000.0f / fx->rate) * (1.0f / 256.0f);
fx->lfo.stepSamp = 65536.0f * step;
fx->lfo.gradFactor = 65536.0f * (depth / step);
fx->lfo.lastNum = -1; fx->lfo.lastNum = -1;
fx->lfo.phase = 0; fx->lfo.phase = 0;
fx->lfo.sign = 0; fx->lfo.sign = 0;
fx->lfo.lastValue = 0; fx->lfo.lastValue = 0;
fx->lfo.grad = 0; fx->lfo.grad = 0;
fx->history[0][0] = 0.0f; depthSamp = 65536.0f * depth;
fx->history[0][1] = 0.0f; phaseAdd = 65536.0f * (256.0f * fx->rate / 32000.0f);
fx->history[0][2] = 0.0f; step = (32000.0f / fx->rate) / 256.0f;
fx->history[0][3] = 0.0f; stepSamp = 65536.0f * step;
fx->history[1][0] = 0.0f; fx->lfo.depthSamp = depthSamp;
fx->history[1][1] = 0.0f; fx->lfo.phaseAdd = phaseAdd;
fx->history[1][2] = 0.0f; fx->lfo.stepSamp = stepSamp;
fx->history[1][3] = 0.0f; chorus_gradient(&fx->lfo, depth, step);
fx->history[2][0] = 0.0f; for (channel = 0; channel < 3; channel++) {
fx->history[2][1] = 0.0f; for (sample = 0; sample < 4; sample++) {
fx->history[2][2] = 0.0f; fx->history[channel][sample] = 0.0f;
fx->history[2][3] = 0.0f; }
}
fx->histIndex = 0; fx->histIndex = 0;
return TRUE; return TRUE;
} }
static void __CalcLFO(s32* output, AXFX_CHORUS_EXP_LFO* lfo) { static void __CalcLFO(s32* output, AXFX_CHORUS_EXP_LFO* lfo) {
u32 remaining = 96; s32 start;
do { s64 value;
s32 value; s32 difference;
u32 phase = lfo->phase & 0xFFFF0000; s64 gradient;
u32 phase;
u32 sample;
for (sample = 0; sample < 96; sample++) {
phase = lfo->phase & 0xFFFF0000;
if (phase != lfo->lastNum) { if (phase != lfo->lastNum) {
s32 start, difference;
s64 product;
lfo->lastNum = phase; lfo->lastNum = phase;
phase >>= 16; phase >>= 16;
start = lfo->table[phase]; start = lfo->table[phase];
difference = lfo->table[(phase + 1) & 0x7F] - start; difference = lfo->table[(phase + 1) & 0x7F] - start;
product = (s64)start * lfo->depthSamp; gradient = difference;
value = ((u32)(product >> 32) << 8) | ((u32)product >> 24); gradient *= lfo->gradFactor;
product = (s64)difference * lfo->gradFactor; lfo->grad = gradient >> 24;
lfo->grad = ((u32)(product >> 32) << 8) | ((u32)product >> 24); value = (s64)start * lfo->depthSamp;
value >>= 24;
} else {
value = lfo->lastValue + lfo->grad;
} }
else value = lfo->lastValue + lfo->grad;
lfo->lastValue = value; lfo->lastValue = value;
if (lfo->sign != 0) value = -value; if (lfo->sign >= 1) value = -value;
lfo->phase += lfo->phaseAdd; lfo->phase += lfo->phaseAdd;
if (lfo->phase & 0xFF800000) { if (lfo->phase & 0xFF800000) {
lfo->phase &= 0x7FFFFF; lfo->phase &= 0x7FFFFF;
lfo->sign ^= 1; lfo->sign ^= 1;
} }
*output++ = value; *output++ = value;
remaining--; }
} while (remaining != 0);
} }

View File

@@ -11,7 +11,7 @@ typedef struct PFD_SDDRV_INFO {
u32 media_inserted; u32 media_inserted;
u32 media_ejected; u32 media_ejected;
s8 drive; s8 drive;
} PFD_SDDRV_INFO; } ATTRIBUTE_ALIGN(8) PFD_SDDRV_INFO;
typedef union PFD_SDDEV_STORAGE { typedef union PFD_SDDEV_STORAGE {
SDDev device; SDDev device;

View File

@@ -86,9 +86,15 @@ s32 uhf_msc_blk_mount(FADisk* disk) {
return ((device->flags >> 2) & 1) - 1; return ((device->flags >> 2) & 1) - 1;
} }
static inline u16 ReadTransferBlocks(u32 remaining, u32 limit) {
u16 count = limit;
if (remaining <= limit) { count = remaining; }
return count;
}
s32 uhf_msc_blk_pread(FADisk* disk, u8* buffer, u32 sector, u32 blocks, u32* completed) { s32 uhf_msc_blk_pread(FADisk* disk, u8* buffer, u32 sector, u32 blocks, u32* completed) {
struct { UHF_MSC_DEVICE* device; u16 blocks; } transfer;
s32 error; s32 error;
UHF_MSC_DEVICE* device;
u32 block_size; u32 block_size;
u8* transfer_buffer; u8* transfer_buffer;
u32 transfer_limit; u32 transfer_limit;
@@ -102,14 +108,24 @@ s32 uhf_msc_blk_pread(FADisk* disk, u8* buffer, u32 sector, u32 blocks, u32* com
if (blocks == 0) { if (blocks == 0) {
return 0; return 0;
} }
device = uhf_msc_blk_find_device(disk); transfer.device = NULL;
if (device == NULL) { {
u32 index;
UHF_MSC_DEVICE* candidate;
for (candidate = uhg_msc_blk_device_tbl, index = 0; index < 8; candidate++, index++) {
if (candidate->disk == disk) {
transfer.device = &uhg_msc_blk_device_tbl[index];
break;
}
}
}
if (transfer.device == NULL) {
return -1; return -1;
} }
if (!(device->flags & 4)) { if (!(transfer.device->flags & 4)) {
return -1; return -1;
} }
block_size = device->block_size; block_size = transfer.device->block_size;
if (block_size == 0) { if (block_size == 0) {
return -1; return -1;
} }
@@ -127,21 +143,18 @@ s32 uhf_msc_blk_pread(FADisk* disk, u8* buffer, u32 sector, u32 blocks, u32* com
transfer_buffer = buffer; transfer_buffer = buffer;
} }
do { do {
u16 transfer_blocks = transfer_limit; transfer.blocks = ReadTransferBlocks(blocks, transfer_limit);
if (blocks <= transfer_limit) { error = usbh_msc_read10(transfer.device, sector, transfer.blocks, transfer_buffer, sense);
transfer_blocks = blocks;
}
error = usbh_msc_read10(device, sector, transfer_blocks, transfer_buffer, sense);
if (error == 0) { if (error == 0) {
if (!cacheable) { if (!cacheable) {
memcpy(buffer, transfer_buffer, transfer_blocks * block_size); memcpy(buffer, transfer_buffer, transfer.blocks * block_size);
buffer += transfer_blocks * block_size; buffer += transfer.blocks * block_size;
} else { } else {
transfer_buffer += transfer_blocks * block_size; transfer_buffer += transfer.blocks * block_size;
} }
blocks -= transfer_blocks; blocks -= transfer.blocks;
sector += transfer_blocks; sector += transfer.blocks;
*completed += transfer_blocks; *completed += transfer.blocks;
if (blocks == 0) { if (blocks == 0) {
break; break;
} }
@@ -151,8 +164,8 @@ s32 uhf_msc_blk_pread(FADisk* disk, u8* buffer, u32 sector, u32 blocks, u32* com
case 11: case 11:
break; break;
case 34: case 34:
if (device->disk != NULL) { if (transfer.device->disk != NULL) {
pdm_disk_notify_media_insert(device->disk); pdm_disk_notify_media_insert(transfer.device->disk);
} }
break; break;
default: default:
@@ -186,7 +199,17 @@ s32 uhf_msc_blk_pwrite(FADisk* disk, u8* buffer, u32 sector, u32 blocks, u32* co
if (blocks == 0) { if (blocks == 0) {
return 0; return 0;
} }
device = uhf_msc_blk_find_device(disk); device = NULL;
{
u32 index;
UHF_MSC_DEVICE* candidate;
for (candidate = uhg_msc_blk_device_tbl, index = 0; index < 8; candidate++, index++) {
if (candidate->disk == disk) {
device = &uhg_msc_blk_device_tbl[index];
break;
}
}
}
if (device == NULL) { if (device == NULL) {
return -1; return -1;
} }

View File

@@ -550,7 +550,15 @@ pf_s32 PFCACHE_DoWriteSector(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_head, const pf
#pragma dont_inline reset #pragma dont_inline reset
#pragma dont_inline on static inline pf_u32 PFCACHE_RecordPageEndOverlap(PF_CACHE_PAGE* p_page, pf_u32 end_sector, pf_u32* p_num_success, pf_u32* p_num_rest_sector) {
pf_u32 last_sector = end_sector - 1;
pf_u32 num_overlap = end_sector - p_page->sector;
*p_num_success += num_overlap;
*p_num_rest_sector -= num_overlap;
p_page->stat |= 2;
return last_sector;
}
pf_s32 PFCACHE_DoWriteNumSectorAndFreeIfNeeded(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_head, const pf_u8* p_buf, pf_u32 sector, 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_u32 num_sector, pf_u32* p_num_success) {
PF_CACHE_PAGE* p_page = PF_NULL; PF_CACHE_PAGE* p_page = PF_NULL;
@@ -609,11 +617,9 @@ pf_s32 PFCACHE_DoWriteNumSectorAndFreeIfNeeded(PF_VOLUME* p_vol, PF_CACHE_PAGE**
(p_page->sector + p_page->size) >= (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], 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); (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)); num_overlap = num_sector;
last_sector = p_page->sector + num_overlap - 1; num_overlap += sector;
*p_num_success += num_overlap; last_sector = PFCACHE_RecordPageEndOverlap(p_page, num_overlap, p_num_success, &num_rest_sector);
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_ebuf = &p_page->buffer[(last_sector - p_page->sector) << p_vol->bpb.log2_bytes_per_sector];
p_page->p_mod_sbuf = p_page->buffer; p_page->p_mod_sbuf = p_page->buffer;
if (p_page->p_mod_ebuf == NULL || p_page->p_mod_ebuf < p_ebuf) { if (p_page->p_mod_ebuf == NULL || p_page->p_mod_ebuf < p_ebuf) {

View File

@@ -603,31 +603,35 @@ pf_s32 PFCLUSTER_InsertCluster(PFCLUSTER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent,
pf_s32 PFCLUSTER_DeleteCluster(PFCLUSTER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent, 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_u32 cluster_index, pf_u32 num_clusters, pf_u32* p_deleted_clusters) {
struct ClusterDeletion {
pf_u32 length;
pf_u32 cluster_size;
pf_u32 position;
};
struct ClusterDeletion deletion;
pf_s32 err; pf_s32 err;
pf_u32 previous_cluster; pf_u32 previous_cluster;
pf_u32 next_cluster; pf_u32 next_cluster;
pf_u32 first_deleted_cluster; pf_u32 first_deleted_cluster;
pf_u32 last_deleted_cluster; pf_u32 last_deleted_cluster;
PF_VOLUME* p_vol; PF_VOLUME* p_vol;
pf_u32 cluster_size;
pf_u32 byte_position;
p_vol = p_ent->p_vol; p_vol = p_ent->p_vol;
cluster_size = p_vol->bpb.bytes_per_sector << p_vol->bpb.log2_sectors_per_cluster; deletion.cluster_size = p_vol->bpb.bytes_per_sector << p_vol->bpb.log2_sectors_per_cluster;
byte_position = cluster_index * cluster_size; deletion.position = cluster_index * deletion.cluster_size;
err = PFFAT_TraceClustersChain(&p_iter->ffd, *p_iter->ffd.p_start_cluster, err = PFFAT_TraceClustersChain(&p_iter->ffd, *p_iter->ffd.p_start_cluster,
byte_position, &previous_cluster, &first_deleted_cluster); deletion.position, &previous_cluster, &first_deleted_cluster);
if (err != 0) return err; if (err != 0) return err;
if (cluster_index == 0) first_deleted_cluster = p_ent->start_cluster; if (cluster_index == 0) first_deleted_cluster = p_ent->start_cluster;
num_clusters = num_clusters * cluster_size; deletion.length = num_clusters * deletion.cluster_size;
if (num_clusters > p_ent->file_size - byte_position) num_clusters = p_ent->file_size - byte_position; if (deletion.length > p_ent->file_size - deletion.position) deletion.length = p_ent->file_size - deletion.position;
err = PFFAT_TraceClustersChain(&p_iter->ffd, first_deleted_cluster, num_clusters, &last_deleted_cluster, &next_cluster); err = PFFAT_TraceClustersChain(&p_iter->ffd, first_deleted_cluster, deletion.length, &last_deleted_cluster, &next_cluster);
if (err != 0) return err; if (err != 0) return err;
if (cluster_index == 0) { if (cluster_index == 0) {
if (next_cluster == PFFAT_GetValueOfEOC2(p_vol)) next_cluster = 0; if (next_cluster == PFFAT_GetValueOfEOC2(p_vol)) next_cluster = 0;
p_ent->start_cluster = next_cluster; p_ent->start_cluster = next_cluster;
} }
p_ent->file_size -= num_clusters; p_ent->file_size -= deletion.length;
PFENT_getcurrentDateTimeForEnt(&p_ent->modify_date, &p_ent->modify_time); PFENT_getcurrentDateTimeForEnt(&p_ent->modify_date, &p_ent->modify_time);
p_ent->access_date = p_ent->modify_date; p_ent->access_date = p_ent->modify_date;
err = PFENT_updateEntry(p_ent, 1); err = PFENT_updateEntry(p_ent, 1);
@@ -636,13 +640,13 @@ pf_s32 PFCLUSTER_DeleteCluster(PFCLUSTER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent,
err = PFCACHE_FlushDataCacheSpecific(p_vol, PF_NULL); err = PFCACHE_FlushDataCacheSpecific(p_vol, PF_NULL);
if (err != 0) return err; if (err != 0) return err;
} }
err = PFFAT_FreeChain(&p_iter->ffd, first_deleted_cluster, -1U, num_clusters); err = PFFAT_FreeChain(&p_iter->ffd, first_deleted_cluster, -1U, deletion.length);
if (err != 0) return err; if (err != 0) return err;
if (cluster_index != 0) { if (cluster_index != 0) {
err = PFFAT_WriteValueToSpecifiedCluster(p_vol, previous_cluster, next_cluster); err = PFFAT_WriteValueToSpecifiedCluster(p_vol, previous_cluster, next_cluster);
if (err != 0) return err; if (err != 0) return err;
} }
*p_deleted_clusters = num_clusters / cluster_size; *p_deleted_clusters = deletion.length / deletion.cluster_size;
if (num_clusters % cluster_size != 0) ++*p_deleted_clusters; if (deletion.length % deletion.cluster_size != 0) ++*p_deleted_clusters;
return 0; return 0;
} }

View File

@@ -140,15 +140,19 @@ 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 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); extern pf_s32 PFFAT_FreeChain(PFDIR_FFD* ffd, pf_u32 start_cluster, pf_u32 chain_index, pf_u32 size);
static inline pf_u32 current_directory_is_open(PF_VOLUME* volume, pf_u32 cluster) { static inline PF_CUR_DIR* current_directories(PFDIR_VOLUME_DIRS* state) {
return state->current_dirs;
}
static inline pf_u32 current_directory_is_open(PF_VOLUME* volume, const PF_DIR_ENT* entry) {
pf_u32 index; pf_u32 index;
for (index = 0; index < 4; index++) { for (index = 0; index < 4; index++) {
if (pf_vol_set.volume_state.volumes[index].p_vol == volume) { if (volume == pf_vol_set.volume_state.volumes[index].p_vol) {
PFDIR_VOLUME_DIRS* state = (PFDIR_VOLUME_DIRS*)volume; PFDIR_VOLUME_DIRS* state = (PFDIR_VOLUME_DIRS*)pf_vol_set.volume_state.volumes[index].p_vol;
PF_CUR_DIR* directory = state->current_dirs; PF_CUR_DIR* directory = current_directories(state);
pf_u32 slot; pf_u32 slot;
for (slot = 0; slot < 4; slot++, directory++) { for (slot = 0; slot < 4; slot++, directory++) {
if ((directory->stat & 1) != 0 && directory->directory.start_cluster == cluster) { return 1; } if ((directory->stat & 1) != 0 && directory->directory.start_cluster == entry->start_cluster) { return 1; }
} }
} }
} }
@@ -381,7 +385,7 @@ pf_s32 PFDIR_p_readdir(PFDIR_DIR* dir, PFDIR_READ_RESULT* result) {
return 0; 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 PFENT_findEntry(PFDIR_FFD*, PF_DIR_ENT*, pf_u32, PFDIR_STR*, pf_u32, pf_u32);
extern pf_s32 PFFAT_GetSectorSpecified(PFDIR_FFD*, pf_u32, 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 pf_s32 PFPATH_transformInUnicode(pf_u16*, const pf_s8*);
extern void PFPATH_SetSearchPattern(pf_s8*, pf_u16*, PFDIR_STR*); extern void PFPATH_SetSearchPattern(pf_s8*, pf_u16*, PFDIR_STR*);
@@ -408,17 +412,9 @@ extern void PFPATH_AdjustExtShortName(pf_s8* name, pf_u32 position);
extern pf_s32 PFCACHE_AllocateDataPage(PF_VOLUME* volume, pf_u32 sector, PF_CACHE_PAGE** page, pf_u32* size); extern pf_s32 PFCACHE_AllocateDataPage(PF_VOLUME* volume, pf_u32 sector, PF_CACHE_PAGE** page, pf_u32* size);
extern void PFCACHE_FreeDataPage(PF_VOLUME* volume, PF_CACHE_PAGE* page); extern void PFCACHE_FreeDataPage(PF_VOLUME* volume, PF_CACHE_PAGE* page);
static inline void set_dot_entry(pf_u8* buffer) { static inline void set_dot_entry(pf_u8* buffer) {
pf_u32 index;
buffer[0] = '.'; buffer[0] = '.';
buffer[1] = ' '; for (index = 1; index < 11; index++) { buffer[index] = ' '; }
buffer[2] = ' ';
buffer[3] = ' ';
buffer[4] = ' ';
buffer[5] = ' ';
buffer[6] = ' ';
buffer[7] = ' ';
buffer[8] = ' ';
buffer[9] = ' ';
buffer[10] = ' ';
} }
static inline void set_dot_dot_entry(pf_u8* buffer) { static inline void set_dot_dot_entry(pf_u8* buffer) {
@@ -453,7 +449,7 @@ extern pf_s32 PFENT_ITER_GetEntryOfPattern(PF_ENT_ITER* iter, PF_DIR_ENT* entry,
extern pf_s32 PFENT_ITER_FindEntry(PF_ENT_ITER* iter, PF_DIR_ENT* entry, PFDIR_STR* pattern, extern pf_s32 PFENT_ITER_FindEntry(PF_ENT_ITER* iter, PF_DIR_ENT* entry, PFDIR_STR* pattern,
pf_u8 attributes, pf_u32 start, pf_u32* found); pf_u8 attributes, pf_u32 start, pf_u32* found);
extern pf_s32 PFENT_findEntry(PFDIR_FFD* ffd, PF_DIR_ENT* entry, pf_u32 start, PFDIR_STR* pattern, extern pf_s32 PFENT_findEntry(PFDIR_FFD* ffd, PF_DIR_ENT* entry, pf_u32 start, PFDIR_STR* pattern,
pf_u8 attributes, pf_u32* logical_position, pf_u32* entry_position); pf_u32 required_attributes, pf_u32 forbidden_attributes);
extern pf_u32 PFSTR_GetCodeMode(PFDIR_STR* path); extern pf_u32 PFSTR_GetCodeMode(PFDIR_STR* path);
extern const pf_s8* PFSTR_GetStrPos(PFDIR_STR* path, pf_u32 target); extern const pf_s8* PFSTR_GetStrPos(PFDIR_STR* path, pf_u32 target);
extern pf_s32 PFPATH_SplitPathPattern(PF_STR* path, PFDIR_STR* directory, PFDIR_STR* pattern); extern pf_s32 PFPATH_SplitPathPattern(PF_STR* path, PFDIR_STR* directory, PFDIR_STR* pattern);
@@ -467,6 +463,16 @@ extern pf_s32 PFFILE_FsexecOpenFile(PF_DIR_ENT* entry, PF_ENT_ITER* iter, pf_u32
extern pf_s32 PFPATH_cmpName(const pf_s8* short_name, PFDIR_STR* pattern, pf_u32 short_search); extern pf_s32 PFPATH_cmpName(const pf_s8* short_name, PFDIR_STR* pattern, pf_u32 short_search);
extern pf_s32 PFPATH_cmpNameUni(const pf_u16* name, PFDIR_STR* pattern); extern pf_s32 PFPATH_cmpNameUni(const pf_u16* name, PFDIR_STR* pattern);
pf_s32 PFDIR_p_mkdir(PF_VOLUME* volume, PF_STR* path, pf_u32 option, PF_DTA* data) { pf_s32 PFDIR_p_mkdir(PF_VOLUME* volume, PF_STR* path, pf_u32 option, PF_DTA* data) {
pf_u32 index;
pf_u32* next_sector;
pf_u16 filename_length;
pf_u16 original_offset;
pf_u8 checksum;
pf_u8 lfn_count = 0;
pf_u32 cluster;
pf_u32 lfn_index;
pf_u32 entry_sector;
pf_s32 error;
PF_DIR_ENT parent_entry; PF_DIR_ENT parent_entry;
PF_DIR_ENT entry; PF_DIR_ENT entry;
pf_s8 normalized_name[512]; pf_s8 normalized_name[512];
@@ -480,19 +486,9 @@ pf_s32 PFDIR_p_mkdir(PF_VOLUME* volume, PF_STR* path, pf_u32 option, PF_DTA* dat
pf_u32 found; pf_u32 found;
pf_u32 page_size; pf_u32 page_size;
PF_CACHE_PAGE* page; PF_CACHE_PAGE* page;
pf_u8 lfn_count = 0;
pf_u32 sector = 0; pf_u32 sector = 0;
pf_u32 written; pf_u32 written;
pf_u32 position; pf_u32 position;
pf_u32 entry_sector;
pf_u16 filename_length;
pf_u16 original_offset;
pf_u8 checksum;
pf_u32 cluster;
pf_u32 index;
pf_u32 lfn_index;
pf_u32* next_sector;
pf_s32 error;
error = PFPATH_SplitPath((PFDIR_STR*)path, &directory, &filename); error = PFPATH_SplitPath((PFDIR_STR*)path, &directory, &filename);
if (error != 0) { return error; } if (error != 0) { return error; }
@@ -870,12 +866,15 @@ pf_s32 PFDIR_p_rename(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
pf_u32 found; pf_u32 found;
pf_u16 time; pf_u16 time;
pf_u8 deleted_marker[1] = {0xE5}; pf_u8 deleted_marker[1] = {0xE5};
pf_u16 saved_initial_char = 0;
pf_u32 sector;
pf_u32* next_sector;
pf_s32 filename_length; pf_s32 filename_length;
pf_s32 parse_error; pf_u32* next_sector;
pf_s32 allocation_error = 0; pf_s32 allocation_error = 0;
pf_u32 sector;
pf_u16 saved_initial_char = 0;
pf_s32 parse_error;
const pf_s8* filename;
pf_u32 remaining_lfns;
pf_u32 lfn_index;
pf_s32 error; pf_s32 error;
pf_u32 index; pf_u32 index;
PF_DIR_ENT* update_entry; PF_DIR_ENT* update_entry;
@@ -911,11 +910,11 @@ pf_s32 PFDIR_p_rename(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
} }
PFSTR_SetLocalStr(&destination_name, (pf_u32)normalized_name); PFSTR_SetLocalStr(&destination_name, (pf_u32)normalized_name);
if (PFSTR_GetCodeMode(&destination_name) == 1) { if (PFSTR_GetCodeMode(&destination_name) == 1) {
const pf_s8* filename = PFSTR_GetStrPos(&destination_name, 1); filename = PFSTR_GetStrPos(&destination_name, 1);
error = pf_strcmp(PFSTR_GetStrPos(&directory, 1), filename); error = pf_strcmp(PFSTR_GetStrPos(&directory, 1), filename);
} else { } else {
const pf_u16* filename = (const pf_u16*)PFSTR_GetStrPos(&destination_name, 1); filename = PFSTR_GetStrPos(&destination_name, 1);
error = pf_w_strcmp((const pf_u16*)PFSTR_GetStrPos(&directory, 1), filename); error = pf_w_strcmp((const pf_u16*)PFSTR_GetStrPos(&directory, 1), (const pf_u16*)filename);
} }
if (error != 0) { if (error != 0) {
error = PFENT_ITER_GetEntryOfPath(&destination_iter, &destination_entry, error = PFENT_ITER_GetEntryOfPath(&destination_iter, &destination_entry,
@@ -925,23 +924,24 @@ pf_s32 PFDIR_p_rename(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
} }
destination_entry.start_cluster = source_parent.start_cluster; destination_entry.start_cluster = source_parent.start_cluster;
PFFAT_InitFFD(&destination_iter.ffd, &destination_hint, volume, &destination_entry.start_cluster); PFFAT_InitFFD(&destination_iter.ffd, &destination_hint, volume, &destination_entry.start_cluster);
error = PFENT_findEntry(&destination_iter.ffd, &destination_entry, 0, &destination_name, 0x7F, 0, 0); error = PFENT_findEntry(&destination_iter.ffd, &destination_entry, 0, &destination_name, 0x7F, 0);
if (error == 0) { return 8; } if (error == 0) { return 8; }
if (error != 0 && error != 3) { return error; } if (error != 0 && error != 3) { return error; }
if ((source_entry.attr & 0x10) == 0) { if ((source_entry.attr & 0x10) == 0) {
if (PFFILE_IsOpened(&source_entry) != 0) { return 0x13; } if (PFFILE_IsOpened(&source_entry) != 0) { return 0x13; }
} else { } else {
if (directory_is_open(&source_entry) != 0) { return 0x13; } if (directory_is_open(&source_entry) != 0) { return 0x13; }
if (current_directory_is_open(source_entry.p_vol, source_entry.start_cluster) != 0) { return 0x1C; } if (current_directory_is_open(source_entry.p_vol, &source_entry) != 0) { return 0x1C; }
if (PFSTR_StrNCmp(&source_name, (const pf_s8*)"..", 1, 0, 2) == 0) { return 0x1C; } if (PFSTR_StrNCmp(&source_name, (const pf_s8*)"..", 1, 0, 2) == 0) { return 0x1C; }
if (PFSTR_StrNCmp(&source_name, (const pf_s8*)".", 1, 0, 1) == 0) { return 0x1C; } if (PFSTR_StrNCmp(&source_name, (const pf_s8*)".", 1, 0, 1) == 0) { return 0x1C; }
{ {
pf_u32 directory_sector;
PFDIR_SFD* file = ((PFDIR_VOLUME_DIRS*)volume)->sfds; PFDIR_SFD* file = ((PFDIR_VOLUME_DIRS*)volume)->sfds;
pf_u32 directory_sector = volume->bpb.first_data_sector + directory_sector = volume->bpb.first_data_sector +
((source_entry.start_cluster - 2) << volume->bpb.log2_sectors_per_cluster); ((source_entry.start_cluster - 2) << volume->bpb.log2_sectors_per_cluster);
for (index = 0; index < 5; index++, file++) { for (index = 0; index < 5; index++, file++) {
if ((file->stat & 1) != 0 && (file->stat & 2) != 0) { if ((file->stat & 1) != 0 && (file->stat & 2) != 0) {
if (file->dir_entry.p_vol == volume && file->dir_entry.entry_sector == directory_sector) { return 0x13; } if (volume == file->dir_entry.p_vol && directory_sector == file->dir_entry.entry_sector) { return 0x13; }
found = 0; found = 0;
error = PFENT_ITER_FindCluster(&file->dir_entry, source_entry.start_cluster, &found); error = PFENT_ITER_FindCluster(&file->dir_entry, source_entry.start_cluster, &found);
if (error != 0) { return error; } if (error != 0) { return error; }
@@ -961,12 +961,13 @@ pf_s32 PFDIR_p_rename(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
destination_entry.num_entry_LFNs = 0; destination_entry.num_entry_LFNs = 0;
PFENT_getcurrentDateTimeForEnt(&destination_entry.access_date, &time); PFENT_getcurrentDateTimeForEnt(&destination_entry.access_date, &time);
error = PFENT_updateEntry(&destination_entry, 1); error = PFENT_updateEntry(&destination_entry, 1);
goto finish_rename; if (error != 0) { return error; }
goto return_allocation_error;
} }
if (source_entry.num_entry_LFNs != 0 && (source_entry.small_letter_flag & 0x18) == 0) { if (source_entry.num_entry_LFNs != 0 && (source_entry.small_letter_flag & 0x18) == 0) {
saved_initial_char = source_entry.long_name[0]; saved_initial_char = source_entry.long_name[0];
source_entry.long_name[0] = 0; source_entry.long_name[0] = 0;
for (index = 1; index <= source_entry.num_entry_LFNs; index++) { for (lfn_index = 1; lfn_index <= source_entry.num_entry_LFNs; lfn_index++) {
error = PFENT_ITER_Retreat(&source_iter, 0); error = PFENT_ITER_Retreat(&source_iter, 0);
if (error != 0) { return error; } if (error != 0) { return error; }
error = PFSEC_WriteData(volume, deleted_marker, source_iter.sector, error = PFSEC_WriteData(volume, deleted_marker, source_iter.sector,
@@ -1004,7 +1005,7 @@ pf_s32 PFDIR_p_rename(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
if (allocation_error != 0) { if (allocation_error != 0) {
if (source_entry.num_entry_LFNs != 0 && (source_entry.small_letter_flag & 0x18) == 0) { if (source_entry.num_entry_LFNs != 0 && (source_entry.small_letter_flag & 0x18) == 0) {
source_entry.long_name[0] = saved_initial_char; source_entry.long_name[0] = saved_initial_char;
source_entry.entry_offset -= (pf_u16)(source_entry.num_entry_LFNs * 32); source_entry.entry_offset -= ((pf_u32)source_entry.num_entry_LFNs << 5) & (0xffU << 5);
} }
update_entry = &source_entry; update_entry = &source_entry;
} else { } else {
@@ -1013,13 +1014,13 @@ pf_s32 PFDIR_p_rename(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
PFENT_getcurrentDateTimeForEnt(&destination_entry.access_date, &time); PFENT_getcurrentDateTimeForEnt(&destination_entry.access_date, &time);
update_entry = &destination_entry; update_entry = &destination_entry;
} }
index = update_entry->num_entry_LFNs; remaining_lfns = update_entry->num_entry_LFNs;
if (index != 0 && (update_entry->small_letter_flag & 0x18) == 0) { if (remaining_lfns != 0 && (update_entry->small_letter_flag & 0x18) == 0) {
sector = update_entry->entry_sector; sector = update_entry->entry_sector;
next_sector = previous_chain; next_sector = previous_chain;
while (index >= 1) { while (remaining_lfns >= 1) {
PFENT_storeLFNEntryFieldsToBuf(entry_buffer, update_entry, index, PFENT_storeLFNEntryFieldsToBuf(entry_buffer, update_entry, remaining_lfns,
update_entry->check_sum, index == update_entry->num_entry_LFNs); update_entry->check_sum, remaining_lfns == update_entry->num_entry_LFNs);
error = PFSEC_WriteData(volume, entry_buffer, sector, update_entry->entry_offset, 32, &written, 0); error = PFSEC_WriteData(volume, entry_buffer, sector, update_entry->entry_offset, 32, &written, 0);
if (error != 0) { return error; } if (error != 0) { return error; }
if (written != 32) { return 0x11; } if (written != 32) { return 0x11; }
@@ -1028,13 +1029,13 @@ pf_s32 PFDIR_p_rename(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
update_entry->entry_offset = 0; update_entry->entry_offset = 0;
sector = *next_sector++; sector = *next_sector++;
} }
index--; remaining_lfns--;
} }
update_entry->entry_sector = sector; update_entry->entry_sector = sector;
} }
error = PFENT_updateEntry(update_entry, 1); error = PFENT_updateEntry(update_entry, 1);
finish_rename: if (error != 0) { return error; }
if (error != 0) { allocation_error = error; } return_allocation_error:
return allocation_error; return allocation_error;
} }
pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) { pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
@@ -1057,15 +1058,16 @@ pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
pf_u32 found; pf_u32 found;
pf_u16 time; pf_u16 time;
pf_u8 deleted_marker[1] = {0xE5}; pf_u8 deleted_marker[1] = {0xE5};
pf_u16 saved_initial_char = 0;
pf_u32 sector;
pf_u32* next_sector;
pf_s32 filename_length; pf_s32 filename_length;
pf_u32* next_sector;
pf_u32 parent_cluster;
pf_u32 sector;
pf_s32 parse_error; pf_s32 parse_error;
pf_s32 allocation_error; pf_s32 allocation_error;
pf_s32 error; pf_s32 error;
pf_u32 index; pf_u16 saved_initial_char = 0;
pf_u32 lfn_index; pf_u32 lfn_index;
pf_u32 index;
PF_DIR_ENT* update_entry; PF_DIR_ENT* update_entry;
error = PFENT_ITER_GetEntryOfPath(&source_iter, &source_entry, volume, (PFDIR_STR*)old_path, 0); error = PFENT_ITER_GetEntryOfPath(&source_iter, &source_entry, volume, (PFDIR_STR*)old_path, 0);
@@ -1083,7 +1085,7 @@ pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
if (error != 0) { return error; } if (error != 0) { return error; }
destination_entry.start_cluster = destination_parent.start_cluster; destination_entry.start_cluster = destination_parent.start_cluster;
PFFAT_InitFFD(&destination_iter.ffd, &destination_hint, volume, &destination_entry.start_cluster); PFFAT_InitFFD(&destination_iter.ffd, &destination_hint, volume, &destination_entry.start_cluster);
error = PFENT_findEntry(&destination_iter.ffd, &destination_entry, 0, &destination_name, 0x7F, 0, 0); error = PFENT_findEntry(&destination_iter.ffd, &destination_entry, 0, &destination_name, 0x7F, 0);
if (error == 0) { if (error == 0) {
if (destination_entry.entry_sector == source_entry.entry_sector && if (destination_entry.entry_sector == source_entry.entry_sector &&
destination_entry.entry_offset == source_entry.entry_offset) { return 0; } destination_entry.entry_offset == source_entry.entry_offset) { return 0; }
@@ -1094,18 +1096,19 @@ pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
if (PFFILE_IsOpened(&source_entry) != 0) { return 0x13; } if (PFFILE_IsOpened(&source_entry) != 0) { return 0x13; }
} else { } else {
if (directory_is_open(&source_entry) != 0) { return 0x13; } if (directory_is_open(&source_entry) != 0) { return 0x13; }
if (current_directory_is_open(source_entry.p_vol, source_entry.start_cluster) != 0) { return 0x1C; } if (current_directory_is_open(source_entry.p_vol, &source_entry) != 0) { return 0x1C; }
error = PFPATH_SplitPath((PFDIR_STR*)old_path, &directory, &source_name); error = PFPATH_SplitPath((PFDIR_STR*)old_path, &directory, &source_name);
if (error != 0) { return error; } if (error != 0) { return error; }
if (PFSTR_StrNCmp(&source_name, (const pf_s8*)"..", 1, 0, 2) == 0) { return 10; } if (PFSTR_StrNCmp(&source_name, (const pf_s8*)"..", 1, 0, 2) == 0) { return 10; }
if (PFSTR_StrNCmp(&source_name, (const pf_s8*)".", 1, 0, 1) == 0) { return 10; } if (PFSTR_StrNCmp(&source_name, (const pf_s8*)".", 1, 0, 1) == 0) { return 10; }
{ {
pf_u32 directory_sector;
PFDIR_SFD* file = ((PFDIR_VOLUME_DIRS*)volume)->sfds; PFDIR_SFD* file = ((PFDIR_VOLUME_DIRS*)volume)->sfds;
pf_u32 directory_sector = volume->bpb.first_data_sector + directory_sector = volume->bpb.first_data_sector +
((source_entry.start_cluster - 2) << volume->bpb.log2_sectors_per_cluster); ((source_entry.start_cluster - 2) << volume->bpb.log2_sectors_per_cluster);
for (index = 0; index < 5; index++, file++) { for (index = 0; index < 5; index++, file++) {
if ((file->stat & 1) != 0 && (file->stat & 2) != 0) { if ((file->stat & 1) != 0 && (file->stat & 2) != 0) {
if (file->dir_entry.p_vol == volume && file->dir_entry.entry_sector == directory_sector) { return 0x13; } if (volume == file->dir_entry.p_vol && directory_sector == file->dir_entry.entry_sector) { return 0x13; }
found = 0; found = 0;
error = PFENT_ITER_FindCluster(&file->dir_entry, source_entry.start_cluster, &found); error = PFENT_ITER_FindCluster(&file->dir_entry, source_entry.start_cluster, &found);
if (error != 0) { return error; } if (error != 0) { return error; }
@@ -1115,12 +1118,11 @@ pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
} }
destination_entry.start_cluster = destination_parent.start_cluster; destination_entry.start_cluster = destination_parent.start_cluster;
for (;;) { for (;;) {
pf_u32 parent_cluster;
if (destination_entry.start_cluster == 1 || destination_entry.start_cluster == 0) { break; } if (destination_entry.start_cluster == 1 || destination_entry.start_cluster == 0) { break; }
PFFAT_InitFFD(&destination_iter.ffd, &destination_hint, volume, &destination_entry.start_cluster); PFFAT_InitFFD(&destination_iter.ffd, &destination_hint, volume, &destination_entry.start_cluster);
PFSTR_InitStr(&parent_name, (const pf_s8*)"..", 1); PFSTR_InitStr(&parent_name, (const pf_s8*)"..", 1);
PFSTR_SetLocalStr(&parent_name, 0); PFSTR_SetLocalStr(&parent_name, 0);
error = PFENT_findEntry(&destination_iter.ffd, &destination_entry, 0, &parent_name, 0x7F, 0, 0); error = PFENT_findEntry(&destination_iter.ffd, &destination_entry, 0, &parent_name, 0x7F, 0);
if (error != 0) { return error; } if (error != 0) { return error; }
parent_cluster = destination_entry.start_cluster; parent_cluster = destination_entry.start_cluster;
if (parent_cluster == 1 || parent_cluster == 0) { break; } if (parent_cluster == 1 || parent_cluster == 0) { break; }
@@ -1140,9 +1142,10 @@ pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
parse_error = PFPATH_parseShortName(destination_entry.short_name, &destination_name); parse_error = PFPATH_parseShortName(destination_entry.short_name, &destination_name);
if (destination_entry.short_name[0] == 0) { return 2; } if (destination_entry.short_name[0] == 0) { return 2; }
if (source_entry.num_entry_LFNs != 0 && (source_entry.small_letter_flag & 0x18) == 0) { if (source_entry.num_entry_LFNs != 0 && (source_entry.small_letter_flag & 0x18) == 0) {
pf_u32 entry_index;
saved_initial_char = source_entry.long_name[0]; saved_initial_char = source_entry.long_name[0];
source_entry.long_name[0] = 0; source_entry.long_name[0] = 0;
for (index = 1; index <= source_entry.num_entry_LFNs; index++) { for (entry_index = 1; entry_index <= source_entry.num_entry_LFNs; entry_index++) {
error = PFENT_ITER_Retreat(&source_iter, 0); error = PFENT_ITER_Retreat(&source_iter, 0);
if (error != 0) { return error; } if (error != 0) { return error; }
error = PFSEC_WriteData(volume, deleted_marker, source_iter.sector, error = PFSEC_WriteData(volume, deleted_marker, source_iter.sector,
@@ -1180,7 +1183,7 @@ pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
if (allocation_error != 0) { if (allocation_error != 0) {
if (source_entry.num_entry_LFNs != 0 && (source_entry.small_letter_flag & 0x18) == 0) { if (source_entry.num_entry_LFNs != 0 && (source_entry.small_letter_flag & 0x18) == 0) {
source_entry.long_name[0] = saved_initial_char; source_entry.long_name[0] = saved_initial_char;
source_entry.entry_offset -= (source_entry.num_entry_LFNs & 0xff) * 32; source_entry.entry_offset -= ((pf_u32)source_entry.num_entry_LFNs << 5) & (0xffU << 5);
} }
update_entry = &source_entry; update_entry = &source_entry;
} else { } else {
@@ -1192,7 +1195,7 @@ pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
PFFAT_InitFFD(&source_iter.ffd, &source_hint, volume, &source_entry.start_cluster); PFFAT_InitFFD(&source_iter.ffd, &source_hint, volume, &source_entry.start_cluster);
PFSTR_InitStr(&parent_name, (const pf_s8*)"..", 1); PFSTR_InitStr(&parent_name, (const pf_s8*)"..", 1);
PFSTR_SetLocalStr(&parent_name, 0); PFSTR_SetLocalStr(&parent_name, 0);
error = PFENT_findEntry(&source_iter.ffd, &source_entry, 0, &parent_name, 0x7F, 0, 0); error = PFENT_findEntry(&source_iter.ffd, &source_entry, 0, &parent_name, 0x7F, 0);
if (error != 0) { return error; } if (error != 0) { return error; }
if (destination_parent.start_cluster == 1 || destination_parent.start_cluster == 0 || if (destination_parent.start_cluster == 1 || destination_parent.start_cluster == 0 ||
(destination_parent.start_cluster == 2 && volume->bpb.fat_type == FAT_32)) { (destination_parent.start_cluster == 2 && volume->bpb.fat_type == FAT_32)) {
@@ -1230,6 +1233,164 @@ pf_s32 PFDIR_p_move(PF_VOLUME* volume, PF_STR* old_path, PF_STR* new_path) {
return allocation_error; return allocation_error;
} }
pf_s32 PFDIR_p_fsnext(PF_DTA* data) {
PFDIR_FFD ffd;
PFDIR_FAT_HINT hint;
PF_DIR_ENT entry;
PFDIR_STR pattern;
pf_u32 logical_position = 0;
pf_u32 entry_position = 0;
pf_u32 code_mode;
pf_s32 index = 0;
pf_s32 error;
if ((data->status & 1) == 1) {
code_mode = 1;
error = PFSTR_InitStr(&pattern, data->reg_exp, code_mode);
} else {
code_mode = 2;
error = PFSTR_InitStr(&pattern, (const pf_s8*)((PF_DTAW*)data)->reg_expW, code_mode);
}
if (error != 0) {
return error;
}
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; }
data->parent_pos = entry_position + 1;
if (entry_position == 999999) { return 3; }
else { break; }
}
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) {
if ((pf_vol_set.setting & 2) == 2) {
pf_vol_set.setting &= 0xFFFFFFFC;
pf_vol_set.setting |= 1;
PFPATH_transformFromUnicodeToNormal(data->LongName, entry.long_name);
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) {
for (index = 0; index < 5; index++) {
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;
}
}
}
if (((PFDIR_VOLUME_DIRS*)data->p_vol)->num_opened_files == 0 || index == 5) {
data->FileSize = entry.file_size;
data->Time = entry.modify_time;
data->Date = entry.modify_date;
data->Attribute = entry.attr;
data->num_entry_LFNs = entry.num_entry_LFNs;
data->ordinal = entry.ordinal;
data->check_sum = entry.check_sum;
}
return 0;
}
pf_s32 PFDIR_p_fsfirst(PF_VOLUME* volume, PF_STR* path, pf_u8 attributes, PF_DTA* data) {
PFDIR_STR directory;
PFDIR_STR pattern;
PF_DIR_ENT entry;
PF_ENT_ITER iter;
pf_s32 error;
error = PFPATH_SplitPathPattern(path, &directory, &pattern);
if (error != 0) {
return error;
}
error = PFENT_ITER_GetEntryOfPattern(&iter, &entry, volume, &directory);
if (error != 0) {
return error;
}
if ((entry.attr & 0x10) == 0) {
return 0x14;
}
data->parent_start_cluster = entry.start_cluster;
data->parent_pos = 0;
data->p_vol = entry.p_vol;
data->attr = attributes;
data->status = 0;
if (PFSTR_GetCodeMode(&pattern) == 1) {
PFPATH_SetSearchPattern(data->reg_exp, 0, &pattern);
data->status |= 1;
} else {
PFPATH_SetSearchPattern(data->reg_exp, ((PF_DTAW*)data)->reg_expW, &pattern);
data->status |= 2;
}
return PFDIR_p_fsnext(data);
}
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_s32 index = 0;
pf_s32 error;
if ((attributes & 0x40) != 0) {
attributes = (pf_u8)(attributes & ~0x40);
}
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;
}
if (PFFILE_IsOpened(entry) != 0) {
return 0x13;
}
entry->attr = attributes;
}
PFENT_getcurrentDateTimeForEnt(&entry->access_date, &time);
error = PFENT_updateEntry(entry, 0);
if (error != 0) {
return error;
}
if ((mode & 0x80000000) == 0) {
data->Attribute = entry->attr;
}
error = PFCACHE_FlushDataCacheSpecific(entry->p_vol, 0);
if (error != 0) { return error; }
return 0;
}
pf_s32 PFDIR_p_fsexec_remove(PF_DTA* data, PF_DIR_ENT* entry, PF_ENT_ITER* iter) { 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_VOLUME_DIRS* volume_dirs = (PFDIR_VOLUME_DIRS*)entry->p_vol;
PFDIR_FAT_HINT hint; PFDIR_FAT_HINT hint;
@@ -1283,47 +1444,6 @@ pf_s32 PFDIR_p_fsexec_remove(PF_DTA* data, PF_DIR_ENT* entry, PF_ENT_ITER* iter)
return release_directory_chain(&iter->ffd, start_cluster, chain_size); 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 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_s32 index = 0;
pf_s32 error;
if ((attributes & 0x40) != 0) {
attributes = (pf_u8)(attributes & ~0x40);
}
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;
}
if (PFFILE_IsOpened(entry) != 0) {
return 0x13;
}
entry->attr = attributes;
}
PFENT_getcurrentDateTimeForEnt(&entry->access_date, &time);
error = PFENT_updateEntry(entry, 0);
if (error != 0) {
return error;
}
if ((mode & 0x80000000) == 0) {
data->Attribute = entry->attr;
}
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, pf_s32 PFDIR_p_fsexec_fopen(PF_DTA* data, PF_DIR_ENT* entry, PF_ENT_ITER* iter, pf_u32 flags,
pf_u32 mode) { pf_u32 mode) {
pf_s8 long_name[13]; pf_s8 long_name[13];
@@ -1910,121 +2030,3 @@ void PFDIR_chdmod(PF_STR* path, pf_u8 attributes) {
} }
volume_dirs->cache.signature = 0; volume_dirs->cache.signature = 0;
} }
pf_s32 PFDIR_p_fsnext(PF_DTA* data) {
PFDIR_FFD ffd;
PFDIR_FAT_HINT hint;
PF_DIR_ENT entry;
PFDIR_STR pattern;
pf_u32 logical_position = 0;
pf_u32 entry_position = 0;
pf_u32 code_mode;
pf_s32 index = 0;
pf_s32 error;
if ((data->status & 1) == 1) {
code_mode = 1;
error = PFSTR_InitStr(&pattern, data->reg_exp, code_mode);
} else {
code_mode = 2;
error = PFSTR_InitStr(&pattern, (const pf_s8*)((PF_DTAW*)data)->reg_expW, code_mode);
}
if (error != 0) {
return error;
}
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; }
data->parent_pos = entry_position + 1;
if (entry_position == 999999) { return 3; }
else { break; }
}
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) {
if ((pf_vol_set.setting & 2) == 2) {
pf_vol_set.setting &= 0xFFFFFFFC;
pf_vol_set.setting |= 1;
PFPATH_transformFromUnicodeToNormal(data->LongName, entry.long_name);
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) {
for (index = 0; index < 5; index++) {
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;
}
}
}
if (((PFDIR_VOLUME_DIRS*)data->p_vol)->num_opened_files == 0 || index == 5) {
data->FileSize = entry.file_size;
data->Time = entry.modify_time;
data->Date = entry.modify_date;
data->Attribute = entry.attr;
data->num_entry_LFNs = entry.num_entry_LFNs;
data->ordinal = entry.ordinal;
data->check_sum = entry.check_sum;
}
return 0;
}
pf_s32 PFDIR_p_fsfirst(PF_VOLUME* volume, PF_STR* path, pf_u8 attributes, PF_DTA* data) {
PFDIR_STR directory;
PFDIR_STR pattern;
PF_DIR_ENT entry;
PF_ENT_ITER iter;
pf_s32 error;
error = PFPATH_SplitPathPattern(path, &directory, &pattern);
if (error != 0) {
return error;
}
error = PFENT_ITER_GetEntryOfPattern(&iter, &entry, volume, &directory);
if (error != 0) {
return error;
}
if ((entry.attr & 0x10) == 0) {
return 0x14;
}
data->parent_start_cluster = entry.start_cluster;
data->parent_pos = 0;
data->p_vol = entry.p_vol;
data->attr = attributes;
data->status = 0;
if (PFSTR_GetCodeMode(&pattern) == 1) {
PFPATH_SetSearchPattern(data->reg_exp, 0, &pattern);
data->status |= 1;
} else {
PFPATH_SetSearchPattern(data->reg_exp, ((PF_DTAW*)data)->reg_expW, &pattern);
data->status |= 2;
}
return PFDIR_p_fsnext(data);
}

View File

@@ -511,8 +511,8 @@ pf_s32 PFENT_ITER_FindCluster(PF_DIR_ENT* p_ent, pf_u32 cluster, pf_bool* p_is_f
iter.ffd.cluster_link.buffer = PF_NULL; iter.ffd.cluster_link.buffer = PF_NULL;
iter.log2_entries_per_sector = p_ent->p_vol->bpb.log2_bytes_per_sector - 5; iter.log2_entries_per_sector = p_ent->p_vol->bpb.log2_bytes_per_sector - 5;
iter.file_sector_index = sector_index; iter.file_sector_index = sector_index;
entries_per_sector = 1 << iter.log2_entries_per_sector; iter.offset_mask = (1U << iter.log2_entries_per_sector) - 1;
iter.offset_mask = entries_per_sector - 1; entries_per_sector = 1U << iter.log2_entries_per_sector;
iter.p_vol = p_ent->p_vol; iter.p_vol = p_ent->p_vol;
iter.sector = p_ent->entry_sector; iter.sector = p_ent->entry_sector;
iter.offset = p_ent->entry_offset; iter.offset = p_ent->entry_offset;
@@ -726,25 +726,29 @@ pf_s32 PFENT_ITER_GetEntryOfIter(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent) {
return 0; return 0;
} }
static inline pf_u32 CopyLongNameFragment(PFITER_ENT_ITER* iter, pf_u8* destination, pf_u32 offset) {
pf_memcpy(destination, &iter->buf[1], 10);
pf_memcpy(destination + 10, &iter->buf[14], 12);
pf_memcpy(destination + 22, &iter->buf[28], 4);
return offset + 26;
}
pf_s32 PFENT_ITER_GetLFNEntryName(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent) { pf_s32 PFENT_ITER_GetLFNEntryName(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent) {
pf_u32 i;
pf_u32 index; pf_u32 index;
pf_u8* destination;
pf_u32 i;
pf_s32 err; pf_s32 err;
if (p_ent->num_entry_LFNs != 0 && !(p_ent->small_letter_flag & 0x18)) { if (p_ent->num_entry_LFNs != 0 && !(p_ent->small_letter_flag & 0x18)) {
index = 0; i = 0;
for (i = 0; i < p_ent->num_entry_LFNs; ++i) { for (index = 0; i < p_ent->num_entry_LFNs; ++i) {
pf_u16* destination;
err = PFENT_ITER_Retreat(p_iter, 0); err = PFENT_ITER_Retreat(p_iter, 0);
if (err != 0) return err; if (err != 0) return err;
err = PFENT_ITER_LoadEntry(p_iter); err = PFENT_ITER_LoadEntry(p_iter);
if (err != 0) return err; if (err != 0) return err;
destination = &p_ent->long_name[index]; destination = (pf_u8*)p_ent->long_name + index;
pf_memcpy(destination, &p_iter->buf[1], 10); index = CopyLongNameFragment(p_iter, destination, index);
pf_memcpy(destination + 5, &p_iter->buf[14], 12);
pf_memcpy(destination + 11, &p_iter->buf[28], 4);
index += 13;
} }
p_ent->long_name[index] = 0; p_ent->long_name[(p_ent->num_entry_LFNs * 26U) >> 1] = 0;
} }
return 0; return 0;
} }

View File

@@ -1458,6 +1458,19 @@ s32 PFFAT_CountFreeClusters(PF_VOLUME* volume, u32* numFreeClusters)
return 0; return 0;
} }
static inline s32 PFFAT_ClearEntryWithBuf(PF_VOLUME* volume, u32 cluster, PF_CACHE_PAGE* page) {
switch (volume->bpb.fat_type) {
case FAT_12:
return PFFAT12_WriteFATEntryWithBuf(volume, (u16)cluster, 0, page);
case FAT_16:
return PFFAT16_WriteFATEntryWithBuf(volume, cluster, 0, page);
case FAT_32:
return PFFAT32_WriteFATEntryWithBuf(volume, cluster, 0, page);
default:
return 15;
}
}
s32 PFFAT_FreeChain(PFFAT_FFD* file, u32 startCluster, u32 chainIndex, s32 PFFAT_FreeChain(PFFAT_FFD* file, u32 startCluster, u32 chainIndex,
u32 size) u32 size)
{ {
@@ -1523,9 +1536,9 @@ s32 PFFAT_FreeChain(PFFAT_FFD* file, u32 startCluster, u32 chainIndex,
} }
if (nextCluster == 0) { if (nextCluster == 0) {
s32 firstFlushError; s32 firstFlushError;
PF_CACHE_PAGE* flushPage;
u16 fatIndex;
u32 fatSector; u32 fatSector;
u16 fatIndex;
const PF_CACHE_PAGE* flushPage;
firstFlushError = 0; firstFlushError = 0;
flushPage = page; flushPage = page;
@@ -1546,33 +1559,19 @@ s32 PFFAT_FreeChain(PFFAT_FFD* file, u32 startCluster, u32 chainIndex,
PFCACHE_FreeDataPage(volume, page); PFCACHE_FreeDataPage(volume, page);
return 0; return 0;
} }
if (chainIndex != -1) { {
error = PFFAT_WriteClusterWithBuf(file, startCluster, chainIndex, s32 writeError;
0, 1, page); if (chainIndex != -1) {
chainIndex++; writeError = PFFAT_WriteClusterWithBuf(file, startCluster, chainIndex,
} else { 0, 1, page);
currentPage = page; chainIndex++;
switch (volume->bpb.fat_type) { } else {
case FAT_12: writeError = PFFAT_ClearEntryWithBuf(volume, startCluster, page);
error = PFFAT12_WriteFATEntryWithBuf( }
volume, (u16)startCluster, 0, currentPage); if (writeError != 0) {
break; PFCACHE_FreeDataPage(volume, page);
case FAT_16: return writeError;
error = PFFAT16_WriteFATEntryWithBuf(volume, startCluster, 0,
currentPage);
break;
case FAT_32:
error = PFFAT32_WriteFATEntryWithBuf(volume, startCluster, 0,
currentPage);
break;
default:
error = 15;
break;
} }
}
if (error != 0) {
PFCACHE_FreeDataPage(volume, page);
return error;
} }
if (size != 0 && fileSize != 0) { if (size != 0 && fileSize != 0) {
if (fileSize <= clusterSize) { if (fileSize <= clusterSize) {
@@ -1590,7 +1589,7 @@ s32 PFFAT_FreeChain(PFFAT_FFD* file, u32 startCluster, u32 chainIndex,
s32 firstFlushError; s32 firstFlushError;
u32 fatSector; u32 fatSector;
u16 fatIndex; u16 fatIndex;
PF_CACHE_PAGE* flushPage; const PF_CACHE_PAGE* flushPage;
firstFlushError = 0; firstFlushError = 0;
flushPage = page; flushPage = page;

View File

@@ -175,68 +175,70 @@ pf_s32 PFFAT12_WriteFATEntryWithBuf(PF_VOLUME* p_vol, pf_s16 cluster, pf_u16 val
pf_s32 PFFAT12_ReadFATEntryWithBuf(PF_VOLUME* p_vol , pf_u16 cluster , pf_u32* p_value , pf_s32 PFFAT12_ReadFATEntryWithBuf(PF_VOLUME* p_vol , pf_u16 cluster , pf_u32* p_value ,
PF_CACHE_PAGE* p_page ) { PF_CACHE_PAGE* p_page ) {
pf_s32 err; struct {
pf_u32 current_fat; pf_u32 sector;
pf_u32 sector; pf_u32 current_fat;
pf_u32 offset; pf_s32 err;
pf_u32 offset;
} state;
pf_s32 result; pf_s32 result;
#define LOAD_FAT_SECTOR(next_sector) \ #define LOAD_FAT_SECTOR(next_sector) \
if (p_page->sector != sector + (next_sector)) { \ if (p_page->sector != state.sector + (next_sector)) { \
if (p_page->option == 1) { \ if (p_page->option == 1) { \
for (err = 0; (pf_u16)err < p_vol->bpb.num_active_FATs; err++) { \ for (state.err = 0; (pf_u16)state.err < p_vol->bpb.num_active_FATs; state.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); \ VFiPFSEC_WriteFAT(p_vol, p_page->p_buf, p_page->sector + (pf_u16)state.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); \ state.err = VFiPFSEC_ReadFAT(p_vol, p_page->p_buf, state.sector + (next_sector), 0, p_vol->bpb.bytes_per_sector); \
if (err != 0) { continue; } \ if (state.err != 0) { continue; } \
p_page->sector = sector + (next_sector); \ p_page->sector = state.sector + (next_sector); \
} }
offset = (pf_u16)(cluster + (cluster >> 1)); state.offset = (pf_u16)(cluster + (cluster >> 1));
sector = p_vol->bpb.active_FAT_sector + (offset >> p_vol->bpb.log2_bytes_per_sector) & 0xFFFF; state.sector = p_vol->bpb.active_FAT_sector + (state.offset >> p_vol->bpb.log2_bytes_per_sector) & 0xFFFF;
if ((p_vol->bpb.ext_flags & 0x80) != 0) { if ((p_vol->bpb.ext_flags & 0x80) != 0) {
current_fat = p_vol->bpb.ext_flags & (0x01 | 0x02 | 0x04); state.current_fat = p_vol->bpb.ext_flags & (0x01 | 0x02 | 0x04);
} else { } else {
current_fat = 1; state.current_fat = 1;
} }
err = 0; state.err = 0;
while (PF_TRUE) { while (PF_TRUE) {
if (err == 0x1000 && p_vol->p_callback != PF_NULL) { if (state.err == 0x1000 && p_vol->p_callback != PF_NULL) {
result = ((PF_VOLUME_CB)p_vol->p_callback)(p_vol->last_driver_error); result = ((PF_VOLUME_CB)p_vol->p_callback)(p_vol->last_driver_error);
if (result == 0) { if (result == 0) {
err = 0; state.err = 0;
continue; continue;
} }
if (result == 1 && p_vol->bpb.num_active_FATs >= 2 && current_fat < p_vol->bpb.num_active_FATs) { if (result == 1 && p_vol->bpb.num_active_FATs >= 2 && state.current_fat < p_vol->bpb.num_active_FATs) {
current_fat++; state.current_fat++;
sector += p_vol->bpb.sectors_per_FAT; state.sector += p_vol->bpb.sectors_per_FAT;
err = 0; state.err = 0;
continue; continue;
} }
} else { } else {
LOAD_FAT_SECTOR(0); LOAD_FAT_SECTOR(0);
offset &= p_vol->bpb.bytes_per_sector - 1; state.offset &= p_vol->bpb.bytes_per_sector - 1;
if (offset == (p_vol->bpb.bytes_per_sector - 1)) { if (state.offset == (p_vol->bpb.bytes_per_sector - 1)) {
*p_value = *(p_page->p_buf + offset); *p_value = *(p_page->p_buf + state.offset);
if (p_page->option == 1) { if (p_page->option == 1) {
for (err = 0; (pf_u16)err < p_vol->bpb.num_active_FATs; err++) { for (state.err = 0; (pf_u16)state.err < p_vol->bpb.num_active_FATs; state.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); VFiPFSEC_WriteFAT(p_vol, p_page->p_buf, p_page->sector + (pf_u16)state.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); state.err = VFiPFSEC_ReadFAT(p_vol, p_page->p_buf, state.sector + 1, 0, p_vol->bpb.bytes_per_sector);
if (err != 0) { continue; } if (state.err != 0) { continue; }
p_page->sector = sector + 1; p_page->sector = state.sector + 1;
*p_value += (pf_u16)(*p_page->p_buf) << 8; *p_value += (pf_u16)(*p_page->p_buf) << 8;
} else { } else {
*p_value = ((pf_u16)p_page->p_buf[offset + 1] << 8) + *(p_page->p_buf + offset); *p_value = ((pf_u16)p_page->p_buf[state.offset + 1] << 8) + *(p_page->p_buf + state.offset);
} }
} }
break; break;
} }
if (err != 0) { if (state.err != 0) {
*p_value = -1; *p_value = -1;
return err; return state.err;
} }
if ((cluster & 0x01) != 0) { if ((cluster & 0x01) != 0) {
*p_value = *p_value >> 4; *p_value = *p_value >> 4;

View File

@@ -647,18 +647,16 @@ void PFFILE_Cursor_MoveToClusterEnd(PFFILE_FILE* file, pf_u32 size) {
} }
} }
PFFILE_SFD* PFFILE_GetSFD(PF_VOLUME* volume, PF_DIR_ENT* entry) { PFFILE_SFD* PFFILE_GetSFD(PFFILE_VOLUME_DIRS* volume_dirs, PF_DIR_ENT* entry) {
PFFILE_VOLUME_DIRS* volume_dirs = (PFFILE_VOLUME_DIRS*)volume;
PFFILE_SFD* first_free_sfd = PF_NULL;
PFFILE_SFD* sfd = volume_dirs->sfds;
pf_u32 first_free_index = 0; pf_u32 first_free_index = 0;
pf_u32 index = 0; PFFILE_SFD* first_free_sfd = PF_NULL;
pf_u32 index;
for (; index < 5; index++, sfd++) { for (index = 0; index < 5; index++) {
if ((volume_dirs->sfds[index].stat & 1) == 0 || if ((volume_dirs->sfds[index].stat & 1) == 0 ||
((volume_dirs->sfds[index].stat & 1) != 0 && (!volume_dirs->sfds[index].stat & 2) != 0)) { ((volume_dirs->sfds[index].stat & 1) != 0 && (!volume_dirs->sfds[index].stat & 2) != 0)) {
if (first_free_sfd == PF_NULL) { if (first_free_sfd == PF_NULL) {
first_free_sfd = sfd; first_free_sfd = &volume_dirs->sfds[index];
first_free_index = index; first_free_index = index;
} }
} else if (entry->p_vol == volume_dirs->sfds[index].dir_entry.p_vol && } else if (entry->p_vol == volume_dirs->sfds[index].dir_entry.p_vol &&
@@ -922,7 +920,7 @@ pf_s32 PFFILE_p_fopen(PF_VOLUME* volume, PF_STR* path, pf_u32 open_mode,
} }
} }
volume = entry.p_vol; volume = entry.p_vol;
sfd = PFFILE_GetSFD(volume, &entry); sfd = PFFILE_GetSFD((PFFILE_VOLUME_DIRS*)volume, &entry);
if (sfd == PF_NULL) { if (sfd == PF_NULL) {
return 0x15; return 0x15;
} }
@@ -1409,7 +1407,7 @@ pf_s32 PFFILE_FsexecOpenFile(PF_DIR_ENT* entry, PFFILE_ENT_ITER* iter,
} else { } else {
PFENT_getcurrentDateTimeForEnt(&entry->access_date, &access_time); PFENT_getcurrentDateTimeForEnt(&entry->access_date, &access_time);
} }
sfd = PFFILE_GetSFD(volume, entry); sfd = PFFILE_GetSFD((PFFILE_VOLUME_DIRS*)volume, entry);
if (sfd == PF_NULL) { if (sfd == PF_NULL) {
return 0x15; return 0x15;
} }

View File

@@ -321,56 +321,21 @@ pf_u32 PFPATH_DoMatchFileNameWithPattern(pf_u16 c_name, PF_FILE_NAME_ITER* p_nam
return 1; return 1;
} }
pf_bool PFPATH_MatchFileNameWithPattern(const pf_s8* file_name, PF_STR* p_pattern, pf_bool is_long_name) { pf_bool PFPATH_MatchFileNameWithPattern(const pf_s8* file_name, PF_STR* p_pattern, pf_bool is_long_name);
pf_u16 c_name;
pf_u16 c_pat;
PF_FILE_NAME_ITER name;
PF_STR pattern;
pf_bool result;
result = PF_TRUE;
name.buf = file_name;
name.current = 0;
name.kind = is_long_name;
name.index = 0;
pattern = *p_pattern;
if (PFSTR_GetCodeMode(p_pattern) == 1) {
if (is_long_name == PF_FALSE && (pf_vol_set.setting & 0x02) == 0x02 && PFPATH_CheckExtShortNameSignature(&pattern) == 1) {
result = PFPATH_CheckExtShortNameSignature(&pattern);
if (result == 1) {
name.index += 2;
pattern.p_head += 2;
}
}
} else if ((pf_vol_set.setting & 0x02) == 0x02 && is_long_name == PF_FALSE &&
PFSTR_StrNCmp(p_pattern, (pf_s8*)".", 1, 0, 1) != 0 && PFSTR_StrNCmp(p_pattern, (pf_s8*)"..", 1, 0, 2) != 0 &&
PFPATH_CheckExtShortName(p_pattern, 1, PF_FALSE) == 0) {
result = PF_FALSE;
}
if (result == PF_TRUE) {
c_name = PFPATH_GetNextCharOfFileName(&name);
c_pat = PFPATH_GetNextCharOfPattern(&pattern, is_long_name);
result = PFPATH_DoMatchFileNameWithPattern(c_name, &name, c_pat, &pattern, is_long_name);
}
return result;
}
pf_s32 PFPATH_cmpNameImpl(const pf_s8* name, const pf_s8* pattern, pf_u32* matched_end) { pf_s32 PFPATH_cmpNameImpl(const pf_s8* name, const pf_s8* pattern, pf_u32* matched_end) {
pf_u32 read_char; pf_u32 read_char;
pf_s32 recursive_error; pf_s32 recursive_error;
pf_u16 name_char; pf_s32 name_width;
pf_u16 pattern_char; pf_u16 pattern_char;
pf_u16 converted_pattern; pf_u16 converted_pattern;
pf_u16 converted_name; pf_u16 converted_name;
pf_s32 name_width; pf_u16 name_char;
pf_s32 pattern_width; pf_s32 pattern_width;
PF_PATH_VOLUME_SET* volume = &pf_vol_set;
while (*pattern != 0) { while (*pattern != 0) {
pattern_width = volume->codeset.oem_char_width(pattern); pattern_width = pf_vol_set.codeset.oem_char_width(pattern);
name_width = volume->codeset.oem_char_width(name); name_width = pf_vol_set.codeset.oem_char_width(name);
if (pattern_width == 1) { if (pattern_width == 1) {
read_char = pf_toupper(*pattern); read_char = pf_toupper(*pattern);
} else { } else {
@@ -399,18 +364,18 @@ pf_s32 PFPATH_cmpNameImpl(const pf_s8* name, const pf_s8* pattern, pf_u32* match
} }
case '*': { case '*': {
do { do {
pattern_width = volume->codeset.oem_char_width(pattern); pattern_width = pf_vol_set.codeset.oem_char_width(pattern);
if (pattern_width != 1) { if (pattern_width == 1) {
read_char = (pf_u16)PF_GET_LE_U16((const pf_u8*)pattern);
} else {
read_char = pf_toupper(*pattern); read_char = pf_toupper(*pattern);
} else {
read_char = (pf_u16)PF_GET_LE_U16((const pf_u8*)pattern);
} }
pattern_char = (pf_u16)read_char; pattern_char = (pf_u16)read_char;
pattern += pattern_width; pattern += pattern_width;
if (pattern_char == '?') { if (pattern_char == '?') {
if (name_char == 0) { return 1; } if (name_char == 0) { return 1; }
name += name_width; name += name_width;
name_width = volume->codeset.oem_char_width(name); name_width = pf_vol_set.codeset.oem_char_width(name);
if (name_width == 1) { read_char = pf_toupper(*name); } if (name_width == 1) { read_char = pf_toupper(*name); }
else { read_char = (pf_u16)PF_GET_LE_U16((const pf_u8*)name); } else { read_char = (pf_u16)PF_GET_LE_U16((const pf_u8*)name); }
name_char = (pf_u16)read_char; name_char = (pf_u16)read_char;
@@ -428,7 +393,7 @@ pf_s32 PFPATH_cmpNameImpl(const pf_s8* name, const pf_s8* pattern, pf_u32* match
} }
if (*matched_end != 0) { return recursive_error; } if (*matched_end != 0) { return recursive_error; }
} }
name_width = volume->codeset.oem_char_width(name); name_width = pf_vol_set.codeset.oem_char_width(name);
if (name_width == 1) { if (name_width == 1) {
read_char = pf_toupper(*name); read_char = pf_toupper(*name);
} else { } else {
@@ -578,6 +543,42 @@ PF_VOLUME* PFPATH_GetVolumeFromPath(PF_STR* p_path) {
return p_vol; return p_vol;
} }
pf_bool PFPATH_MatchFileNameWithPattern(const pf_s8* file_name, PF_STR* p_pattern, pf_bool is_long_name) {
pf_u16 c_name;
pf_u16 c_pat;
PF_FILE_NAME_ITER name;
PF_STR pattern;
pf_bool result;
result = PF_TRUE;
name.buf = file_name;
name.current = 0;
name.kind = is_long_name;
name.index = 0;
pattern = *p_pattern;
if (PFSTR_GetCodeMode(p_pattern) == 1) {
if (is_long_name == PF_FALSE && (pf_vol_set.setting & 0x02) == 0x02 && PFPATH_CheckExtShortNameSignature(&pattern) == 1) {
result = PFPATH_CheckExtShortNameSignature(&pattern);
if (result == 1) {
name.index += 2;
pattern.p_head += 2;
}
}
} else if ((pf_vol_set.setting & 0x02) == 0x02 && is_long_name == PF_FALSE &&
PFSTR_StrNCmp(p_pattern, (pf_s8*)".", 1, 0, 1) != 0 && PFSTR_StrNCmp(p_pattern, (pf_s8*)"..", 1, 0, 2) != 0 &&
PFPATH_CheckExtShortName(p_pattern, 1, PF_FALSE) == 0) {
result = PF_FALSE;
}
if (result == PF_TRUE) {
c_name = PFPATH_GetNextCharOfFileName(&name);
c_pat = PFPATH_GetNextCharOfPattern(&pattern, is_long_name);
result = PFPATH_DoMatchFileNameWithPattern(c_name, &name, c_pat, &pattern, is_long_name);
}
return result;
}
pf_s32 PFPATH_putShortName(pf_u8* pDirEntry, const pf_s8* short_name, pf_u8 attr) { pf_s32 PFPATH_putShortName(pf_u8* pDirEntry, const pf_s8* short_name, pf_u8 attr) {
pf_s32 i = 0; pf_s32 i = 0;

View File

@@ -225,8 +225,6 @@ typedef struct PFVOL_SET {
PFVOL_SET pf_vol_set; PFVOL_SET pf_vol_set;
static s8 default_volume_label[12] = "NO NAME "; static s8 default_volume_label[12] = "NO NAME ";
static const u8 deleted_entry_mark[8] = {0xE5};
extern s32 PFDRV_mount(PFVOL_VOLUME* volume); extern s32 PFDRV_mount(PFVOL_VOLUME* volume);
extern s32 PFDRV_unmount(PFVOL_VOLUME* volume, u32 mode); extern s32 PFDRV_unmount(PFVOL_VOLUME* volume, u32 mode);
extern s32 PFDRV_format(PFVOL_VOLUME* volume, const u8* format_options); extern s32 PFDRV_format(PFVOL_VOLUME* volume, const u8* format_options);
@@ -372,8 +370,13 @@ static inline s32 finalize_volume(PFVOL_VOLUME* volume) {
if (error != 0) { return error; } if (error != 0) { return error; }
return 0; return 0;
} }
static inline s32 copy_codeset(const PFVOL_CHARCODE* code_set) { static inline s32 copy_codeset(PFVOL_CHARCODE* code_set) {
pf_vol_set.codeset = *code_set; pf_vol_set.codeset.oem2unicode = code_set->oem2unicode;
pf_vol_set.codeset.unicode2oem = code_set->unicode2oem;
pf_vol_set.codeset.oem_char_width = code_set->oem_char_width;
pf_vol_set.codeset.is_oem_mb_char = code_set->is_oem_mb_char;
pf_vol_set.codeset.unicode_char_width = code_set->unicode_char_width;
pf_vol_set.codeset.is_unicode_mb_char = code_set->is_unicode_mb_char;
return 0; return 0;
} }
s32 PFVOL_DoMountVolume(PFVOL_VOLUME* volume) { s32 PFVOL_DoMountVolume(PFVOL_VOLUME* volume) {
@@ -584,7 +587,7 @@ s32 PFVOL_p_rmvvol(PFVOL_VOLUME* volume) {
u32 logical_position; u32 logical_position;
u32 entry_position; u32 entry_position;
u32 processed; u32 processed;
u8 deleted = deleted_entry_mark[0]; u8 deleted[1] = {0xE5};
s32 error; s32 error;
error = PFENT_GetRootDir(volume, &root_entry); error = PFENT_GetRootDir(volume, &root_entry);
@@ -599,7 +602,7 @@ s32 PFVOL_p_rmvvol(PFVOL_VOLUME* volume) {
return error; return error;
} }
if (entry_position != 999999) { if (entry_position != 999999) {
error = PFSEC_WriteData(volume, &deleted, entry.entry_sector, entry.entry_offset, 1, &processed, 0); error = PFSEC_WriteData(volume, deleted, entry.entry_sector, entry.entry_offset, 1, &processed, 0);
if (error != 0) { if (error != 0) {
return error; return error;
} }
@@ -1102,7 +1105,13 @@ s32 PFVOL_attach(PFVOL_DRIVER* driver, s32 notify_command, void* callback_data)
pf_vol_set.num_attached_drives++; pf_vol_set.num_attached_drives++;
if (PFDRV_IsInserted(volume) != 0) { if (PFDRV_IsInserted(volume) != 0) {
driver->stat |= 0x10; driver->stat |= 0x10;
attach_mount(volume, driver); error = clear_mount(volume);
if (error != 0) {
pf_vol_set.last_error = error;
volume->last_error = error;
return 0;
}
driver->stat |= 2;
} }
return 0; return 0;
} }
@@ -1458,7 +1467,7 @@ s32 PFVOL_getvolcfg(s8 drive, u32* config) {
return 0; return 0;
} }
s32 PFVOL_setcode(const PFVOL_CHARCODE* code_set) { s32 PFVOL_setcode(PFVOL_CHARCODE* code_set) {
if (pf_vol_set.num_mounted_volumes > 0) { if (pf_vol_set.num_mounted_volumes > 0) {
pf_vol_set.last_error = 36; pf_vol_set.last_error = 36;
return 36; return 36;
@@ -1466,17 +1475,21 @@ s32 PFVOL_setcode(const PFVOL_CHARCODE* code_set) {
return copy_codeset(code_set); return copy_codeset(code_set);
} }
static inline u32 ContextStatus(const PFVOL_CONTEXT* context) {
return context->stat & 1;
}
s32 PFVOL_regctx(void) { s32 PFVOL_regctx(void) {
s32 context_id;
s32 free_context_index;
u32 context_index; u32 context_index;
s32 free_context_index;
s32 context_id;
s32 error; s32 error;
error = PFSYS_GetCurrentContextID(&context_id); error = PFSYS_GetCurrentContextID(&context_id);
if (error != 0) { pf_vol_set.last_error = 26; return 26; } if (error != 0) { pf_vol_set.last_error = 26; return 26; }
free_context_index = 0; free_context_index = 0;
for (context_index = 1; context_index < 4; context_index++) { for (context_index = 1; context_index < 4; context_index++) {
u32 stat; u32 stat;
stat = pf_vol_set.context[context_index - 1].stat & 1; stat = ContextStatus(&pf_vol_set.context[context_index - 1]);
if (stat != 0 && pf_vol_set.context[context_index - 1].context_id == context_id) { break; } if (stat != 0 && pf_vol_set.context[context_index - 1].context_id == context_id) { break; }
if (stat == 0 && free_context_index == 0) { free_context_index = context_index; } if (stat == 0 && free_context_index == 0) { free_context_index = context_index; }
} }

View File

@@ -562,11 +562,13 @@ static inline u32 kbdChannelFlags(u32 channel) {
} }
static void kbd_led_handler(BOOL success, void* callbackArg) { static void kbd_led_handler(BOOL success, void* callbackArg) {
const KBDLEDCallbackData* callback;
u32 index; u32 index;
u32 err; u32 err;
index = (u32)callbackArg; index = (u32)callbackArg;
callback = &kbdLCBuf[index];
kbdCmdBuf[index].device = 0; kbdCmdBuf[index].device = 0;
if (kbdLCBuf[index].callbackAddress == (USBKBDCmdLEDCallback)(u32)kbdCmdBuf[index].device) { if (callback->callbackAddress == (USBKBDCmdLEDCallback)(u32)kbdCmdBuf[index].device) {
return; return;
} }
switch (success) { switch (success) {

View File

@@ -276,14 +276,15 @@ static inline f32 object_interval_distance(f32 interval) {
const f32 sensorIntervalConversion = 0.383864f; const f32 sensorIntervalConversion = 0.383864f;
static void reset_kpad(KPADInside* kpad) { static void reset_kpad(KPADInside* kpad) {
f32 upperY; f32 sensorDistance;
f32 distanceValue; f32 distanceValue;
f32 zero; f32 zero;
f32 sensorDistance; f32 upperY;
f32 lowerY; f32 lowerY;
f32 one; f32 one;
f32 negativeOne; f32 negativeOne;
KPADDPDObject* object; KPADDPDObject* object;
f32 calibratedDistance;
negativeOne = -1.0f; negativeOne = -1.0f;
one = 1.0f; one = 1.0f;
zero = 0.0f; zero = 0.0f;
@@ -299,8 +300,9 @@ static void reset_kpad(KPADInside* kpad) {
kpad->value508 = negativeOne / kp_err_dist_speed; kpad->value508 = negativeOne / kp_err_dist_speed;
kpad->value50C = kp_ah_circle_radius * kp_ah_circle_radius; kpad->value50C = kp_ah_circle_radius * kp_ah_circle_radius;
kpad->value514 = kp_err_dist_min; kpad->value514 = kp_err_dist_min;
distanceValue = kp_dist_vv1 / sensorDistance; calibratedDistance = kp_dist_vv1;
kpad->value510 = kp_dist_vv1; distanceValue = calibratedDistance / sensorDistance;
kpad->value510 = calibratedDistance;
kpad->status.release = 0; kpad->status.release = 0;
kpad->status.trig = 0; kpad->status.trig = 0;
kpad->status.hold = 0; kpad->status.hold = 0;
@@ -854,26 +856,33 @@ static s8 select_1obj_continue(KPADInside* kpad) {
} }
*matchedCandidate = *source; *matchedCandidate = *source;
{ {
f32 axisX = kpad->horizonTangent.x; f32 distance;
f32 normX = kpad->horizonAxis.x; f32 normY;
f32 axisY = kpad->horizonTangent.y; f32 vertical;
f32 normY = kpad->horizonAxis.y;
f32 distance = kpad->dpdObjectDistance;
f32 horizontal = axisX * normX;
f32 vertical = axisY * normX;
f32 offsetX;
f32 directionX;
f32 directionY; f32 directionY;
f32 offsetX;
f32 axisY;
f32 horizontal;
f32 axisX;
f32 directionX;
f32 normX;
f32 offsetY; f32 offsetY;
f32 tangentY; f32 tangentY;
f32 tangentX; f32 tangentX;
axisX = kpad->horizonTangent.x;
normX = kpad->horizonAxis.x;
axisY = kpad->horizonTangent.y;
normY = kpad->horizonAxis.y;
distance = kpad->dpdObjectDistance;
horizontal = axisX * normX;
vertical = axisY * normX;
tangentY = axisY * normY; tangentY = axisY * normY;
tangentX = axisX * normY; tangentX = axisX * normY;
directionX = horizontal + tangentY; directionX = horizontal + tangentY;
directionY = vertical - tangentX; directionY = vertical - tangentX;
offsetX = directionX * distance; offsetX = distance * directionX;
kpad->dpdObjectDirection.x = directionX; kpad->dpdObjectDirection.x = directionX;
offsetY = directionY * distance; offsetY = distance * directionY;
kpad->dpdObjectDirection.y = directionY; kpad->dpdObjectDirection.y = directionY;
if (matchedCandidate == kpad->dpdState.candidates) { if (matchedCandidate == kpad->dpdState.candidates) {
kpad->dpdState.candidates[1].x = matchedCandidate->x + offsetX; kpad->dpdState.candidates[1].x = matchedCandidate->x + offsetX;

View File

@@ -144,8 +144,8 @@ const u16 kprLookupTable437[] = {
0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0,
}; };
static void (*kprProcDeadKeysFP)(KPRQueue* queue); static void (*kprProcDeadKeysFP)(KPRQueue* queue) = NULL;
static void (*kprProcRomajiFP)(KPRQueue* queue); static void (*kprProcRomajiFP)(KPRQueue* queue) = NULL;
const char* __KPRVersion = "<< RVL_SDK - KPR \trelease build: Apr 20 2010 11:21:44 (0x4199_60831) >>"; const char* __KPRVersion = "<< RVL_SDK - KPR \trelease build: Apr 20 2010 11:21:44 (0x4199_60831) >>";
void KPRProcessDeadKeys(KPRQueue* queue); void KPRProcessDeadKeys(KPRQueue* queue);
@@ -242,6 +242,25 @@ u8 KPRLookAhead(KPRQueue* queue, u16* destination, u32 capacity) {
return queue->iCount + queue->oCount; return queue->iCount + queue->oCount;
} }
static inline u32 KPRConvertAltValue(u32 value, u32 leadingZero) {
if (value >= 128 && value <= 255) {
if (leadingZero) {
if (value < 160) {
value = kprLookupTable1252[value - 128];
}
} else {
value = kprLookupTable437[value - 128];
}
} else if (value > 255) {
u32 converted = 32;
if (value <= 0x6666666) {
converted = (u8)value;
}
value = converted;
}
return value;
}
BOOL KPRProcessAltKeypad(KPRQueue* queue, u16 character) { BOOL KPRProcessAltKeypad(KPRQueue* queue, u16 character) {
if (queue->altVal != 0) { if (queue->altVal != 0) {
u32 accumulator = queue->altVal & 0x7FFFFFFF; u32 accumulator = queue->altVal & 0x7FFFFFFF;
@@ -256,21 +275,7 @@ BOOL KPRProcessAltKeypad(KPRQueue* queue, u16 character) {
return TRUE; return TRUE;
} }
value = queue->altVal; value = queue->altVal;
if (value >= 128 && value <= 255) { value = KPRConvertAltValue(value, leadingZero);
if (leadingZero) {
if (value < 160) {
value = kprLookupTable1252[value - 128];
}
} else {
value = kprLookupTable437[value - 128];
}
} else if (value > 255) {
u32 converted = 32;
if (value <= 0x6666666) {
converted = (u8)value;
}
value = converted;
}
{ {
u16* destination; u16* destination;
int index = queue->oCount + queue->iCount; int index = queue->oCount + queue->iCount;

View File

@@ -484,6 +484,7 @@ static inline unsigned long __nupBase64EncodedSize(unsigned long length) {
} }
static void __nupBase64Encode(u8* output, u8* input, unsigned long length) { static void __nupBase64Encode(u8* output, u8* input, unsigned long length) {
static char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
u8* end = input + length; u8* end = input + length;
u32 value = 0; u32 value = 0;
u32 count = 0; u32 count = 0;
@@ -496,26 +497,19 @@ static void __nupBase64Encode(u8* output, u8* input, unsigned long length) {
if (count < 3) { if (count < 3) {
continue; continue;
} }
u8 encodedSecond = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[value >> 12 & 0x3f]; output[0] = alphabet[value >> 18 & 0x3f];
u8 encodedFirst = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[value >> 18 & 0x3f]; output[1] = alphabet[value >> 12 & 0x3f];
output[0] = encodedFirst; output[2] = alphabet[value >> 6 & 0x3f];
u8 encodedThird = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[value >> 6 & 0x3f]; output[3] = alphabet[value & 0x3f];
output[1] = encodedSecond;
u8 encodedFourth = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[value & 0x3f];
output[2] = encodedThird;
output[3] = encodedFourth;
count = 0; count = 0;
output += 4; output += 4;
} }
if (count == 2) { if (count == 2) {
value <<= 8; value <<= 8;
u8 encodedSecond = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[value >> 12 & 0x3f]; output[0] = alphabet[value >> 18 & 0x3f];
u8 encodedFirst = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[value >> 18 & 0x3f]; output[1] = alphabet[value >> 12 & 0x3f];
output[0] = encodedFirst; output[2] = alphabet[value >> 6 & 0x3f];
u8 encodedThird = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[value >> 6 & 0x3f];
output[1] = encodedSecond;
output[2] = encodedThird;
output[3] = fillByte; output[3] = fillByte;
return; return;
} }
@@ -523,10 +517,8 @@ static void __nupBase64Encode(u8* output, u8* input, unsigned long length) {
return; return;
} }
value <<= 16; value <<= 16;
u8 encodedSecond = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[value >> 12 & 0x3f]; output[0] = alphabet[value >> 18 & 0x3f];
u8 encodedFirst = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[value >> 18 & 0x3f]; output[1] = alphabet[value >> 12 & 0x3f];
output[0] = encodedFirst;
output[1] = encodedSecond;
output[2] = fillByte; output[2] = fillByte;
output[3] = fillByte; output[3] = fillByte;
} }

View File

@@ -50,12 +50,16 @@ int NHTTPGetHeaderAll(void*, char**);
void NHTTPCancelRequestAsync(int); void NHTTPCancelRequestAsync(int);
void NHTTPDestroyResponse(void*); void NHTTPDestroyResponse(void*);
static inline unsigned long NhttpBufferSize(unsigned long requested) {
if (requested != 0 && requested < 0x8000) return requested;
return 0x8000;
}
static u8* __nupNhttpBufFull(u8** buffer, unsigned long* length, unsigned long requested, void*, void*, HttpState* state) { static u8* __nupNhttpBufFull(u8** buffer, unsigned long* length, unsigned long requested, void*, void*, HttpState* state) {
u8* next = NULL; u8* next = NULL;
if (state->progress != NULL && *length != 0) { if (state->progress != NULL && *length != 0) {
state->progress(state->progressContext, *length); state->progress(state->progressContext, *length);
} }
if ((state->received + *length) < state->received) { if ((u32)(state->received + *length) < (u32)state->received) {
if (state->error == 0) state->error = -5012; if (state->error == 0) state->error = -5012;
} }
state->received += *length; state->received += *length;
@@ -69,22 +73,26 @@ static u8* __nupNhttpBufFull(u8** buffer, unsigned long* length, unsigned long r
if (state->error != 0) goto done; if (state->error != 0) goto done;
} }
next = *buffer; next = *buffer;
if (next == NULL) { switch ((u32)next) {
if (requested != 0 && requested < 0x8000) {} else requested = 0x8000; case 0: {
requested = NhttpBufferSize(requested);
next = (u8*)nup::__nupMalloc(requested); next = (u8*)nup::__nupMalloc(requested);
if (next == NULL) { if (next == NULL) {
state->error = -5000; state->error = -5000;
goto done; goto done;
} }
*length = requested; *length = requested;
break;
}
default: break;
} }
if (*length != 0) state->lastActivity = OSGetTime(); if (*length != 0) state->lastActivity = OSGetTime();
} }
} }
done: done:
if (state->error != 0) { if (state->error != 0) {
next = NULL;
*length = 0; *length = 0;
next = NULL;
} }
return next; return next;
} }
@@ -101,12 +109,17 @@ static void __nupNhttpReqDone(int result, void* response, HttpState* state) {
} }
static int __nupNhttpOp(char* url, NHTTPReqMethod method, char* headers, u8* body, unsigned long bodyLength, unsigned long limit, ProgressCallback progress, void* progressContext, FlushCallback flush, void* flushContext) { static int __nupNhttpOp(char* url, NHTTPReqMethod method, char* headers, u8* body, unsigned long bodyLength, unsigned long limit, ProgressCallback progress, void* progressContext, FlushCallback flush, void* flushContext) {
unsigned long transferred, expected; int result = 0;
int length; char* headerCopy = NULL;
char* responseHeaders = NULL; void* request;
u8* responseBody = NULL; int requestId;
HttpState state;
int status; int status;
u8* responseBody = NULL;
char* responseHeaders = NULL;
int length;
unsigned long expected;
unsigned long transferred;
HttpState state;
state.error = 0; state.error = 0;
state.limit = limit; state.limit = limit;
state.received = 0; state.received = 0;
@@ -118,10 +131,7 @@ static int __nupNhttpOp(char* url, NHTTPReqMethod method, char* headers, u8* bod
state.done = 0; state.done = 0;
state.result = 0; state.result = 0;
state.lastActivity = 0; state.lastActivity = 0;
int result = 0; request = NHTTPCreateRequestEx(url, method, NULL, 0, __nupNhttpReqDone, &state, __nupNhttpBufFull, __nupNhttpBufFree);
int requestId = 0;
char* headerCopy = NULL;
void* request = NHTTPCreateRequestEx(url, method, NULL, 0, __nupNhttpReqDone, &state, __nupNhttpBufFull, __nupNhttpBufFree);
if (request == NULL) { result = -7000 - NHTTPGetError(); goto cleanup; } if (request == NULL) { result = -7000 - NHTTPGetError(); goto cleanup; }
if (NHTTPSetSocketBufferSize(request, 0x8000) != 0) { result = -7000 - NHTTPGetError(); goto cleanup; } if (NHTTPSetSocketBufferSize(request, 0x8000) != 0) { result = -7000 - NHTTPGetError(); goto cleanup; }
if (headers != NULL) { if (headers != NULL) {
@@ -130,16 +140,15 @@ static int __nupNhttpOp(char* url, NHTTPReqMethod method, char* headers, u8* bod
if (headerCopy == NULL) { result = -5000; goto cleanup; } if (headerCopy == NULL) { result = -5000; goto cleanup; }
memcpy(headerCopy, headers, size); memcpy(headerCopy, headers, size);
char* field = headerCopy; char* field = headerCopy;
while (*field != 0) { char* colon;
char* colon = strchr(field, ':'); char* end;
if (colon == NULL) break; while (*field != 0 && (colon = strchr(field, ':')) != NULL && (end = strstr(colon, "\r\n")) != NULL) {
char* end = strstr(colon, "\r\n");
if (end == NULL) break;
*colon = 0; *colon = 0;
*end = 0; *end = 0;
while (*field && isspace(*field)) field++; while (*field && isspace(*field)) field++;
do { colon++; } while (*colon && isspace(*colon)); char* value = colon + 1;
if (NHTTPAddHeaderField(request, field, colon) != 0) { result = -7000 - NHTTPGetError(); goto cleanup; } while (*value && isspace(*value)) ++value;
if (NHTTPAddHeaderField(request, field, value) != 0) { result = -7000 - NHTTPGetError(); goto cleanup; }
field = end + 2; field = end + 2;
} }
} }
@@ -153,40 +162,39 @@ static int __nupNhttpOp(char* url, NHTTPReqMethod method, char* headers, u8* bod
if (method == NHTTP_POST && body != NULL && bodyLength != 0 && NHTTPAddPostDataRaw(request, body, bodyLength) != 0) { result = -7000 - NHTTPGetError(); goto cleanup; } if (method == NHTTP_POST && body != NULL && bodyLength != 0 && NHTTPAddPostDataRaw(request, body, bodyLength) != 0) { result = -7000 - NHTTPGetError(); goto cleanup; }
requestId = NHTTPSendRequestAsync(request); requestId = NHTTPSendRequestAsync(request);
if (requestId < 0) { if (requestId < 0) {
int error = NHTTPGetError(); result = -7000 - NHTTPGetError();
NHTTPDeleteRequest(request); NHTTPDeleteRequest(request);
result = -7000 - error;
goto cleanup; goto cleanup;
} }
state.lastActivity = OSGetTime(); state.lastActivity = OSGetTime();
for (;;) { while (NHTTPGetProgress(&expected, &transferred) == 0 || state.done == 0) {
if (NHTTPGetProgress(&expected, &transferred) != 0 && state.done != 0) { if (OSGetTime() - state.lastActivity >= OSMillisecondsToTicks((OSTime)90000)) {
if (state.result != 0) { result = -7000 - state.result; goto cleanup; } if (requestId >= 0) {
if (state.response != NULL) { NHTTPCancelRequestAsync(requestId);
length = NHTTPGetBodyAll(state.response, &responseBody); NCDSleep(OSMillisecondsToTicks(100));
if (length < 0) { result = -5007; goto cleanup; }
__nupNhttpBufFull(&responseBody, (unsigned long*)&length, 0, NULL, NULL, &state);
} }
result = state.error; result = -5009;
if (result != 0 || state.response == NULL) goto cleanup;
length = NHTTPGetHeaderAll(state.response, &responseHeaders);
if (length < 0) { result = -5007; goto cleanup; }
char* protocol = strstr(responseHeaders, "HTTP/");
if (protocol != NULL && sscanf(protocol, "HTTP/%*d.%*d %d", &status) == 1) {
if (status != 200 && status != 202) result = -5000 - status;
goto cleanup;
}
result = -5007;
goto cleanup; goto cleanup;
} }
if (OSGetTime() - state.lastActivity >= OSMillisecondsToTicks(90000)) break;
NCDSleep(OSMillisecondsToTicks(100)); NCDSleep(OSMillisecondsToTicks(100));
} }
if (requestId >= 0) { if (state.result != 0) { result = -7000 - state.result; goto cleanup; }
NHTTPCancelRequestAsync(requestId); if (state.response != NULL) {
NCDSleep(OSMillisecondsToTicks(100)); length = NHTTPGetBodyAll(state.response, &responseBody);
if (length < 0) { result = -5007; goto cleanup; }
__nupNhttpBufFull(&responseBody, (unsigned long*)&length, 0, NULL, NULL, &state);
} }
result = -5009; if (state.error != 0) { result = state.error; goto cleanup; }
if (state.response == NULL) goto cleanup;
length = NHTTPGetHeaderAll(state.response, &responseHeaders);
if (length < 0) { result = -5007; goto cleanup; }
char* protocol = strstr(responseHeaders, "HTTP/");
if (protocol == NULL || sscanf(protocol, "HTTP/%*d.%*d %d", &status) != 1) {
result = -5007;
goto cleanup;
}
if (status != 200 && status != 202) result = -5000 - status;
goto cleanup;
cleanup: cleanup:
if (state.response != NULL || result == -5009) NHTTPDestroyResponse(state.response); if (state.response != NULL || result == -5009) NHTTPDestroyResponse(state.response);
if (headerCopy != NULL) nup::__nupFree(headerCopy); if (headerCopy != NULL) nup::__nupFree(headerCopy);
@@ -194,18 +202,21 @@ cleanup:
} }
extern "C" { extern "C" {
static long __nupHttpStringFlush(u8* data, unsigned long length, unsigned long requested, void* context) { static inline unsigned long HttpStringGrowthSize(HttpString* text, unsigned long total, unsigned long requested) {
HttpString* text = (HttpString*)context; if (requested >= total) return requested;
requested = text->growth + total;
text->growth <<= 1;
if (text->growth >= text->maximumGrowth) text->growth = text->maximumGrowth;
return requested;
}
static inline long AppendHttpString(unsigned long length, u8* data, unsigned long requested, HttpString* text) {
u8* next;
unsigned long total; unsigned long total;
total = length + text->length; total = text->length + length;
long result = 0; long result = 0;
if (total > text->capacity) { if (total > text->capacity) {
if (requested >= total) {} else { requested = HttpStringGrowthSize(text, total, requested);
requested = text->growth + total; next = (u8*)nup::__nupMalloc(requested);
text->growth <<= 1;
if (text->growth < text->maximumGrowth) {} else text->growth = text->maximumGrowth;
}
u8* next = (u8*)nup::__nupMalloc(requested);
if (next == NULL) { result = -5000; goto done; } if (next == NULL) { result = -5000; goto done; }
if (text->buffer != NULL) { if (text->buffer != NULL) {
memcpy(next, text->buffer, text->length); memcpy(next, text->buffer, text->length);
@@ -218,6 +229,9 @@ static long __nupHttpStringFlush(u8* data, unsigned long length, unsigned long r
done: done:
return result; return result;
} }
static long __nupHttpStringFlush(u8* data, unsigned long length, unsigned long requested, void* context) {
return AppendHttpString(length, data, requested, (HttpString*)context);
}
} }
static int __nupNhttpOpString(u8** output, unsigned long* outputLength, char* url, NHTTPReqMethod method, char* headers, u8* body, unsigned long bodyLength, unsigned long limit, ProgressCallback progress, void* context) NO_INLINE; static int __nupNhttpOpString(u8** output, unsigned long* outputLength, char* url, NHTTPReqMethod method, char* headers, u8* body, unsigned long bodyLength, unsigned long limit, ProgressCallback progress, void* context) NO_INLINE;
static int __nupNhttpOpString(u8** output, unsigned long* outputLength, char* url, NHTTPReqMethod method, char* headers, u8* body, unsigned long bodyLength, unsigned long limit, ProgressCallback progress, void* context) { static int __nupNhttpOpString(u8** output, unsigned long* outputLength, char* url, NHTTPReqMethod method, char* headers, u8* body, unsigned long bodyLength, unsigned long limit, ProgressCallback progress, void* context) {

View File

@@ -1167,9 +1167,9 @@ u32 VIGetRetraceCount(void)
static u32 getCurrentHalfLine(void) static u32 getCurrentHalfLine(void)
{ {
u32 horizontalCount;
u32 previousVerticalCount;
u32 verticalCount; u32 verticalCount;
u32 previousVerticalCount;
u32 horizontalCount;
verticalCount = __VIRegs[22] & 0x7FF; verticalCount = __VIRegs[22] & 0x7FF;
for (;;) { for (;;) {
@@ -1180,7 +1180,7 @@ static u32 getCurrentHalfLine(void)
break; break;
} }
} }
return ((horizontalCount - 1) / CurrTiming->hlw) + ((verticalCount - 1) * 2); return ((verticalCount - 1) * 2) + ((horizontalCount - 1) / CurrTiming->hlw);
} }
static u32 getCurrentFieldEvenOdd(void) static u32 getCurrentFieldEvenOdd(void)

View File

@@ -1283,7 +1283,7 @@ static void __ClearControlBlock(s32 chan) {
p->sleeping = TRUE; p->sleeping = TRUE;
p->getInfoBusy = FALSE; p->getInfoBusy = FALSE;
p->getInfoCB = NULL; p->getInfoCB = NULL;
p->unk_0x98E = 0; p->continuous = 0;
memset(&p->wpInfo, 0, sizeof(p->wpInfo)); memset(&p->wpInfo, 0, sizeof(p->wpInfo));
memset(&p->wmReadDataBuf, 0, sizeof(p->wmReadDataBuf)); memset(&p->wmReadDataBuf, 0, sizeof(p->wmReadDataBuf));
@@ -1315,7 +1315,7 @@ static void __ClearControlBlock(s32 chan) {
_wmb[chan].unk_0x04 = 0; _wmb[chan].unk_0x04 = 0;
_wmb[chan].unk_0x08 = 0; _wmb[chan].unk_0x08 = 0;
_wmb[chan].unk_0x0C = 0; _wmb[chan].unk_0x0C = 0;
_wmb[chan].unk_0x10 = NULL; _wmb[chan].callback = NULL;
_rumbleCnt[chan] = 0; _rumbleCnt[chan] = 0;
} }
@@ -1551,7 +1551,7 @@ static void firmwareCheckCallback(s32 chan, s32 status) {
DEBUGPrint(" ==>this error means that the firmware is for NDEV %s\n", p->configIndex != 0 ? "2.0" : "2.1 or later"); DEBUGPrint(" ==>this error means that the firmware is for NDEV %s\n", p->configIndex != 0 ? "2.0" : "2.1 or later");
WPADiSendSetReportType(&p->stdCmdQueue, WPAD_FMT_CORE_BTN, p->unk_0x98E, &abortConnCallback); WPADiSendSetReportType(&p->stdCmdQueue, WPAD_FMT_CORE_BTN, p->continuous, &abortConnCallback);
WPADiSendDPDCSB(&p->stdCmdQueue, FALSE, &abortConnCallback); WPADiSendDPDCSB(&p->stdCmdQueue, FALSE, &abortConnCallback);
WPADiSendSetPort(&p->stdCmdQueue, port, &abortConnCallback); WPADiSendSetPort(&p->stdCmdQueue, port, &abortConnCallback);
@@ -1626,7 +1626,7 @@ static void WPADiConnCallback(WUDDevInfo* devInfo, u8 open) {
p->status = WPAD_ERR_OK; p->status = WPAD_ERR_OK;
p->radioSensitivity = 100; p->radioSensitivity = 100;
p->sleeping = FALSE; p->sleeping = FALSE;
p->unk_0x98D = FALSE; p->encStatus = FALSE;
WPADiSendReadData(&p->stdCmdQueue, p->wmReadDataBuf, 1, WM_ADDR_MEM_1770, firmwareCheckCallback); WPADiSendReadData(&p->stdCmdQueue, p->wmReadDataBuf, 1, WM_ADDR_MEM_1770, firmwareCheckCallback);
@@ -1643,8 +1643,8 @@ static void WPADiConnCallback(WUDDevInfo* devInfo, u8 open) {
if (p->cmdBlkCB != NULL) { if (p->cmdBlkCB != NULL) {
p->cmdBlkCB(chan, WPAD_ERR_NO_CONTROLLER); p->cmdBlkCB(chan, WPAD_ERR_NO_CONTROLLER);
} else if (_wmb[chan].unk_0x10 != NULL) { } else if (_wmb[chan].callback != NULL) {
_wmb[chan].unk_0x10(chan, WPAD_ERR_NO_CONTROLLER); _wmb[chan].callback(chan, WPAD_ERR_NO_CONTROLLER);
} }
do { do {
@@ -1886,7 +1886,7 @@ s32 WPADSetDataFormat(s32 chan, u32 format) {
} }
if (currFormat != format) { if (currFormat != format) {
if (!WPADiSendSetReportType(&p->stdCmdQueue, format, p->unk_0x98E, NULL)) { if (!WPADiSendSetReportType(&p->stdCmdQueue, format, p->continuous, NULL)) {
status = WPAD_ERR_COMMUNICATION_ERROR; status = WPAD_ERR_COMMUNICATION_ERROR;
} else { } else {
enabled = OSDisableInterrupts(); enabled = OSDisableInterrupts();
@@ -2741,13 +2741,13 @@ BOOL WPADiSendSetPort(WPADCommandQueue* pQueue, u8 port, WPADCallback pCallback)
return success; return success;
} }
BOOL WPADiSendSetReportType(WPADCommandQueue* pQueue, s32 format, BOOL unk, WPADCallback pCallback) { BOOL WPADiSendSetReportType(WPADCommandQueue* pQueue, s32 format, BOOL continuous, WPADCallback pCallback) {
BOOL success; BOOL success;
WPADCommand command; WPADCommand command;
command.reportID = RPTID_SET_DATA_REPORT_MODE; command.reportID = RPTID_SET_DATA_REPORT_MODE;
command.dataLength = RPT12_SIZE; command.dataLength = RPT12_SIZE;
command.dataBuf[RPT12_CONT_REPORT] = unk ? 0 : 4; // Always continuous reporting command.dataBuf[RPT12_CONT_REPORT] = continuous ? 0 : 4; // Always continuous reporting
command.cmdCB = pCallback; command.cmdCB = pCallback;
switch (format) { switch (format) {

View File

@@ -111,8 +111,8 @@ static void initExtension(s32 chan) {
WPADiClearQueue(&p_wpd->extCmdQueue); WPADiClearQueue(&p_wpd->extCmdQueue);
WPADiSendSetReportType(&p_wpd->extCmdQueue, p_wpd->dataFormat, WPADiSendSetReportType(&p_wpd->extCmdQueue, p_wpd->dataFormat,
p_wpd->unk_0x98E, abortInitExtension); p_wpd->continuous, abortInitExtension);
p_wpd->unk_0x98D = 1; p_wpd->encStatus = 1;
WPADiSendWriteDataCmd(&p_wpd->extCmdQueue, 0x55, 0x04a400f0, WPADiSendWriteDataCmd(&p_wpd->extCmdQueue, 0x55, 0x04a400f0,
abortInitExtension); abortInitExtension);
WPADiSendWriteDataCmd(&p_wpd->extCmdQueue, 0, 0x04a400fb, WPADiSendWriteDataCmd(&p_wpd->extCmdQueue, 0, 0x04a400fb,
@@ -127,7 +127,7 @@ static void abortInitExtension(s32 chan, s32 result) {
if (result != WPAD_ERR_NONE) { if (result != WPAD_ERR_NONE) {
WPADiClearQueue(&p_wpd->extCmdQueue); WPADiClearQueue(&p_wpd->extCmdQueue);
p_wpd->unk_0x98D = 0; p_wpd->encStatus = 0;
if (result == WPAD_ERR_NO_CONTROLLER) { if (result == WPAD_ERR_NO_CONTROLLER) {
type = WPAD_DEV_NOT_FOUND; type = WPAD_DEV_NOT_FOUND;
} }
@@ -142,7 +142,7 @@ static void abortInitExtension(s32 chan, s32 result) {
else { else {
DEBUGPrint("detaching extension during initialization.\n"); DEBUGPrint("detaching extension during initialization.\n");
WPADiSendSetReportType(&p_wpd->extCmdQueue, p_wpd->dataFormat, p_wpd->unk_0x98E, NULL); WPADiSendSetReportType(&p_wpd->extCmdQueue, p_wpd->dataFormat, p_wpd->continuous, NULL);
return; return;
} }
p_wpd->devType = (u8)type; p_wpd->devType = (u8)type;
@@ -509,7 +509,7 @@ static void getExtType(s32 chan, s32 result) {
} }
} else { } else {
if (isExtEncMain(_devType[chan])) { if (isExtEncMain(_devType[chan])) {
p_wpd->unk_0x98D = 2; p_wpd->encStatus = 2;
WPADiSendWriteDataCmd(cmdq, 0xAA, 0x4A400F0, abortInitExtension); WPADiSendWriteDataCmd(cmdq, 0xAA, 0x4A400F0, abortInitExtension);
WPADiCreateKey(chan); WPADiCreateKey(chan);
WPADiSendWriteData(cmdq, p_wpd->encryptionKey, 6, 0x4A40040, abortInitExtension); WPADiSendWriteData(cmdq, p_wpd->encryptionKey, 6, 0x4A40040, abortInitExtension);
@@ -517,7 +517,7 @@ static void getExtType(s32 chan, s32 result) {
WPADiSendWriteData(cmdq, p_wpd->encryptionKey + 12, 4, 0x4A4004C, abortInitExtension); WPADiSendWriteData(cmdq, p_wpd->encryptionKey + 12, 4, 0x4A4004C, abortInitExtension);
WPADiSendReadData(cmdq, p_wpd->wmReadDataBuf, 32, 0x4A40020, p_wpd->extensionCB); WPADiSendReadData(cmdq, p_wpd->wmReadDataBuf, 32, 0x4A40020, p_wpd->extensionCB);
} else { } else {
p_wpd->unk_0x98D = 3; p_wpd->encStatus = 3;
WPADiSendWriteDataCmd(cmdq, 0xAA, 0x4A400F0, abortInitExtension); WPADiSendWriteDataCmd(cmdq, 0xAA, 0x4A400F0, abortInitExtension);
WPADiCreateKeyFor3rd(chan); WPADiCreateKeyFor3rd(chan);
WPADiSendWriteData(cmdq, p_wpd->encryptionKey, 6, 0x4A40040, abortInitExtension); WPADiSendWriteData(cmdq, p_wpd->encryptionKey, 6, 0x4A40040, abortInitExtension);
@@ -651,7 +651,7 @@ void __a1_20_status_report(u8 chan, u8* data) {
p_wpd->devMode = 0; p_wpd->devMode = 0;
WPADiClearQueue(&p_wpd->extCmdQueue); WPADiClearQueue(&p_wpd->extCmdQueue);
WPADiSendSetReportType(&p_wpd->extCmdQueue, p_wpd->dataFormat, p_wpd->unk_0x98E, NULL); WPADiSendSetReportType(&p_wpd->extCmdQueue, p_wpd->dataFormat, p_wpd->continuous, NULL);
if (attach) { if (attach) {
if (p_wpd->extensionCB) { if (p_wpd->extensionCB) {
@@ -741,11 +741,11 @@ void __a1_21_user_data(u8 chan, u8* data) {
DEBUGPrint("length : %d\n", p_wpd->wmReadLength); DEBUGPrint("length : %d\n", p_wpd->wmReadLength);
status = (p_wpd->wmReadHadError < 0) ? WPAD_ERR_TRANSFER : 0; status = (p_wpd->wmReadHadError < 0) ? WPAD_ERR_TRANSFER : 0;
DEBUGPrint("i2c = %04x\n", i2c); DEBUGPrint("i2c = %04x\n", i2c);
DEBUGPrint("enc = %d\n", p_wpd->unk_0x98D); DEBUGPrint("enc = %d\n", p_wpd->encStatus);
if (i2c == 0x04a4) { if (i2c == 0x04a4) {
DEBUGPrint("Access to extension register.\n"); DEBUGPrint("Access to extension register.\n");
if (p_wpd->unk_0x98D == 2 || p_wpd->unk_0x98D == 3) { if (p_wpd->encStatus == 2 || p_wpd->encStatus == 3) {
DEBUGPrint("Decode!!!!\n"); DEBUGPrint("Decode!!!!\n");
DEBUGPrint(" len = %d, addr = %04x\n", len, base); DEBUGPrint(" len = %d, addr = %04x\n", len, base);

View File

@@ -13,8 +13,8 @@ typedef struct _CDBCryptBuf {
u32 buffer32[0xFB00]; u32 buffer32[0xFB00];
}; // 0x00 }; // 0x00
u32 unk_0x3EC00; u32 size; // 0x3EC00
u32 unk_0x3EC04; u32 offset; // 0x3EC04
BOOL allocated; // 0x3EC08 BOOL allocated; // 0x3EC08
u8 unk_0x3EC0C[0x34]; u8 unk_0x3EC0C[0x34];
} CDBCryptBuf; } CDBCryptBuf;

View File

@@ -19,7 +19,7 @@ typedef struct _CDBRecordFile {
#else #else
u8 unk_0x00[0x1C - 0x00]; u8 unk_0x00[0x1C - 0x00];
#endif #endif
int unk_0x1C; int allocFlag; // 0x1C
CDBAttr attr; // 0x20 CDBAttr attr; // 0x20
CDBBridgeFile bridgeFile; // 0x42C CDBBridgeFile bridgeFile; // 0x42C
u8 unk_0x434[0x438 - 0x434]; u8 unk_0x434[0x438 - 0x434];

View File

@@ -24,7 +24,7 @@ typedef struct NWC24MsgObjPrivate {
#ifdef NWC24_MSG_READ #ifdef NWC24_MSG_READ
u32 headerSize; u32 headerSize;
#elif defined(NWC24_MBOX_CTRL) || defined(NWC24_MSG_COMMIT) #elif defined(NWC24_MBOX_CTRL) || defined(NWC24_MSG_COMMIT)
u32 unk_0x10; u32 headerSize; // 0x10
#else #else
u8 unk_0x10[0x4]; u8 unk_0x10[0x4];
#endif #endif
@@ -46,8 +46,8 @@ typedef struct NWC24MsgObjPrivate {
#endif #endif
u32 date; // 0x28 u32 date; // 0x28
u32 receivedDate; // 0x2C u32 receivedDate; // 0x2C
NWC24Data unk_0x30; NWC24Data fromData; // 0x30
NWC24Data unk_0x38; NWC24Data toData; // 0x38
NWC24Data subject; // 0x40 NWC24Data subject; // 0x40
NWC24Data text; // 0x48 NWC24Data text; // 0x48
NWC24Data unk_0x50; NWC24Data unk_0x50;
@@ -73,7 +73,7 @@ typedef struct NWC24MsgObjPrivate {
}; };
u32 raw; u32 raw;
} msgBoardFlags; // 0xCC } msgBoardFlags; // 0xCC
NWC24Data unk_0xD0; NWC24Data extraData; // 0xD0
NWC24Data faceData; // 0xD8 NWC24Data faceData; // 0xD8
NWC24Data altName; // 0xE0 NWC24Data altName; // 0xE0
u32 textSize; // 0xE4 u32 textSize; // 0xE4

View File

@@ -26,9 +26,9 @@ extern struct NWC24Work {
u8 configData[1024]; // 0x1300 u8 configData[1024]; // 0x1300
u8 unk_0x1700[128]; // 0x1700 u8 sendMbcHeader[128]; // 0x1700
u8 unk_0x1780[128]; // 0x1780 u8 recvMbcHeader[128]; // 0x1780
u8 unk_0x1800[256]; // 0x1800 u8 mbcEntry[256]; // 0x1800
u8 base64Work[256]; // 0x1900 u8 base64Work[256]; // 0x1900
u8 unk_0x1A00[4096]; // 0x1A00 u8 unk_0x1A00[4096]; // 0x1A00

View File

@@ -87,6 +87,10 @@ typedef struct WD_Info_ {
u8 unk_0x60[0x30]; // 0x60 (is it padding???) u8 unk_0x60[0x30]; // 0x60 (is it padding???)
} PACKED WD_Info; } PACKED WD_Info;
#ifdef __cplusplus
extern "C" {
#endif
s32 WDCheckEnableChannel(u16* enableChannel); s32 WDCheckEnableChannel(u16* enableChannel);
s32 WDScanOnce(u8* scanBuffer, u32 scanBufferLen, WDScanParam* param); s32 WDScanOnce(u8* scanBuffer, u32 scanBufferLen, WDScanParam* param);
s32 WDGetPrivacyMode(WDBssDesc* bssDesc); s32 WDGetPrivacyMode(WDBssDesc* bssDesc);
@@ -94,4 +98,8 @@ s32 WDGetPrivacyMode(WDBssDesc* bssDesc);
BOOL WDFindInformationElement(WDInfoElement** outIE, u32* outIELength, WDBssDesc* bssDesc, int id); BOOL WDFindInformationElement(WDInfoElement** outIE, u32* outIELength, WDBssDesc* bssDesc, int id);
BOOL WDiFindVendorSpecificIE(WDVendorInfoElement** outIE, u32* outIELength, WDBssDesc* bssDesc, int id, u8* data, u8 mode); BOOL WDiFindVendorSpecificIE(WDVendorInfoElement** outIE, u32* outIELength, WDBssDesc* bssDesc, int id, u8* data, u8 mode);
#ifdef __cplusplus
}
#endif
#endif // REVOLUTION_WD_H #endif // REVOLUTION_WD_H

View File

@@ -57,7 +57,7 @@ void CDBRecordInstanceInit(CDBRecordFile* recordFile, CDBRecord* record, int typ
OSLockMutex((OSMutex*)recordFile); OSLockMutex((OSMutex*)recordFile);
recordFile->used = 1; recordFile->used = 1;
OSUnlockMutex((OSMutex*)recordFile); OSUnlockMutex((OSMutex*)recordFile);
recordFile->unk_0x1C = type; recordFile->allocFlag = type;
recordFile->database = record->unk_0x00; recordFile->database = record->unk_0x00;
CDBAttrInit(&recordFile->attr); CDBAttrInit(&recordFile->attr);
CDBRecordKeyCopy(&recordFile->key, &record->key); CDBRecordKeyCopy(&recordFile->key, &record->key);
@@ -164,7 +164,7 @@ CDBErr CDBRecordOpen_(CDBRecord* record) {
goto open_result_ready; goto open_result_ready;
open_location_ok: open_location_ok:
if (CDBFSSDIsMounted()) { if (CDBFSSDIsMounted()) {
err = CDBRecordDecrypt(record, cryptBuf, 0x3EC00, &cryptBuf->unk_0x3EC00, NULL); err = CDBRecordDecrypt(record, cryptBuf, 0x3EC00, &cryptBuf->size, NULL);
} else { } else {
err = CDB_ERROR_SD_IS_NOT_MOUNTED; err = CDB_ERROR_SD_IS_NOT_MOUNTED;
} }
@@ -174,7 +174,7 @@ CDBErr CDBRecordOpen_(CDBRecord* record) {
CDBCryptBufFree((CDBCryptBuf**)&record->cryptBuf); CDBCryptBufFree((CDBCryptBuf**)&record->cryptBuf);
return err; return err;
} }
cryptBuf->unk_0x3EC04 = sizeof(CDBAttrBuf); cryptBuf->offset = sizeof(CDBAttrBuf);
} }
return CDB_ERROR_OK; return CDB_ERROR_OK;
} }
@@ -223,7 +223,7 @@ CDBErr CDBRecordOpenReadOnly_(CDBRecord* record) {
goto result_ready; goto result_ready;
location_ok: location_ok:
if (CDBFSSDIsMounted()) { if (CDBFSSDIsMounted()) {
result = CDBRecordDecrypt(record, cryptBuf, 0x3EC00, &cryptBuf->unk_0x3EC00, NULL); result = CDBRecordDecrypt(record, cryptBuf, 0x3EC00, &cryptBuf->size, NULL);
} else { } else {
result = CDB_ERROR_SD_IS_NOT_MOUNTED; result = CDB_ERROR_SD_IS_NOT_MOUNTED;
} }
@@ -233,7 +233,7 @@ CDBErr CDBRecordOpenReadOnly_(CDBRecord* record) {
CDBCryptBufFree((CDBCryptBuf**)&record->cryptBuf); CDBCryptBufFree((CDBCryptBuf**)&record->cryptBuf);
return result; return result;
} }
cryptBuf->unk_0x3EC04 = sizeof(CDBAttrBuf); cryptBuf->offset = sizeof(CDBAttrBuf);
} }
return CDB_ERROR_OK; return CDB_ERROR_OK;
} }
@@ -310,7 +310,7 @@ CDBErr CDBRecordWrite_(CDBRecord* record, void* buffer, u32 size) {
CDBReportError("can't write data in the record; the record is closed\n"); CDBReportError("can't write data in the record; the record is closed\n");
return CDB_ERROR_27; return CDB_ERROR_27;
} }
if ((recordFile->unk_0x1C & 2) == 0) { if ((recordFile->allocFlag & 2) == 0) {
CDBReportError("can't write data in the record; the record is opened as READONLY\n"); CDBReportError("can't write data in the record; the record is opened as READONLY\n");
return CDB_ERROR_27; return CDB_ERROR_27;
} }
@@ -367,6 +367,19 @@ CDBErr CDBRecordSeek(CDBRecord* record, s32 offset, CDBSeek seek) {
return err; return err;
} }
CDBErr CDBRecordGetFileSize(CDBRecord* record, u32* size) {
CDBErr err;
CDBLock();
if ((s32)record->file == 0) {
CDBReportError("can't get file size of the record ; the record is closed\n");
err = CDB_ERROR_27;
} else {
err = CDBRecordFileGetFileSize(record, size);
}
CDBUnlock();
return err;
}
CDBErr CDBRecordGetDataSize(CDBRecord* record, u32* size) { CDBErr CDBRecordGetDataSize(CDBRecord* record, u32* size) {
CDBErr err; CDBErr err;
CDBLock(); CDBLock();
@@ -455,7 +468,7 @@ CDBErr CDBRecordGetId(CDBRecord* record, CDBId* id) {
} else { } else {
CDBLock(); CDBLock();
if (record->file == NULL) { if (record->file == NULL) {
CDBReportError("can't get CDBId of the record ; the record is closed\n"); CDBReportError("can't get maker code of the record ; the record is closed\n");
err = CDB_ERROR_27; err = CDB_ERROR_27;
} else { } else {
CDBLock(); CDBLock();
@@ -656,9 +669,10 @@ CDBErr CDBCryptBuffer(void* buffer, u32 size, void* iv, u32* processedSize, BOOL
CDBErr CDBRecordEncrypt(CDBRecord* record, void* buffer, CDBRecordKey* key, u32 size, u32* encryptedSize) { CDBErr CDBRecordEncrypt(CDBRecord* record, void* buffer, CDBRecordKey* key, u32 size, u32* encryptedSize) {
CDBRecordFile* recordFile; CDBRecordFile* recordFile;
CDBErr err; CDBErr err;
u32 fileSize;
u32 dataSize; u32 dataSize;
u32 fileSize;
u32 cryptSize; u32 cryptSize;
u32 authenticatedSize;
int fileOffset; int fileOffset;
u8 iv[0x10]; u8 iv[0x10];
u8 wiiIdKey[0x40] ATTRIBUTE_ALIGN(64); u8 wiiIdKey[0x40] ATTRIBUTE_ALIGN(64);
@@ -673,7 +687,7 @@ CDBErr CDBRecordEncrypt(CDBRecord* record, void* buffer, CDBRecordKey* key, u32
if ((s32)recordFile == 0) { if ((s32)recordFile == 0) {
return CDB_ERROR_27; return CDB_ERROR_27;
} }
if (recordFile->unk_0x1C == 1) { if (recordFile->allocFlag == 1) {
return CDB_ERROR_26; return CDB_ERROR_26;
} }
if ((s32)buffer == 0) { if ((s32)buffer == 0) {
@@ -685,7 +699,7 @@ CDBErr CDBRecordEncrypt(CDBRecord* record, void* buffer, CDBRecordKey* key, u32
tempFile = record->file; tempFile = record->file;
if ((s32)tempFile == 0) { if ((s32)tempFile == 0) {
result = CDB_ERROR_27; result = CDB_ERROR_27;
} else if (tempFile->unk_0x1C == 1) { } else if (tempFile->allocFlag == 1) {
result = CDB_ERROR_26; result = CDB_ERROR_26;
} else { } else {
CDBAttrSetWiiId(&tempFile->attr, CDBGetWiiId()); CDBAttrSetWiiId(&tempFile->attr, CDBGetWiiId());
@@ -699,7 +713,7 @@ CDBErr CDBRecordEncrypt(CDBRecord* record, void* buffer, CDBRecordKey* key, u32
CDBErr result; CDBErr result;
if ((s32)record->file == 0) { if ((s32)record->file == 0) {
result = CDB_ERROR_27; result = CDB_ERROR_27;
} else if (((CDBRecordFile*)record->file)->unk_0x1C == 1) { } else if (((CDBRecordFile*)record->file)->allocFlag == 1) {
result = CDB_ERROR_26; result = CDB_ERROR_26;
} else { } else {
CDBAttrInitIV(&((CDBRecordFile*)record->file)->attr); CDBAttrInitIV(&((CDBRecordFile*)record->file)->attr);
@@ -713,7 +727,7 @@ CDBErr CDBRecordEncrypt(CDBRecord* record, void* buffer, CDBRecordKey* key, u32
CDBErr result; CDBErr result;
if ((s32)record->file == 0) { if ((s32)record->file == 0) {
result = CDB_ERROR_27; result = CDB_ERROR_27;
} else if (((CDBRecordFile*)record->file)->unk_0x1C == 1) { } else if (((CDBRecordFile*)record->file)->allocFlag == 1) {
result = CDB_ERROR_26; result = CDB_ERROR_26;
} else { } else {
CDBAttrSetKeyStr(&((CDBRecordFile*)record->file)->attr, key); CDBAttrSetKeyStr(&((CDBRecordFile*)record->file)->attr, key);
@@ -723,14 +737,7 @@ CDBErr CDBRecordEncrypt(CDBRecord* record, void* buffer, CDBRecordKey* key, u32
return CDB_ERROR_OK; return CDB_ERROR_OK;
} }
} }
CDBLock(); err = CDBRecordGetFileSize(record, &fileSize);
if ((s32)record->file == 0) {
CDBReportError("can't get file size of the record ; the record is closed\n");
err = CDB_ERROR_27;
} else {
err = CDBRecordFileGetFileSize(record, &fileSize);
}
CDBUnlock();
CDBAttrSetFileSize(&recordFile->attr, fileSize); CDBAttrSetFileSize(&recordFile->attr, fileSize);
if (err != CDB_ERROR_OK) { if (err != CDB_ERROR_OK) {
return CDB_ERROR_OK; return CDB_ERROR_OK;
@@ -754,10 +761,11 @@ CDBErr CDBRecordEncrypt(CDBRecord* record, void* buffer, CDBRecordKey* key, u32
if ((s32)record->file == 0) { if ((s32)record->file == 0) {
err = CDB_ERROR_27; err = CDB_ERROR_27;
} else { } else {
fileOffset = CDBRecordFileTellData(record); int position = CDBRecordFileTellData(record);
if (fileOffset < 0) { if (position < 0) {
err = CDB_ERROR_CANNOT_OPEN_FILE; err = CDB_ERROR_CANNOT_OPEN_FILE;
} else { } else {
fileOffset = position;
err = CDB_ERROR_OK; err = CDB_ERROR_OK;
} }
} }
@@ -804,8 +812,9 @@ CDBErr CDBRecordEncrypt(CDBRecord* record, void* buffer, CDBRecordKey* key, u32
CDBGetWiiIdKey((char*)wiiIdKey); CDBGetWiiIdKey((char*)wiiIdKey);
CDBGetDeviceKey((char*)&wiiIdKey[12]); CDBGetDeviceKey((char*)&wiiIdKey[12]);
CDBAttrClearSignature((CDBAttr*)buffer); CDBAttrClearSignature((CDBAttr*)buffer);
authenticatedSize = cryptSize + CDB_RECORD_BUFFER_SIZE;
NETHMACInit(&hmac, NETGetSHA1Interface(), wiiIdKey, 0x40); NETHMACInit(&hmac, NETGetSHA1Interface(), wiiIdKey, 0x40);
NETHMACUpdate(&hmac, buffer, cryptSize + CDB_RECORD_BUFFER_SIZE); NETHMACUpdate(&hmac, buffer, authenticatedSize);
NETHMACGetDigest(&hmac, digest); NETHMACGetDigest(&hmac, digest);
memcpy(((CDBAttrBuf*)buffer)->signature.sha1Hmac, digest, sizeof(digest)); memcpy(((CDBAttrBuf*)buffer)->signature.sha1Hmac, digest, sizeof(digest));
if (encryptedSize != 0) { if (encryptedSize != 0) {
@@ -933,7 +942,7 @@ CDBErr CDBRecordDecrypt(CDBRecord* record, void* buffer, u32 size, u32* dataSize
if (CDBRecordKeyCompareByDate(&comparisonKey, &record->key) != 0) { if (CDBRecordKeyCompareByDate(&comparisonKey, &record->key) != 0) {
if (CDBIsPrintDebugMessage(3)) { if (CDBIsPrintDebugMessage(3)) {
CDBReport_(3); CDBReport_(3);
OSReport("CDBRecordPrivateChangeOwner\n"); OSReport("ファイル名の改竄を検出\n");
} }
return CDB_ERROR_32; return CDB_ERROR_32;
} }

View File

@@ -264,8 +264,8 @@ CDBErr CDBRecordFileReadData(CDBRecord* record, void* buffer, u32 size, u32* rea
CDBCryptBuf* cryptBuf = record->cryptBuf; CDBCryptBuf* cryptBuf = record->cryptBuf;
if (cryptBuf != NULL) { if (cryptBuf != NULL) {
u32 unk = cryptBuf->unk_0x3EC00 - cryptBuf->unk_0x3EC04; u32 unk = cryptBuf->size - cryptBuf->offset;
if (cryptBuf->unk_0x3EC00 < unk) { if (cryptBuf->size < unk) {
unk = 0; unk = 0;
} }
@@ -274,8 +274,8 @@ CDBErr CDBRecordFileReadData(CDBRecord* record, void* buffer, u32 size, u32* rea
} }
if (unk != 0) { if (unk != 0) {
memcpy(buffer, (u8*)&cryptBuf->buffer[cryptBuf->unk_0x3EC04], unk); memcpy(buffer, (u8*)&cryptBuf->buffer[cryptBuf->offset], unk);
cryptBuf->unk_0x3EC04 += unk; cryptBuf->offset += unk;
} }
if (readSize != NULL) { if (readSize != NULL) {
@@ -300,16 +300,16 @@ CDBErr CDBRecordFileSeekData(CDBRecord* record, u32 offset, CDBSeek seek) {
if (cryptBuf != NULL) { if (cryptBuf != NULL) {
switch (seek) { switch (seek) {
case CDB_SEEK_BEGIN: { case CDB_SEEK_BEGIN: {
cryptBuf->unk_0x3EC04 = sizeof(CDBAttrBuf); cryptBuf->offset = sizeof(CDBAttrBuf);
cryptBuf->unk_0x3EC04 += offset; cryptBuf->offset += offset;
break; break;
} }
case CDB_SEEK_END: { case CDB_SEEK_END: {
cryptBuf->unk_0x3EC04 = (cryptBuf->unk_0x3EC00 - 1) - offset; cryptBuf->offset = (cryptBuf->size - 1) - offset;
break; break;
} }
case CDB_SEEK_CUR: { case CDB_SEEK_CUR: {
cryptBuf->unk_0x3EC04 += offset; cryptBuf->offset += offset;
break; break;
} }
} }
@@ -329,7 +329,7 @@ int CDBRecordFileTellData(CDBRecord* record) {
CDBCryptBuf* cryptBuf = record->cryptBuf; CDBCryptBuf* cryptBuf = record->cryptBuf;
if (cryptBuf != NULL) { if (cryptBuf != NULL) {
return cryptBuf->unk_0x3EC04 - sizeof(CDBAttrBuf); return cryptBuf->offset - sizeof(CDBAttrBuf);
} }
return CDBFTellData(&recordFile->bridgeFile, record->key.location); return CDBFTellData(&recordFile->bridgeFile, record->key.location);
} }

View File

@@ -265,7 +265,7 @@ CDBErr CDBRecordFree(CDBRecord* record) {
OSLockMutex((OSMutex*)recordFile); OSLockMutex((OSMutex*)recordFile);
*(u32*)&recordFile->unk_0x00[0x18] = 0; *(u32*)&recordFile->unk_0x00[0x18] = 0;
OSUnlockMutex((OSMutex*)recordFile); OSUnlockMutex((OSMutex*)recordFile);
recordFile->unk_0x1C = 0; recordFile->allocFlag = 0;
record->file = NULL; record->file = NULL;
OSUnlockMutex(&s_mutex); OSUnlockMutex(&s_mutex);
} }

View File

@@ -234,30 +234,39 @@ void AESiDecryptBlock(AESContext* context, u32* output, const u32* input) {
} }
BOOL NETAESCreateEx(AESContext* context, const void* key, u32 keyLength, const void* iv, const AESBlockMode* mode) { BOOL NETAESCreateEx(AESContext* context, const void* key, u32 keyLength, const void* iv, const AESBlockMode* mode) {
BOOL result=FALSE;
u32 words,index,value;
u32* schedule; u32* schedule;
u32 words;
u32 index;
u32 value;
BOOL result = FALSE;
if (keyLength != 16 && keyLength != 24 && keyLength != 32) { if (keyLength != 16 && keyLength != 24 && keyLength != 32) {
OSReport("NETAESCreateEx() failed! (key-length is allowed only 16, 20, 24 BYTEs)"); OSReport("NETAESCreateEx() failed! (key-length is allowed only 16, 20, 24 BYTEs)");
} else { } else {
context->rounds=keyLength/4+6; context->needsTransform = 1;
context->needsTransform=1; context->rounds = (keyLength * 8) / 32 + 6;
context->mode=mode; context->mode = mode;
memcpy(context->chain, iv, 16); memcpy(context->chain, iv, 16);
schedule=context->keys; schedule = context->keys;
words=keyLength/4; words = keyLength / 4;
memcpy(schedule,key,keyLength); memcpy(schedule, key, keyLength);
value=schedule[words-1]; value = schedule[words - 1];
for(index=words; index<(context->rounds+1)*4; ++index) { for (index = words; index < (context->rounds + 1) * 4; ++index) {
if (index%words == 0) { if (index % words == 0) {
value=SUBSTITUTE_XOR(AESiSubShiftTable,value<<8,value<<8,value<<8,value>>24) ^ ((u32)AESiRoundKeyRcon0[index/words-1]<<24); u32 high = (u32)AESiSubShiftTable[(value >> 16) & 255] << 24;
} else if(words>6 && index%words==4) { u32 low = AESiSubShiftTable[value >> 24];
value=SUBSTITUTE_XOR(AESiSubShiftTable,value,value,value,value); u32 lower = (u32)AESiSubShiftTable[value & 255] << 8;
u32 upper = (u32)AESiSubShiftTable[(value >> 8) & 255] << 16;
value = (low ^ high) ^ (lower ^ upper);
value ^= (u32)AESiRoundKeyRcon0[index / words - 1] << 24;
} else if (words > 6 && index % words == 4) {
value = ((u32)AESiSubShiftTable[value >> 24] << 24) ^
(((u32)AESiSubShiftTable[(value >> 16) & 255] << 16) ^
(AESiSubShiftTable[value & 255] ^ ((u32)AESiSubShiftTable[(value >> 8) & 255] << 8)));
} }
value ^= schedule[index-words]; value ^= schedule[index - words];
schedule[index]=value; schedule[index] = value;
} }
result=TRUE; result = TRUE;
} }
return result; return result;
} }

View File

@@ -19,15 +19,23 @@ typedef struct HMACContext {
u8 key[64]; u8 key[64];
} HMACContext; } HMACContext;
void NETHMACInit(HMACContext* context, const DigestInterface* interface, const void* key, u32 length) { static inline void BeginDigest(HMACContext* context, u8 mask) {
u8 innerKey[64]; u8 blockKey[64];
u32 i; u32 i;
u32 keyLength; u32 keyLength;
void* work = context->digestContext; void* work = context->digestContext;
const char* function = "NETHMACInit"; keyLength = context->keyLength;
for (i = 0; i < keyLength; ++i) blockKey[i] = context->key[i] ^ mask;
memset(blockKey + keyLength, mask, context->interface.blockSize - keyLength);
context->interface.init(work);
context->interface.update(work, blockKey, context->interface.blockSize);
}
void NETHMACInit(HMACContext* context, const DigestInterface* interface, const void* key, u32 length) {
void* work = context->digestContext;
context->interface = *interface; context->interface = *interface;
if (context->interface.contextSize > 96 || context->interface.blockSize > 64) { if (context->interface.contextSize > 96 || context->interface.blockSize > 64) {
OSReport("%s(%d):[warning in %s]", "hmac.c", 100, function); OSReport("%s(%d):[warning in %s]", "hmac.c", 100, __FUNCTION__);
OSReport("specified interface needs too large workmemory."); OSReport("specified interface needs too large workmemory.");
OSReport("\n"); OSReport("\n");
return; return;
@@ -41,11 +49,7 @@ void NETHMACInit(HMACContext* context, const DigestInterface* interface, const v
context->interface.getDigest(work, context->key); context->interface.getDigest(work, context->key);
context->keyLength = context->interface.digestSize; context->keyLength = context->interface.digestSize;
} }
keyLength = context->keyLength; BeginDigest(context, 0x36);
for (i=0; i<keyLength; ++i) innerKey[i] = context->key[i] ^ 0x36;
memset(innerKey + keyLength, 0x36, context->interface.blockSize - keyLength);
context->interface.init(context->digestContext);
context->interface.update(context->digestContext, innerKey, context->interface.blockSize);
} }
void NETHMACUpdate(HMACContext* context, const void* data, u32 length) { void NETHMACUpdate(HMACContext* context, const void* data, u32 length) {
@@ -54,16 +58,9 @@ void NETHMACUpdate(HMACContext* context, const void* data, u32 length) {
void NETHMACGetDigest(HMACContext* context, void* digest) { void NETHMACGetDigest(HMACContext* context, void* digest) {
u8 innerDigest[64]; u8 innerDigest[64];
u8 outerKey[64];
u32 i;
u32 keyLength;
void* work = context->digestContext; void* work = context->digestContext;
context->interface.getDigest(work, innerDigest); context->interface.getDigest(work, innerDigest);
keyLength = context->keyLength; BeginDigest(context, 0x5c);
for (i=0; i<keyLength; ++i) outerKey[i] = context->key[i] ^ 0x5c;
memset(outerKey + keyLength, 0x5c, context->interface.blockSize - keyLength);
context->interface.init(context->digestContext);
context->interface.update(context->digestContext, outerKey, context->interface.blockSize);
context->interface.update(work, innerDigest, context->interface.digestSize); context->interface.update(work, innerDigest, context->interface.digestSize);
context->interface.getDigest(work, digest); context->interface.getDigest(work, digest);
} }

View File

@@ -13,7 +13,7 @@ static void FindHeaderBlock(const NHTTPResponseInfo* response, s32 position, NHT
} }
} }
static s8 ReadHeaderChar(const NHTTPResponseInfo* response, NHTTPi_HDRBUFLIST** block, s32* offset) { static int ReadHeaderChar(const NHTTPResponseInfo* response, NHTTPi_HDRBUFLIST** block, s32* offset) {
if(!*block) { if(!*block) {
if(*offset<1024) return (s8)response->hdrBufFirst[(*offset)++]; if(*offset<1024) return (s8)response->hdrBufFirst[(*offset)++];
*block=response->hdrBufBlock_p; *block=response->hdrBufBlock_p;
@@ -23,37 +23,37 @@ static s8 ReadHeaderChar(const NHTTPResponseInfo* response, NHTTPi_HDRBUFLIST**
} }
static int LowerCase(int character) { static int LowerCase(int character) {
if((character>='A') & (character<='Z')) character+=32; return ((character >= 'A') & (character <= 'Z')) ? character + 32 : character;
return character;
} }
s32 NHTTPi_findNextLineHdrRecvBuf(const NHTTPResponseInfo* response, s32 position, s32 limit, s32* colon, s32* newlineLength) { s32 NHTTPi_findNextLineHdrRecvBuf(const NHTTPResponseInfo* response, s32 position, s32 limit, s32* colon, s32* newlineLength) {
NHTTPi_HDRBUFLIST* block; NHTTPi_HDRBUFLIST* block;
s32 offset; s32 offset;
s32 next=-1;
BOOL carriage=FALSE;
if(colon) *colon=-1; if(colon) *colon=-1;
if(position>=limit) return -1; if (position < limit) {
FindHeaderBlock(response,position,&block,&offset); s32 next=-1;
for(; position<limit; ++position) { BOOL carriage=FALSE;
s8 character=ReadHeaderChar(response,&block,&offset); FindHeaderBlock(response,position,&block,&offset);
if(character==':' && colon && *colon<0) *colon=position; for(; position<limit; ++position) {
if(carriage) { int character=ReadHeaderChar(response,&block,&offset);
if(character=='\n') { if((s8)character==':' && colon && *colon<0) *colon=position;
next=position==limit-1 ? 0 : position+1; if(carriage) {
if(newlineLength) *newlineLength=2; if((s8)character=='\n') {
next=position==limit-1 ? 0 : position+1;
if(newlineLength) *newlineLength=2;
}
return next;
}
if((s8)character=='\r') {
next=position==limit-1 ? 0 : position+1;
carriage=TRUE;
if(newlineLength) *newlineLength=1;
}
if((s8)character=='\n') {
next=position==limit-1 ? 0 : position+1;
if(newlineLength) *newlineLength=1;
return next;
} }
return next;
}
if(character=='\r') {
next=position==limit-1 ? 0 : position+1;
carriage=TRUE;
if(newlineLength) *newlineLength=1;
}
if(character=='\n') {
next=position==limit-1 ? 0 : position+1;
if(newlineLength) *newlineLength=1;
return next;
} }
} }
return -1; return -1;
@@ -62,11 +62,12 @@ s32 NHTTPi_findNextLineHdrRecvBuf(const NHTTPResponseInfo* response, s32 positio
s32 NHTTPi_skipSpaceHdrRecvBuf(const NHTTPResponseInfo* response, s32 position, s32 limit) { s32 NHTTPi_skipSpaceHdrRecvBuf(const NHTTPResponseInfo* response, s32 position, s32 limit) {
NHTTPi_HDRBUFLIST* block; NHTTPi_HDRBUFLIST* block;
s32 offset; s32 offset;
if(position>=limit) return -1; if (position < limit) {
FindHeaderBlock(response,position,&block,&offset); FindHeaderBlock(response,position,&block,&offset);
for(; position<limit; ++position) { for(; position<limit; ++position) {
s8 character=ReadHeaderChar(response,&block,&offset); s8 character=ReadHeaderChar(response,&block,&offset);
if(character!=' ') return position; if(character!=' ') return position;
}
} }
return -1; return -1;
} }
@@ -74,15 +75,17 @@ s32 NHTTPi_skipSpaceHdrRecvBuf(const NHTTPResponseInfo* response, s32 position,
s32 NHTTPi_compareTokenN_HdrRecvBuf(const NHTTPResponseInfo* response, s32 position, s32 limit, const char* token, s8 delimiter) { s32 NHTTPi_compareTokenN_HdrRecvBuf(const NHTTPResponseInfo* response, s32 position, s32 limit, const char* token, s8 delimiter) {
NHTTPi_HDRBUFLIST* block; NHTTPi_HDRBUFLIST* block;
s32 offset; s32 offset;
s8 character; int character;
if(position>=limit) return -1;
FindHeaderBlock(response,position,&block,&offset); if (position < limit) {
character=ReadHeaderChar(response,&block,&offset); FindHeaderBlock(response, position, &block, &offset);
while(LowerCase(character)==LowerCase(*token)) { character = ReadHeaderChar(response, &block, &offset);
if(*token==0 || *token==' ' || *token==delimiter || position==limit-1) return 0; while (LowerCase((s8)character) == LowerCase(*token)) {
character=ReadHeaderChar(response,&block,&offset); if (*token == 0 || *token == ' ' || *token == delimiter || position == limit - 1) return 0;
++position; character = ReadHeaderChar(response, &block, &offset);
++token; ++position;
++token;
}
} }
return -1; return -1;
} }
@@ -91,32 +94,35 @@ s32 NHTTPi_loadFromHdrRecvBuf(NHTTPResponseInfo* response, char* destination, s3
s32 amount; s32 amount;
NHTTPi_HDRBUFLIST* block; NHTTPi_HDRBUFLIST* block;
if(position+length>response->headerLen) return FALSE; if (position + length <= response->headerLen) {
if(length) {
if(position<1024) {
amount=length;
if(length>1024-position) amount=1024-position;
NHTTPi_memcpy(destination,response->hdrBufFirst+position,amount);
position+=amount; length-=amount; destination+=amount;
}
if(length) { if(length) {
s32 blocks; if(position<1024) {
position-=1024;
block=response->hdrBufBlock_p;
blocks=position>>9;
position&=511;
while(blocks--) block=block->next_p;
while(length) {
amount=length; amount=length;
if(length>512-position) amount=512-position; if(length>1024-position) amount=1024-position;
NHTTPi_memcpy(destination,block->block+position,amount); NHTTPi_memcpy(destination,response->hdrBufFirst+position,amount);
position=(position+amount)&511; position+=amount; length-=amount; destination+=amount;
block=block->next_p; }
length-=amount; destination+=amount; if(length) {
s32 blocks;
position-=1024;
block=response->hdrBufBlock_p;
blocks=position>>9;
position&=511;
while(blocks--) block=block->next_p;
while(length) {
amount=length;
if(length>512-position) amount=512-position;
NHTTPi_memcpy(destination,block->block+position,amount);
position+=amount;
position&=511;
block=block->next_p;
length-=amount; destination+=amount;
}
} }
} }
return TRUE;
} }
return TRUE; return FALSE;
} }
BOOL NHTTPi_isRecvBufFull(NHTTPResponseInfo* response, u32 length) { return length>=response->recvBufLen; } BOOL NHTTPi_isRecvBufFull(NHTTPResponseInfo* response, u32 length) { return length>=response->recvBufLen; }

View File

@@ -95,7 +95,7 @@ s32 NHTTPi_SocRecv_sub(NHTTPConnectionInfo* connection, s32 socket, void* data,
} else return result; } else return result;
} }
if(connection->recvBufDataLen!=0) { if(connection->recvBufDataLen!=0) {
if((u32)length>connection->recvBufDataLen) length=connection->recvBufDataLen; length = (u32)length > connection->recvBufDataLen ? connection->recvBufDataLen : length;
NHTTPi_memcpy(data,buffer+connection->recvBufOffset,length); NHTTPi_memcpy(data,buffer+connection->recvBufOffset,length);
connection->recvBufDataLen-=length; connection->recvBufDataLen-=length;
if(connection->recvBufDataLen==0) { if(connection->recvBufDataLen==0) {
@@ -135,10 +135,14 @@ s32 NHTTPi_SocSend_sub(s32 socket, const char* data, u32 length, s32 flags) {
if(head>length) head=length; if(head>length) head=length;
NHTTPi_memcpy(buffer,data,head); NHTTPi_memcpy(buffer,data,head);
result=SOSend(socket,buffer,head,flags); result=SOSend(socket,buffer,head,flags);
if(result<=0) return result; if (result > 0) {
sent=result; sent = result;
if((u32)result<head) return result; if ((u32)result < head) return result;
data+=result; length-=result; data += result;
length -= result;
} else {
return result;
}
} }
if((s32)length>0) { if((s32)length>0) {
head=length&~31; head=length&~31;
@@ -164,7 +168,7 @@ s32 NHTTPi_SocSend_sub(s32 socket, const char* data, u32 length, s32 flags) {
return sent; return sent;
} }
s32 NHTTPi_SocSend(NHTTPRequestInfo* request, s32 socket, const char* data, s32 length, s32 flags) { s32 NHTTPi_SocSend(const NHTTPRequestInfo* request, s32 socket, const void* data, s32 length, s32 flags) {
s32 result; s32 result;
SSLId ssl=request->sslId; SSLId ssl=request->sslId;
if(ssl>0) result=SSLWrite(ssl,data,length); if(ssl>0) result=SSLWrite(ssl,data,length);

View File

@@ -102,23 +102,25 @@ s32 NHTTPi_strToInt(const char* string, s32 length) {
return value; return value;
} }
static inline u32 TakeDecimalDigit(u32* remaining, u32 scale) {
u32 digit = *remaining / scale;
*remaining -= digit * scale;
return digit;
}
s32 NHTTPi_intToStr(char* destination, u32 value) { s32 NHTTPi_intToStr(char* destination, u32 value) {
u32 scales[9]={1000000000,100000000,10000000,1000000,100000,10000,1000,100,10}; u32 scales[9]={1000000000,100000000,10000000,1000000,100000,10000,1000,100,10};
char* output;
int digit; int digit;
BOOL started; BOOL started;
s32 length; s32 length;
output = destination;
length = 0; length = 0;
started = FALSE; started = FALSE;
for(digit=0; digit<9; ++digit) { for(digit=0; digit<9; ++digit) {
if(value>=scales[digit]) { if(value>=scales[digit]) {
u32 quotient=value/scales[digit]; u32 quotient=TakeDecimalDigit(&value, scales[digit]);
started=TRUE; started=TRUE;
++length; destination[length++]=quotient+'0';
*output++=quotient+'0'; } else if(started) { destination[length++]='0'; }
value-=quotient*scales[digit];
} else if(started) { *output++='0'; ++length; }
} }
destination[length]=value+'0'; destination[length]=value+'0';
return length+1; return length+1;

View File

@@ -82,7 +82,7 @@ s32 NHTTPi_ReceivedCallback(void* mutex, NHTTPConnectionInfo* connection);
void NHTTPi_NotifyCompletion(NHTTPConnectionInfo* connection); void NHTTPi_NotifyCompletion(NHTTPConnectionInfo* connection);
void NHTTPi_SetVirtualContentLength(NHTTPConnectionInfo* connection, u32 length); void NHTTPi_SetVirtualContentLength(NHTTPConnectionInfo* connection, u32 length);
BOOL NHTTPi_isRecvBufFull(NHTTPResponseInfo* response, s32 offset); BOOL NHTTPi_isRecvBufFull(NHTTPResponseInfo* response, s32 offset);
s32 NHTTPi_SocSend(NHTTPRequestInfo* request, s32 socket, const void* buffer, s32 length, s32 flags); s32 NHTTPi_SocSend(const NHTTPRequestInfo* request, s32 socket, const void* buffer, s32 length, s32 flags);
s32 NHTTPi_SocRecv(void* mutex, NHTTPRequestInfo* request, s32 socket, void* buffer, s32 length, s32 flags); s32 NHTTPi_SocRecv(void* mutex, NHTTPRequestInfo* request, s32 socket, void* buffer, s32 length, s32 flags);
s32 NHTTPi_SocClose(void* mutex, NHTTPRequestInfo* request, s32 socket); s32 NHTTPi_SocClose(void* mutex, NHTTPRequestInfo* request, s32 socket);
s32 NHTTPi_SocOpen(NHTTPRequestInfo* request); s32 NHTTPi_SocOpen(NHTTPRequestInfo* request);
@@ -986,9 +986,16 @@ static BOOL NHTTPi_ThreadParseHeaderProc(NHTTPThreadContext* context)
if (length > 0x100) context->keepAlive = FALSE; if (length > 0x100) context->keepAlive = FALSE;
else if (length > 0) else if (length > 0)
{ {
struct TokenMatch {
BOOL matched;
};
struct TokenMatch match = {FALSE};
if (NHTTPi_compareTokenN_HdrRecvBuf(response, offset, offset + length, "Keep-Alive", 0) == 0) if (NHTTPi_compareTokenN_HdrRecvBuf(response, offset, offset + length, "Keep-Alive", 0) == 0)
context->keepAlive = TRUE; {
else context->keepAlive = FALSE; match.matched = TRUE;
context->keepAlive = match.matched;
}
else context->keepAlive = match.matched;
} }
else context->keepAlive = FALSE; else context->keepAlive = FALSE;
} }

View File

@@ -120,10 +120,11 @@ NWC24Err NWC24iMinutesToOSCalendarTime(OSCalendarTime* calendar, s32 minutes) {
NWC24Err NWC24iDateToOSCalendarTime(OSCalendarTime* calendar, const NWC24Date* date) { NWC24Err NWC24iDateToOSCalendarTime(OSCalendarTime* calendar, const NWC24Date* date) {
BOOL isLeapYear; BOOL isLeapYear;
s32 days; s32 days;
const u16 year = date->year;
isLeapYear = 0; isLeapYear = 0;
calendar->year = date->year; calendar->year = year;
calendar->mon = date->month - 1; calendar->mon = date->month - 1;
calendar->mday = date->day; calendar->mday = date->day;
calendar->hour = date->hour; calendar->hour = date->hour;
@@ -132,7 +133,7 @@ NWC24Err NWC24iDateToOSCalendarTime(OSCalendarTime* calendar, const NWC24Date* d
calendar->msec = 0; calendar->msec = 0;
calendar->usec = 0; calendar->usec = 0;
calendar->yday = date->day + DAYS_OF_YEAR[date->month - 1] - 1; calendar->yday = date->day + DAYS_OF_YEAR[date->month - 1] - 1;
if (((date->year % 4 == 0 && date->year % 100 != 0) || date->year % 400 == 0)) { if (((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)) {
isLeapYear = 1; isLeapYear = 1;
} }
if (isLeapYear && date->month > 2) { if (isLeapYear && date->month > 2) {
@@ -176,7 +177,8 @@ s32 ConvertDateToDays(u16 year, u8 month, u8 day) {
} }
validDate: validDate:
daysOfYear = day - 1 + DAYS_OF_YEAR[month - 1]; daysOfYear = day - 1;
daysOfYear += DAYS_OF_YEAR[month - 1];
if (month >= 3) { if (month >= 3) {
isLeapYear = 0; isLeapYear = 0;
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
@@ -206,31 +208,41 @@ void ConvertDaysToDate(u16* year, u8* month, u8* day, s32 days) {
for (;;) { for (;;) {
u16 currentYear = *year; u16 currentYear = *year;
s32 previousDays = days; s32 previousDays = days;
BOOL leapYear = (currentYear % 4 == 0 && currentYear % 100 != 0) || currentYear % 400 == 0; BOOL leapYear = TRUE;
BOOL commonLeapYear = FALSE;
if (currentYear % 4 == 0 && currentYear % 100 != 0) {
commonLeapYear = TRUE;
}
if (!commonLeapYear && currentYear % 400 != 0) {
leapYear = FALSE;
}
days -= 365 + (leapYear != FALSE); days -= 365 + (leapYear != FALSE);
if (days < 0) { if (days < 0) {
days = previousDays; days = previousDays;
break; break;
} }
*year = *year + 1; *year += 1;
continue;
} }
for (;;) { for (;;) {
s32 previousDays = days; s32 previousDays;
if (*month == 2) { u8 currentMonth;
BOOL leapYear = IsLeapYear(*year); const u8* parsedMonth = month;
if (leapYear) { previousDays = days;
days -= 29; currentMonth = *parsedMonth;
} else { if (currentMonth == 2 && IsLeapYear(*year)) {
days -= DAYS_OF_MONTH[*month - 1]; days -= 29;
}
} else { } else {
days -= DAYS_OF_MONTH[*month - 1]; days -= DAYS_OF_MONTH[currentMonth - 1];
} }
if (days < 0) { if (days >= 0) {
*day += previousDays; *month += 1;
return; } else {
days = previousDays;
break;
} }
*month = *month + 1;
} }
*day += days;
} }

View File

@@ -64,7 +64,7 @@ static NWC24Err ClearMBCEntry(MBCHeader* header, NWC24File* file, u32 offset);
static NWC24Err MountVFMBox(NWC24MBoxType type); static NWC24Err MountVFMBox(NWC24MBoxType type);
static NWC24Err CopyMsgObjToMBCFmt(const NWC24MsgObjPrivate* msg, MBCEntry* entry); static NWC24Err CopyMsgObjToMBCFmt(const NWC24MsgObjPrivate* msg, MBCEntry* entry);
static NWC24Err CopyMsgObjToPrvFmt(const MBCEntry* entry, NWC24MsgObjPrivate* msg) NO_INLINE; static NWC24Err CopyMsgObjToPrvFmt(const MBCEntry* entry, NWC24MsgObjPrivate* msg) NO_INLINE;
BOOL NWC24iIsMsgObjReadable(const MBCEntry* entry) NO_INLINE; BOOL NWC24iIsMsgObjReadable(MBCEntry* entry) NO_INLINE;
NWC24Err NWC24CreateVF(const char* path, u32 size); NWC24Err NWC24CreateVF(const char* path, u32 size);
static inline NWC24Err MakeCtrlPath(char* path, NWC24MBoxType type) { static inline NWC24Err MakeCtrlPath(char* path, NWC24MBoxType type) {
@@ -170,7 +170,7 @@ NWC24Err NWC24GetMsgObj(NWC24MsgObj* msg, NWC24MBoxType type, u32 id) {
u32 count = 0; u32 count = 0;
if (!NWC24IsMsgLibOpened() && !NWC24IsMsgLibOpenedByTool()) if (!NWC24IsMsgLibOpened() && !NWC24IsMsgLibOpenedByTool())
return NWC24_ERR_LIB_NOT_OPENED; return NWC24_ERR_LIB_NOT_OPENED;
entry = (MBCEntry*)NWC24WorkP->unk_0x1800; entry = (MBCEntry*)NWC24WorkP->mbcEntry;
memset(entry, 0, sizeof(*entry)); memset(entry, 0, sizeof(*entry));
if (id == 0) if (id == 0)
return NWC24_ERR_HIDDEN; return NWC24_ERR_HIDDEN;
@@ -221,7 +221,7 @@ NWC24Err NWC24GetMsgObj(NWC24MsgObj* msg, NWC24MBoxType type, u32 id) {
return result; return result;
} }
BOOL NWC24iIsMsgObjReadable(const MBCEntry* entry) { BOOL NWC24iIsMsgObjReadable(MBCEntry* entry) {
if (!(entry->type & 0x200000)) if (!(entry->type & 0x200000))
return FALSE; return FALSE;
if (entry->type & 0xFE000000) if (entry->type & 0xFE000000)
@@ -251,7 +251,7 @@ NWC24Err NWC24GetMsgIdList(NWC24MBoxType type, u32* ids, u32 maxLength) {
MBCEntry* entry; MBCEntry* entry;
if (!NWC24IsMsgLibOpened() && !NWC24IsMsgLibOpenedByTool()) if (!NWC24IsMsgLibOpened() && !NWC24IsMsgLibOpenedByTool())
return NWC24_ERR_LIB_NOT_OPENED; return NWC24_ERR_LIB_NOT_OPENED;
entry = (MBCEntry*)NWC24WorkP->unk_0x1800; entry = (MBCEntry*)NWC24WorkP->mbcEntry;
err = GetCachedMBCHeader(type, &header); err = GetCachedMBCHeader(type, &header);
if (err != NWC24_OK) if (err != NWC24_OK)
return err; return err;
@@ -307,11 +307,11 @@ NWC24Err NWC24iOpenMBox(void) {
NWC24File recvFile, sendFile; NWC24File recvFile, sendFile;
char* path = NWC24WorkP->pathWork; char* path = NWC24WorkP->pathWork;
NWC24Err err; NWC24Err err;
Mail_memset(NWC24WorkP->unk_0x1700, 0, 128); Mail_memset(NWC24WorkP->sendMbcHeader, 0, 128);
err = GetCachedMBCHeader(NWC24_MBOX_TYPE_SEND, &header); err = GetCachedMBCHeader(NWC24_MBOX_TYPE_SEND, &header);
if (err != NWC24_OK) if (err != NWC24_OK)
return err; return err;
Mail_memset(NWC24WorkP->unk_0x1780, 0, 128); Mail_memset(NWC24WorkP->recvMbcHeader, 0, 128);
err = GetCachedMBCHeader(NWC24_MBOX_TYPE_RECV, &header); err = GetCachedMBCHeader(NWC24_MBOX_TYPE_RECV, &header);
if (err != NWC24_OK) if (err != NWC24_OK)
return err; return err;
@@ -340,11 +340,11 @@ NWC24Err NWC24iInitMBox(void) {
NWC24File recvFile, sendFile; NWC24File recvFile, sendFile;
NWC24Err recvResult, sendResult, err, sendStatus; NWC24Err recvResult, sendResult, err, sendStatus;
char* path = NWC24WorkP->pathWork; char* path = NWC24WorkP->pathWork;
Mail_memset(NWC24WorkP->unk_0x1700, 0, 128); Mail_memset(NWC24WorkP->sendMbcHeader, 0, 128);
sendResult = CreateCtrlFile(NWC24_MBOX_TYPE_SEND, FALSE); sendResult = CreateCtrlFile(NWC24_MBOX_TYPE_SEND, FALSE);
if (sendResult < 0) if (sendResult < 0)
return sendResult; return sendResult;
Mail_memset(NWC24WorkP->unk_0x1780, 0, 128); Mail_memset(NWC24WorkP->recvMbcHeader, 0, 128);
recvResult = CreateCtrlFile(NWC24_MBOX_TYPE_RECV, FALSE); recvResult = CreateCtrlFile(NWC24_MBOX_TYPE_RECV, FALSE);
if (recvResult < 0) if (recvResult < 0)
return recvResult; return recvResult;
@@ -555,14 +555,14 @@ NWC24Err NWC24iMBoxFlushHeader(NWC24MBoxType type) {
return result != NWC24_OK ? result : closeResult; return result != NWC24_OK ? result : closeResult;
} }
static inline void GetOldestMsgId(const MBCHeader* header, u32* id) { static inline void GetOldestMsgId(const MBCHeader* header, volatile u32* id) {
*id = header->oldestId; *id = header->oldestId;
} }
NWC24Err NWC24iMBoxCheck(NWC24MBoxType type, u32 size) { NWC24Err NWC24iMBoxCheck(NWC24MBoxType type, u32 size) {
u32 required; u32 required;
struct { struct {
u32 oldestId; volatile u32 oldestId;
MBCHeader* header; MBCHeader* header;
} mailbox; } mailbox;
NWC24Err err; NWC24Err err;
@@ -616,11 +616,11 @@ static NWC24Err CreateCtrlFile(NWC24MBoxType type, BOOL force) {
err = MakeCtrlPath(path, type); err = MakeCtrlPath(path, type);
if (err != NWC24_OK) if (err != NWC24_OK)
return err; return err;
entry = (MBCEntry*)NWC24WorkP->unk_0x1800; entry = (MBCEntry*)NWC24WorkP->mbcEntry;
if (type == NWC24_MBOX_TYPE_SEND) if (type == NWC24_MBOX_TYPE_SEND)
header = (MBCHeader*)NWC24WorkP->unk_0x1700; header = (MBCHeader*)NWC24WorkP->sendMbcHeader;
else if (type == NWC24_MBOX_TYPE_RECV) else if (type == NWC24_MBOX_TYPE_RECV)
header = (MBCHeader*)NWC24WorkP->unk_0x1780; header = (MBCHeader*)NWC24WorkP->recvMbcHeader;
else else
return NWC24_ERR_INVALID_VALUE; return NWC24_ERR_INVALID_VALUE;
result = err; result = err;
@@ -676,7 +676,7 @@ static NWC24Err DeleteMsg(NWC24MBoxType type, u32 id, BOOL protect) {
NWC24Err err, deleteResult, closeResult; NWC24Err err, deleteResult, closeResult;
if (!NWC24IsMsgLibOpened() && !NWC24IsMsgLibOpenedByTool()) if (!NWC24IsMsgLibOpened() && !NWC24IsMsgLibOpenedByTool())
return NWC24_ERR_LIB_NOT_OPENED; return NWC24_ERR_LIB_NOT_OPENED;
entry = (MBCEntry*)NWC24WorkP->unk_0x1800; entry = (MBCEntry*)NWC24WorkP->mbcEntry;
err = GetCachedMBCHeader(type, &header); err = GetCachedMBCHeader(type, &header);
if (err != NWC24_OK) if (err != NWC24_OK)
return err; return err;
@@ -754,7 +754,7 @@ static NWC24Err DuplicationCheck(MBCHeader* header, const NWC24MsgObjPrivate* ms
NWC24Err clearResult, deleteResult; NWC24Err clearResult, deleteResult;
if (type == NWC24_MBOX_TYPE_SEND) if (type == NWC24_MBOX_TYPE_SEND)
return NWC24_OK; return NWC24_OK;
entry = (MBCEntry*)NWC24WorkP->unk_0x1800; entry = (MBCEntry*)NWC24WorkP->mbcEntry;
for (offset = 128; offset < header->fileSize; offset += 128) { for (offset = 128; offset < header->fileSize; offset += 128) {
if (count >= header->numMessages) if (count >= header->numMessages)
break; break;
@@ -783,7 +783,7 @@ static NWC24Err DuplicationCheck(MBCHeader* header, const NWC24MsgObjPrivate* ms
continue; continue;
} }
if (msg->unk_0x1C != 0 && entry->crc == msg->unk_0x1C && entry->type == msg->type && entry->length == msg->length && if (msg->unk_0x1C != 0 && entry->crc == msg->unk_0x1C && entry->type == msg->type && entry->length == msg->length &&
entry->flags == msg->unk_0x10 && (s32)entry->date == (s32)msg->date) { entry->flags == msg->headerSize && (s32)entry->date == (s32)msg->date) {
duplicateId = entry->msgId; duplicateId = entry->msgId;
duplicateOffset = offset; duplicateOffset = offset;
continue; continue;
@@ -809,9 +809,9 @@ static NWC24Err GetCachedMBCHeader(NWC24MBoxType type, MBCHeader** header) {
char* path; char* path;
NWC24Err err = NWC24_OK, closeResult; NWC24Err err = NWC24_OK, closeResult;
if (type == NWC24_MBOX_TYPE_SEND) if (type == NWC24_MBOX_TYPE_SEND)
*header = (MBCHeader*)NWC24WorkP->unk_0x1700; *header = (MBCHeader*)NWC24WorkP->sendMbcHeader;
else if (type == NWC24_MBOX_TYPE_RECV) else if (type == NWC24_MBOX_TYPE_RECV)
*header = (MBCHeader*)NWC24WorkP->unk_0x1780; *header = (MBCHeader*)NWC24WorkP->recvMbcHeader;
else { else {
*header = NULL; *header = NULL;
return NWC24_ERR_INVALID_VALUE; return NWC24_ERR_INVALID_VALUE;
@@ -874,7 +874,7 @@ static NWC24Err InitMBCHeader(MBCHeader* header, NWC24MBoxType type) {
static NWC24Err AddMBCEntry(MBCHeader* header, const NWC24MsgObjPrivate* msg, NWC24File* file) { static NWC24Err AddMBCEntry(MBCHeader* header, const NWC24MsgObjPrivate* msg, NWC24File* file) {
u32 offset = header->freeOffset; u32 offset = header->freeOffset;
MBCEntry* entry = (MBCEntry*)NWC24WorkP->unk_0x1800; MBCEntry* entry = (MBCEntry*)NWC24WorkP->mbcEntry;
u32 next; u32 next;
NWC24Err err; NWC24Err err;
if (offset == 0) if (offset == 0)
@@ -906,7 +906,7 @@ static NWC24Err AddMBCEntry(MBCHeader* header, const NWC24MsgObjPrivate* msg, NW
} }
static NWC24Err ClearMBCEntry(MBCHeader* header, NWC24File* file, u32 offset) { static NWC24Err ClearMBCEntry(MBCHeader* header, NWC24File* file, u32 offset) {
MBCEntry* entry = (MBCEntry*)NWC24WorkP->unk_0x1800; MBCEntry* entry = (MBCEntry*)NWC24WorkP->mbcEntry;
NWC24Err err = NWC24FSeek(file, offset, NWC24_SEEK_BEG); NWC24Err err = NWC24FSeek(file, offset, NWC24_SEEK_BEG);
if (err != NWC24_OK) if (err != NWC24_OK)
return err; return err;
@@ -947,8 +947,8 @@ static NWC24Err MountVFMBox(NWC24MBoxType type) {
} }
static NWC24Err CopyMsgObjToMBCFmt(const NWC24MsgObjPrivate* msg, MBCEntry* entry) { static NWC24Err CopyMsgObjToMBCFmt(const NWC24MsgObjPrivate* msg, MBCEntry* entry) {
u32 field1 = ((u32)msg->unk_0x30.ptr & 0xFFFFF) | (msg->unk_0x30.size << 20); u32 field1 = ((u32)msg->fromData.ptr & 0xFFFFF) | (msg->fromData.size << 20);
u32 field2 = ((u32)msg->unk_0x38.ptr & 0xFFFFF) | (msg->unk_0x38.size << 20); u32 field2 = ((u32)msg->toData.ptr & 0xFFFFF) | (msg->toData.size << 20);
u32 field3 = ((u32)msg->subject.ptr & 0xFFFFF) | (msg->subject.size << 20); u32 field3 = ((u32)msg->subject.ptr & 0xFFFFF) | (msg->subject.size << 20);
u32 field4 = ((u32)msg->unk_0x50.ptr & 0xFFFFF) | (msg->unk_0x50.size << 20); u32 field4 = ((u32)msg->unk_0x50.ptr & 0xFFFFF) | (msg->unk_0x50.size << 20);
u32 field5 = ((u32)msg->unk_0x58.ptr & 0xFFFFF) | (msg->unk_0x58.size << 20); u32 field5 = ((u32)msg->unk_0x58.ptr & 0xFFFFF) | (msg->unk_0x58.size << 20);
@@ -956,7 +956,7 @@ static NWC24Err CopyMsgObjToMBCFmt(const NWC24MsgObjPrivate* msg, MBCEntry* entr
entry->type = msg->type; entry->type = msg->type;
entry->length = msg->length; entry->length = msg->length;
entry->appId = msg->appId; entry->appId = msg->appId;
entry->flags = msg->unk_0x10; entry->flags = msg->headerSize;
entry->tag = msg->tag; entry->tag = msg->tag;
entry->ledPattern = msg->ledPattern; entry->ledPattern = msg->ledPattern;
entry->crc = msg->unk_0x1C; entry->crc = msg->unk_0x1C;
@@ -1003,7 +1003,7 @@ static NWC24Err CopyMsgObjToPrvFmt(const MBCEntry* entry, NWC24MsgObjPrivate* ms
msg->type = entry->type; msg->type = entry->type;
msg->length = entry->length; msg->length = entry->length;
msg->appId = entry->appId; msg->appId = entry->appId;
msg->unk_0x10 = entry->flags; msg->headerSize = entry->flags;
msg->tag = entry->tag; msg->tag = entry->tag;
msg->ledPattern = entry->ledPattern; msg->ledPattern = entry->ledPattern;
msg->unk_0x1C = entry->crc; msg->unk_0x1C = entry->crc;
@@ -1019,10 +1019,10 @@ static NWC24Err CopyMsgObjToPrvFmt(const MBCEntry* entry, NWC24MsgObjPrivate* ms
msg->textSize = entry->textSize; msg->textSize = entry->textSize;
msg->dwcId = entry->dwcId; msg->dwcId = entry->dwcId;
msg->iconNew = entry->iconNew; msg->iconNew = entry->iconNew;
msg->unk_0x30.ptr = (void*)offset1; msg->fromData.ptr = (void*)offset1;
msg->unk_0x30.size = size1; msg->fromData.size = size1;
msg->unk_0x38.ptr = (void*)offset2; msg->toData.ptr = (void*)offset2;
msg->unk_0x38.size = size2; msg->toData.size = size2;
msg->subject.ptr = (void*)offset3; msg->subject.ptr = (void*)offset3;
msg->subject.size = size3; msg->subject.size = size3;
msg->unk_0x50.ptr = (void*)offset4; msg->unk_0x50.ptr = (void*)offset4;

View File

@@ -231,11 +231,11 @@ static NWC24Err QEncode(char* encoded, u32 encodedCapacity, u32* encodedSize, u8
} }
static NWC24Err QDecode(char* decoded, u32 decodedCapacity, u32* decodedSize, char* encoded, u32 encodedSize, u32* encodedSizeOut, int flags) { static NWC24Err QDecode(char* decoded, u32 decodedCapacity, u32* decodedSize, char* encoded, u32 encodedSize, u32* encodedSizeOut, int flags) {
u32 decodedOffset = 0;
u32 encodedOffset; u32 encodedOffset;
u32 decodedOffset = 0;
u8 value = 0;
char* input; char* input;
char* output; char* output;
u8 value = 0;
NWC24Err result = NWC24_OK; NWC24Err result = NWC24_OK;
if (decoded == NULL) if (decoded == NULL)
@@ -255,7 +255,7 @@ static NWC24Err QDecode(char* decoded, u32 decodedCapacity, u32* decodedSize, ch
input = encoded; input = encoded;
output = decoded; output = decoded;
for (encodedOffset = 0; encodedOffset < encodedSize; encodedOffset++) { for (encodedOffset = 0; encodedOffset < encodedSize; encodedOffset++) {
if (decodedCapacity <= decodedOffset) { if (decodedOffset >= decodedCapacity) {
result = NWC24_ERR_OVERFLOW; result = NWC24_ERR_OVERFLOW;
break; break;
} }
@@ -265,15 +265,15 @@ static NWC24Err QDecode(char* decoded, u32 decodedCapacity, u32* decodedSize, ch
decodedOffset++; decodedOffset++;
} else if (*input == '=' && encodedOffset + 2 < encodedSize) { } else if (*input == '=' && encodedOffset + 2 < encodedSize) {
BOOL validHex = TRUE; BOOL validHex = TRUE;
u32 inputAfterEqual = encodedOffset + 1; input++;
char* current = ++input; encodedOffset++;
if (*current == ' ' || *current == '\t') { if (*input == ' ' || *input == '\t') {
char* next = current + 1; char* next = input + 1;
u32 scan = 1; u32 scan = 1;
while (inputAfterEqual + scan + 1 < encodedSize) { while (encodedOffset + scan + 1 < encodedSize) {
if (*next == '\r' && next[1] == '\n') { if (*next == '\r' && next[1] == '\n') {
inputAfterEqual += scan; encodedOffset += scan;
current = next; input = next;
break; break;
} }
if (*next != ' ' && *next != '\t') { if (*next != ' ' && *next != '\t') {
@@ -283,29 +283,27 @@ static NWC24Err QDecode(char* decoded, u32 decodedCapacity, u32* decodedSize, ch
scan++; scan++;
} }
} }
if (*current == '\r' && current[1] == '\n') { if (*input == '\r' && input[1] == '\n') {
current += 2; input += 2;
encodedOffset = inputAfterEqual + 1; encodedOffset++;
input = current;
} else { } else {
int high = Util_xtoi(*current); int high = Util_xtoi(*input);
int low; int low;
if (high >= 0) { if (high >= 0) {
value = (high & 0x0F) << 4; value = (high & 0x0F) << 4;
} }
if (high < 0) { validHex = FALSE; } if (high < 0) { validHex = FALSE; }
low = Util_xtoi(current[1]); low = Util_xtoi(input[1]);
if (low >= 0) { if (low >= 0) {
value |= low & 0x0F; value |= low & 0x0F;
} }
if (low < 0) { validHex = FALSE; } if (low < 0) { validHex = FALSE; }
current += 2; input += 2;
if (validHex) { if (validHex) {
*output++ = (char)value; *output++ = (char)value;
decodedOffset++; decodedOffset++;
} }
encodedOffset = inputAfterEqual + 1; encodedOffset++;
input = current;
} }
} else { } else {
*output++ = *input++; *output++ = *input++;
@@ -501,22 +499,42 @@ static BOOL CopyWithoutLinearWhiteSpaces(char* output, int* outputSize, char* in
} }
static inline char* FindMarker(char* input, u32 size, const char* marker) { static inline char* FindMarker(char* input, u32 size, const char* marker) {
u32 markerLength = Mail_strlen(marker);
u32 offset; u32 offset;
u32 markerLength;
markerLength = Mail_strlen(marker);
for (offset = 0; offset <= size; offset++) { for (offset = 0; offset <= size; offset++) {
char* current = input + offset; char* current = input + offset;
if (Mail_strncmp(current, marker, markerLength) == 0) if (Mail_strncmp(current, marker, markerLength) == 0)
return current; return input + offset;
} }
return NULL; return NULL;
} }
static inline char* FindMarkerAfterPrefix(char* input, u32 size, u32 prefix, const char* marker) { static inline char* FindMarkerAfterPrefix(char* input, u32 size, u32 prefix, const char* marker) {
u32 markerLength = Mail_strlen(marker); char* current;
char* current = input + prefix;
u32 offset; u32 offset;
u32 markerLength;
markerLength = Mail_strlen(marker);
current = input + prefix;
for (offset = 0; offset <= size; offset++) { for (offset = 0; offset <= size; offset++) {
if (Mail_strncmp(current, marker, markerLength) == 0) { if (Mail_strncmp(current, marker, markerLength) == 0) {
return input + offset + prefix; return input + prefix + offset;
}
current++;
}
return NULL;
}
static inline char* FindEncodingMarker(char* encoded, u32 size) {
u32 offset;
u32 markerLength;
const char* marker;
char* current;
marker = "?";
markerLength = Mail_strlen(marker);
current = encoded;
for (offset = 0; offset <= size; offset++) {
if (Mail_strncmp(current, marker, markerLength) == 0) {
return encoded + offset;
} }
current++; current++;
} }
@@ -524,14 +542,28 @@ static inline char* FindMarkerAfterPrefix(char* input, u32 size, u32 prefix, con
} }
static inline NWC24Err ExtractWordEncoding(char* encoding, u32* encodingSize, char* encoded, u32 encodedSize) { static inline NWC24Err ExtractWordEncoding(char* encoding, u32* encodingSize, char* encoded, u32 encodedSize) {
char* delimiter = FindMarkerAfterPrefix(encoded, encodedSize, 0, "?"); char* delimiter = FindEncodingMarker(encoded, encodedSize);
if (delimiter == NULL) { return NWC24_ERR_INVALID_VALUE; } if (delimiter == NULL) { return NWC24_ERR_INVALID_VALUE; }
*encoding = delimiter[1]; *encoding = delimiter[1];
*encodingSize = 2; *encodingSize = 2;
return NWC24_OK; return NWC24_OK;
} }
static inline BOOL IsLinearWhitespaceOnly(char* text, u32 size) {
u32 offset;
BOOL whitespaceOnly;
whitespaceOnly = TRUE;
for (offset = 0; offset < size && text[offset] != '\0'; offset++) {
char value = text[offset];
if (value != ' ' && value != '\t' && value != '\r' && value != '\n') {
whitespaceOnly = FALSE;
}
}
return whitespaceOnly;
}
static NWC24Err DecodeWord(char* charsetData, u32 charsetCapacity, char* decoded, u32 decodedCapacity, u32* decodedSize, char* encoded, static NWC24Err DecodeWord(char* charsetData, u32 charsetCapacity, char* decoded, u32 decodedCapacity, u32* decodedSize, char* encoded,
u32 encodedSize, u32* encodedSizeOut) { u32 encodedSize, u32* encodedSizeOut) {
char encoding;
char* encodedWord; char* encodedWord;
u32 consumedSize; u32 consumedSize;
u32 decodedLength; u32 decodedLength;
@@ -548,7 +580,6 @@ static NWC24Err DecodeWord(char* charsetData, u32 charsetCapacity, char* decoded
if (encodedSizeOut != NULL) { *encodedSizeOut = 0; } if (encodedSizeOut != NULL) { *encodedSizeOut = 0; }
encodedWord = FindMarker(encoded, encodedSize, "=?"); encodedWord = FindMarker(encoded, encodedSize, "=?");
if (encodedWord == encoded) { if (encodedWord == encoded) {
char encoding;
result = ExtractCharset(charsetData, charsetCapacity, &consumedSize, encodedWord, encodedSize); result = ExtractCharset(charsetData, charsetCapacity, &consumedSize, encodedWord, encodedSize);
if (result != NWC24_OK) { return result; } if (result != NWC24_OK) { return result; }
encodedLength = consumedSize; encodedLength = consumedSize;
@@ -574,15 +605,7 @@ static NWC24Err DecodeWord(char* charsetData, u32 charsetCapacity, char* decoded
} }
decodedLength = localSize; decodedLength = localSize;
if (encodedWord != NULL) { if (encodedWord != NULL) {
BOOL whitespaceOnly = TRUE; if (IsLinearWhitespaceOnly(decoded, localSize)) {
u32 offset;
for (offset = 0; offset < localSize && decoded[offset] != '\0'; offset++) {
char value = decoded[offset];
if (value != ' ' && value != '\t' && value != '\r' && value != '\n') {
whitespaceOnly = FALSE;
}
}
if (whitespaceOnly) {
*decoded = '\0'; *decoded = '\0';
decodedLength = 1; decodedLength = 1;
} }
@@ -695,8 +718,9 @@ static NWC24Err ExtractCharset(char* charset, u32 charsetCapacity, u32* charsetS
return NWC24_OK; return NWC24_OK;
} }
static inline char* FindMarkerOffsetPrefix(char* input, u32 size, u32 prefix, const char* marker) { static inline char* FindMarkerOffsetPrefix(char* input, u32 size, u32 prefix, const char* marker) {
u32 markerLength = Mail_strlen(marker);
u32 offset; u32 offset;
u32 markerLength;
markerLength = Mail_strlen(marker);
for (offset = 0; offset <= size; offset++) { for (offset = 0; offset <= size; offset++) {
if (Mail_strncmp(input + offset + prefix, marker, markerLength) == 0) { if (Mail_strncmp(input + offset + prefix, marker, markerLength) == 0) {
return input + prefix + offset; return input + prefix + offset;

View File

@@ -202,33 +202,40 @@ static inline NWC24Err WriteMBNoReplyField(NWC24MsgObjPrivate* msg) {
return err; return err;
} }
static inline NWC24Err WriteMBRegDateField(NWC24MsgObjPrivate* msg, u32 flags) { typedef struct {
u32 flags;
char* buffer;
} MBFieldWork;
static inline NWC24Err WriteMBRegDateField(NWC24MsgObjPrivate* msg) {
MBFieldWork field;
NWC24Err err; NWC24Err err;
s32 length; s32 length;
char* buffer; field.flags = msg->msgBoardFlags.raw & 0xFFFF;
if (!flags) if (!field.flags)
return NWC24_OK; return NWC24_OK;
buffer = NWC24WorkP->stringWork; field.buffer = NWC24WorkP->stringWork;
Mail_memset(buffer, 0, 1024); Mail_memset(field.buffer, 0, 1024);
Mail_sprintf(buffer, "X-Wii-MB-RegDate: %04X\r\n", flags); Mail_sprintf(field.buffer, "X-Wii-MB-RegDate: %04X\r\n", field.flags);
length = STD_strnlen(buffer, 1024); length = STD_strnlen(field.buffer, 1024);
err = NWC24FWrite(buffer, length, m_pFile); err = NWC24FWrite(field.buffer, length, m_pFile);
if (err == NWC24_OK) if (err == NWC24_OK)
msg->length += length; msg->length += length;
return err; return err;
} }
static inline NWC24Err WriteMBDelayField(NWC24MsgObjPrivate* msg, u32 flags) { static inline NWC24Err WriteMBDelayField(NWC24MsgObjPrivate* msg) {
MBFieldWork field;
NWC24Err err; NWC24Err err;
s32 length; s32 length;
char* buffer; field.flags = msg->msgBoardFlags.raw & 0xFF0000;
if (!flags) if (!field.flags)
return NWC24_OK; return NWC24_OK;
buffer = NWC24WorkP->stringWork; field.buffer = NWC24WorkP->stringWork;
Mail_memset(buffer, 0, 1024); Mail_memset(field.buffer, 0, 1024);
Mail_sprintf(buffer, "X-Wii-MB-Delay: %02X\r\n", flags >> 16); Mail_sprintf(field.buffer, "X-Wii-MB-Delay: %02X\r\n", field.flags >> 16);
length = STD_strnlen(buffer, 1024); length = STD_strnlen(field.buffer, 1024);
err = NWC24FWrite(buffer, length, m_pFile); err = NWC24FWrite(field.buffer, length, m_pFile);
if (err == NWC24_OK) if (err == NWC24_OK)
msg->length += length; msg->length += length;
return err; return err;
@@ -236,11 +243,11 @@ static inline NWC24Err WriteMBDelayField(NWC24MsgObjPrivate* msg, u32 flags) {
static inline NWC24Err WriteExtraFields(NWC24MsgObjPrivate* msg) { static inline NWC24Err WriteExtraFields(NWC24MsgObjPrivate* msg) {
NWC24Err err; NWC24Err err;
if (msg->unk_0xD0.size == 0) if (msg->extraData.size == 0)
return NWC24_OK; return NWC24_OK;
err = NWC24FWrite(msg->unk_0xD0.ptr, msg->unk_0xD0.size, m_pFile); err = NWC24FWrite(msg->extraData.ptr, msg->extraData.size, m_pFile);
if (err == NWC24_OK) if (err == NWC24_OK)
msg->length += msg->unk_0xD0.size; msg->length += msg->extraData.size;
return err; return err;
} }
@@ -306,8 +313,8 @@ static NWC24Err NWC24CommitMsgInternal(NWC24MsgObjPrivate* msg, NWC24MBoxType ty
CHECK_WRITE(WriteIconNewField(msg)); CHECK_WRITE(WriteIconNewField(msg));
if (msg->msgBoardFlags.raw != 0) { if (msg->msgBoardFlags.raw != 0) {
CHECK_WRITE(WriteMBNoReplyField(msg)); CHECK_WRITE(WriteMBNoReplyField(msg));
{ u16 dateFlags = msg->msgBoardFlags.raw; CHECK_WRITE(WriteMBRegDateField(msg, dateFlags)); } CHECK_WRITE(WriteMBRegDateField(msg));
CHECK_WRITE(WriteMBDelayField(msg, msg->msgBoardFlags.raw & 0xFF0000)); CHECK_WRITE(WriteMBDelayField(msg));
} }
} }
CHECK_WRITE(WriteExtraFields(msg)); CHECK_WRITE(WriteExtraFields(msg));
@@ -323,7 +330,7 @@ static NWC24Err NWC24CommitMsgInternal(NWC24MsgObjPrivate* msg, NWC24MBoxType ty
} }
CHECK_WRITE(WriteString(msg, buffer)); CHECK_WRITE(WriteString(msg, buffer));
if (msg->type & 0x10000) { if (msg->type & 0x10000) {
msg->unk_0x10 = msg->length; msg->headerSize = msg->length;
buffer = NWC24WorkP->stringWork; buffer = NWC24WorkP->stringWork;
Mail_memset(buffer, 0, 1024); Mail_memset(buffer, 0, 1024);
Mail_sprintf(buffer, "\r\n--%s", MultiPartDivider); Mail_sprintf(buffer, "\r\n--%s", MultiPartDivider);
@@ -332,7 +339,7 @@ static NWC24Err NWC24CommitMsgInternal(NWC24MsgObjPrivate* msg, NWC24MBoxType ty
} }
CHECK_WRITE(WriteContentTypeField(msg)); CHECK_WRITE(WriteContentTypeField(msg));
if (!(msg->type & 0x10000)) if (!(msg->type & 0x10000))
msg->unk_0x10 = msg->length; msg->headerSize = msg->length;
text.ptr = (const void*)msg->length; text.ptr = (const void*)msg->length;
{ NWC24Err textResult = WritePlainText(msg); { NWC24Err textResult = WritePlainText(msg);
err = textResult == NWC24_ERR_NULL ? NWC24_OK : textResult; } err = textResult == NWC24_ERR_NULL ? NWC24_OK : textResult; }
@@ -423,14 +430,17 @@ static NWC24Err CheckMsgObject(const NWC24MsgObjPrivate* msg) {
return NWC24_OK; return NWC24_OK;
} }
static inline u32 Base64StorageSize(const u32* byteCount) {
return (*byteCount * 4 + 2) / 3 + *byteCount / 57 * 2 + 4;
}
static NWC24Err CheckMsgBoxSpace(const NWC24MsgObjPrivate* msg, NWC24MBoxType type) { static NWC24Err CheckMsgBoxSpace(const NWC24MsgObjPrivate* msg, NWC24MBoxType type) {
u32 total = 0; u32 total = 0;
u32 textSize = 0; u32 textSize = 0;
s32 index; s32 index;
NWC24Err err; NWC24Err err;
for (index = 0; index < msg->numAttached; ++index) { for (index = 0; index < msg->numAttached; ++index) {
u32 size = msg->attachedSize[index]; total += Base64StorageSize(&msg->attachedSize[index]);
total += (size * 4 + 2) / 3 + size / 57 * 2 + 4;
} }
switch (msg->encoding) { switch (msg->encoding) {
case NWC24_ENC_7BIT: case NWC24_ENC_7BIT:
@@ -567,7 +577,7 @@ static NWC24Err WriteFromField(NWC24MsgObjPrivate* msg) {
Mail_memset(buffer, 0, 1024); Mail_memset(buffer, 0, 1024);
Mail_strncat(buffer, "From: ", 1022); Mail_strncat(buffer, "From: ", 1022);
address = buffer + 6; address = buffer + 6;
msg->unk_0x30.ptr = (const void*)(msg->length + 6); msg->fromData.ptr = (const void*)(msg->length + 6);
type = 1; type = 1;
if (msg->type & 0x100000) if (msg->type & 0x100000)
type = 2; type = 2;
@@ -586,7 +596,7 @@ static NWC24Err WriteFromField(NWC24MsgObjPrivate* msg) {
err = NWC24FWrite(NWC24WorkP->stringWork, total, m_pFile); err = NWC24FWrite(NWC24WorkP->stringWork, total, m_pFile);
if (err == NWC24_OK) { if (err == NWC24_OK) {
msg->length += total; msg->length += total;
msg->unk_0x30.size = msg->length - (u32)msg->unk_0x30.ptr - 2; msg->fromData.size = msg->length - (u32)msg->fromData.ptr - 2;
} }
} }
return err; return err;
@@ -602,7 +612,7 @@ static NWC24Err WriteToField(NWC24MsgObjPrivate* msg) {
cursor += 4; cursor += 4;
index = 0; index = 0;
total = 4; total = 4;
msg->unk_0x38.ptr = (const void*)(msg->length + 4); msg->toData.ptr = (const void*)(msg->length + 4);
remaining = 1018; remaining = 1018;
for (; index < msg->numTo; ++index) { for (; index < msg->numTo; ++index) {
err = SynthesizeAddrStr(&msg->toAddrs[index], msg->type, cursor, remaining, &length); err = SynthesizeAddrStr(&msg->toAddrs[index], msg->type, cursor, remaining, &length);
@@ -631,7 +641,7 @@ static NWC24Err WriteToField(NWC24MsgObjPrivate* msg) {
err = NWC24FWrite(NWC24WorkP->stringWork, total + 2, m_pFile); err = NWC24FWrite(NWC24WorkP->stringWork, total + 2, m_pFile);
if (err == NWC24_OK) { if (err == NWC24_OK) {
msg->length += total + 2; msg->length += total + 2;
msg->unk_0x38.size = msg->length - (u32)msg->unk_0x38.ptr - 2; msg->toData.size = msg->length - (u32)msg->toData.ptr - 2;
} }
} }
return err; return err;
@@ -759,19 +769,14 @@ static NWC24Err WriteMIMEAttachHeader(NWC24MsgObjPrivate* msg, u32 index) {
char* buffer; char* buffer;
const char* mime; const char* mime;
const char* suffix; const char* suffix;
s32 typeLength, encodingLength, dispositionLength, mimeLength; int mimeLength;
s32 first, second, third, total; s32 first, second, third, total;
NWC24Err err; NWC24Err err;
Mail_memset(NWC24WorkP->stringWork, 0, 1024); Mail_memset(NWC24WorkP->stringWork, 0, 1024);
buffer = NWC24WorkP->stringWork; buffer = NWC24WorkP->stringWork;
mime = NWC24GetMIMETypeStr(msg->attachedType[index]); mime = NWC24GetMIMETypeStr(msg->attachedType[index]);
suffix = NWC24iGetMIMETypeSuffix(msg->attachedType[index]); suffix = NWC24iGetMIMETypeSuffix(msg->attachedType[index]);
encodingLength = Mail_strlen(ContentTxEncA); mimeLength = (Mail_strlen(ContentTypeA) + Mail_strlen(ContentTxEncA)) + Mail_strlen(ContentDispA) + Mail_strlen(mime) + 4;
typeLength = Mail_strlen(ContentTypeA);
dispositionLength = Mail_strlen(ContentDispA);
typeLength += encodingLength;
mimeLength = Mail_strlen(mime);
mimeLength = (dispositionLength + typeLength) + mimeLength + 4;
if (mimeLength >= 1024) if (mimeLength >= 1024)
return NWC24_ERR_NOMEM; return NWC24_ERR_NOMEM;
first = Mail_sprintf(buffer, (char*)ContentTypeA, mime, (char)('a' + index), msg->msgId, suffix); first = Mail_sprintf(buffer, (char*)ContentTypeA, mime, (char)('a' + index), msg->msgId, suffix);

View File

@@ -73,11 +73,11 @@ NWC24Err NWC24InitMsgObj(NWC24MsgObj* msg, NWC24MsgType type) {
msgObj->attachedType[i] = NWC24_TEXT_PLAIN; msgObj->attachedType[i] = NWC24_TEXT_PLAIN;
} }
NWC24Data_Init(&msgObj->unk_0x30); NWC24Data_Init(&msgObj->fromData);
NWC24Data_Init(&msgObj->unk_0x38); NWC24Data_Init(&msgObj->toData);
NWC24Data_Init(&msgObj->unk_0x50); NWC24Data_Init(&msgObj->unk_0x50);
NWC24Data_Init(&msgObj->unk_0x58); NWC24Data_Init(&msgObj->unk_0x58);
NWC24Data_Init(&msgObj->unk_0xD0); NWC24Data_Init(&msgObj->extraData);
NWC24Data_Init(&msgObj->faceData); NWC24Data_Init(&msgObj->faceData);
NWC24Data_Init(&msgObj->altName); NWC24Data_Init(&msgObj->altName);

View File

@@ -19,7 +19,7 @@ static inline NWC24Err SelectMBox(const NWC24MsgObjPrivate* msg, NWC24MBoxType*
} }
NWC24Err NWC24ReadMsgField(const NWC24MsgObj* msg, char* fieldName, u8* output, u32 capacity) { NWC24Err NWC24ReadMsgField(const NWC24MsgObj* msg, char* fieldName, u8* output, u32 capacity) {
const NWC24MsgObjPrivate* privateMsg = (const NWC24MsgObjPrivate*)msg; NWC24MsgObjPrivate* privateMsg = (NWC24MsgObjPrivate*)msg;
NWC24File file; NWC24File file;
NWC24FileStream stream; NWC24FileStream stream;
char* field; char* field;
@@ -268,7 +268,7 @@ NWC24Err NWC24ReadMsgMBOptOutFlag(const NWC24MsgObj* msg, BOOL* optOut, u32* app
} }
NWC24Err NWC24ReadMsgFromAddr(const NWC24MsgObj* msg, char* address, u32 capacity) { NWC24Err NWC24ReadMsgFromAddr(const NWC24MsgObj* msg, char* address, u32 capacity) {
const NWC24MsgObjPrivate* privateMsg = (const NWC24MsgObjPrivate*)msg; NWC24MsgObjPrivate* privateMsg = (NWC24MsgObjPrivate*)msg;
NWC24MBoxType type; NWC24MBoxType type;
NWC24File file; NWC24File file;
NWC24FileStream stream; NWC24FileStream stream;
@@ -289,7 +289,7 @@ NWC24Err NWC24ReadMsgFromAddr(const NWC24MsgObj* msg, char* address, u32 capacit
default: default:
return result; return result;
} }
if (privateMsg->unk_0x30.size == 0) if (privateMsg->fromData.size == 0)
return NWC24_ERR_NULL; return NWC24_ERR_NULL;
result = NWC24iMBoxOpenStoredMsg(type, privateMsg->msgId, &file); result = NWC24iMBoxOpenStoredMsg(type, privateMsg->msgId, &file);
switch (result) { switch (result) {
@@ -300,9 +300,9 @@ NWC24Err NWC24ReadMsgFromAddr(const NWC24MsgObj* msg, char* address, u32 capacit
} }
result = NWC24FStreamInit(&stream, &file, 0, privateMsg->length, buffer, 1024); result = NWC24FStreamInit(&stream, &file, 0, privateMsg->length, buffer, 1024);
if (result == NWC24_OK) { if (result == NWC24_OK) {
result = NWC24FStreamSeek(&stream, (u32)privateMsg->unk_0x30.ptr); result = NWC24FStreamSeek(&stream, (u32)privateMsg->fromData.ptr);
if (result == NWC24_OK) if (result == NWC24_OK)
result = NWC24iExtractAddrSpec(&stream, privateMsg->unk_0x30.size, 0, address, capacity); result = NWC24iExtractAddrSpec(&stream, privateMsg->fromData.size, 0, address, capacity);
} }
closeResult = NWC24iMBoxCloseMsg(&file); closeResult = NWC24iMBoxCloseMsg(&file);
if (result != NWC24_OK) if (result != NWC24_OK)
@@ -312,7 +312,7 @@ NWC24Err NWC24ReadMsgFromAddr(const NWC24MsgObj* msg, char* address, u32 capacit
} }
NWC24Err NWC24ReadMsgSubject(const NWC24MsgObj* msg, char* subject, u32 capacity) { NWC24Err NWC24ReadMsgSubject(const NWC24MsgObj* msg, char* subject, u32 capacity) {
const NWC24MsgObjPrivate* privateMsg = (const NWC24MsgObjPrivate*)msg; NWC24MsgObjPrivate* privateMsg = (NWC24MsgObjPrivate*)msg;
NWC24MBoxType type; NWC24MBoxType type;
NWC24File file; NWC24File file;
u32 length; u32 length;
@@ -386,14 +386,14 @@ NWC24Err NWC24ReadMsgTextEx(const NWC24MsgObj* msg, char* text, u32 capacity, ch
} }
static NWC24Err ReadMsgTextInternal(const NWC24MsgObj* msg, char* text, u32 capacity, char* charset, u32 charsetCapacity, NWC24Encoding* encoding) { static NWC24Err ReadMsgTextInternal(const NWC24MsgObj* msg, char* text, u32 capacity, char* charset, u32 charsetCapacity, NWC24Encoding* encoding) {
const NWC24MsgObjPrivate* privateMsg = (const NWC24MsgObjPrivate*)msg; u32 length;
NWC24MBoxType type; NWC24MBoxType type;
NWC24File file; NWC24File file;
NWC24Err result, closeResult; NWC24Err result, closeResult;
NWC24Err overflow = NWC24_OK; NWC24Err overflow = NWC24_OK;
u32 length;
u32 decodedSize;
char* buffer; char* buffer;
u32 decodedSize;
NWC24MsgObjPrivate* privateMsg = (NWC24MsgObjPrivate*)msg;
if (!NWC24IsMsgLibOpened() && !NWC24IsMsgLibOpenedByTool()) if (!NWC24IsMsgLibOpened() && !NWC24IsMsgLibOpenedByTool())
return NWC24_ERR_LIB_NOT_OPENED; return NWC24_ERR_LIB_NOT_OPENED;
if (!(privateMsg->type & 0x200)) if (!(privateMsg->type & 0x200))
@@ -408,13 +408,15 @@ static NWC24Err ReadMsgTextInternal(const NWC24MsgObj* msg, char* text, u32 capa
return result; return result;
} }
length = privateMsg->textSize; length = privateMsg->textSize;
if (length == 0) switch (length) {
length = privateMsg->text.size; case 0: length = privateMsg->text.size; break;
default: break;
}
if (length == 0) if (length == 0)
return NWC24_ERR_NULL; return NWC24_ERR_NULL;
if (length > capacity - 1) { if (length > capacity - 1) {
overflow = NWC24_ERR_OVERFLOW;
length = capacity - 1; length = capacity - 1;
overflow = NWC24_ERR_OVERFLOW;
} }
result = NWC24iMBoxOpenStoredMsg(type, privateMsg->msgId, &file); result = NWC24iMBoxOpenStoredMsg(type, privateMsg->msgId, &file);
switch (result) { switch (result) {
@@ -450,13 +452,16 @@ static NWC24Err ReadMsgTextInternal(const NWC24MsgObj* msg, char* text, u32 capa
result = NWC24FRead(text, length, &file); result = NWC24FRead(text, length, &file);
text[length] = 0; text[length] = 0;
break; break;
case 2: case 2: {
NWC24Err decodeResult;
decodedSize = 0; decodedSize = 0;
result = ReadBase64Data(&file, &privateMsg->text, (u8*)text, length, &decodedSize); decodeResult = ReadBase64Data(&file, &privateMsg->text, (u8*)text, length, &decodedSize);
if (result == NWC24_OK && decodedSize != privateMsg->textSize) if (decodeResult == NWC24_OK && decodedSize != privateMsg->textSize)
result = NWC24_ERR_FORMAT; decodeResult = NWC24_ERR_FORMAT;
result = decodeResult;
text[length] = 0; text[length] = 0;
break; break;
}
case 3: case 3:
result = ReadQPText(privateMsg, &file, text, length); result = ReadQPText(privateMsg, &file, text, length);
break; break;
@@ -468,15 +473,15 @@ static NWC24Err ReadMsgTextInternal(const NWC24MsgObj* msg, char* text, u32 capa
} }
close: close:
closeResult = NWC24iMBoxCloseMsg(&file); closeResult = NWC24iMBoxCloseMsg(&file);
if (result == NWC24_OK) if (result != NWC24_OK)
result = closeResult; closeResult = result;
if (result == NWC24_OK) if (closeResult != NWC24_OK)
result = overflow; overflow = closeResult;
return result; return overflow;
} }
NWC24Err NWC24ReadMsgAttached(const NWC24MsgObj* msg, u32 index, u8* output, u32 capacity) { NWC24Err NWC24ReadMsgAttached(const NWC24MsgObj* msg, u32 index, u8* output, u32 capacity) {
const NWC24MsgObjPrivate* privateMsg = (const NWC24MsgObjPrivate*)msg; NWC24MsgObjPrivate* privateMsg = (NWC24MsgObjPrivate*)msg;
NWC24File file; NWC24File file;
NWC24MBoxType type; NWC24MBoxType type;
u32 decodedSize; u32 decodedSize;
@@ -505,11 +510,8 @@ NWC24Err NWC24ReadMsgAttached(const NWC24MsgObj* msg, u32 index, u8* output, u32
} }
decodedSize = 0; decodedSize = 0;
result = ReadBase64Data(&file, &privateMsg->attached[index], output, capacity, &decodedSize); result = ReadBase64Data(&file, &privateMsg->attached[index], output, capacity, &decodedSize);
switch (result) { if (result == NWC24_OK) {
case NWC24_OK: if (decodedSize != ((const NWC24MsgObjPrivate*)msg)->attachedSize[index]) result = NWC24_ERR_FORMAT;
if (decodedSize != privateMsg->attachedSize[index]) { result = NWC24_ERR_FORMAT; }
break;
default: break;
} }
closeResult = NWC24iMBoxCloseMsg(&file); closeResult = NWC24iMBoxCloseMsg(&file);
if (result == NWC24_OK) if (result == NWC24_OK)

Some files were not shown because too many files have changed in this diff Show More