Compare commits

...

26 Commits

Author SHA1 Message Date
coah
a306fae5c9 chore: remove agent handoff material now that the decompilation is complete (#1379) 2026-10-09 15:49:55 -05:00
coah
6941513d15 cleanup(nup,revoex,sdk): names, gotos, volatile and unused pragmas (worker 1262edba) (#1378) 2026-10-09 15:03:53 -05:00
coah
ea0d6a66d0 cleanup(ezitext): structure 54 decompiler gotos, drop volatile locals (worker 8017758e) (#1377) 2026-10-09 14:55:50 -05:00
coah
a764ab3331 cleanup(chansvm): typed buffers and names (worker 4b37bd69) (#1376) 2026-10-09 14:54:26 -05:00
coah
3b4748da31 cleanup(system,aoss,aterm): AOSS gotos, unused locals, content-count names (worker a6f4c4b7) (#1375) 2026-10-09 14:53:01 -05:00
coah
42edf4032b cleanup(system,scene,bs2): drop volatile casts and decompiler gotos (worker aaadedee) (#1374) 2026-10-09 14:51:33 -05:00
coah
112de090e3 cleanup(bte): split chained assignments, drop inactive config defaults (worker fd3ae621) (#1373) 2026-10-09 14:49:57 -05:00
coah
a2c1cf9c2c cleanup(sdk): wad/fs/usb/ipc/sc/es names, gotos and redundant initializers (worker 0e11525f) (#1372) 2026-10-09 14:48:33 -05:00
coah
f7a0d5b746 cleanup(jpeg): name TMC_JPEG fields and decoder parameters (worker e0c6e69a) (#1371) 2026-10-09 14:45:38 -05:00
coah
8a67b68cf2 docs(agents): record completion state and cleanup-phase policy (#1370) 2026-10-09 14:29:33 -05:00
coah
04d3d1e87d decomp(jpeg): TMCJPEGDEC_err_restart in C (last asm placeholder removed) (worker 25aed309) (#1369) 2026-10-09 14:28:11 -05:00
coah
7a44876cbd decomp(system): warning_run in C (asm placeholder removed) (worker d00a2f20) (#1368) 2026-10-09 14:19:16 -05:00
coah
c628bab36c cleanup(nandsd,esmisc): structured control flow replaces decompiler gotos (worker 76b2d600) (#1367) 2026-10-09 13:27:35 -05:00
coah
ed6f7f6fa5 decomp(cntcache): CNTCACHEClear in C (asm placeholder removed) (worker f91deefd) (#1366) 2026-10-09 13:22:41 -05:00
coah
be309e8f72 cleanup: bannerSound, homebutton, iplwww, layout, sound (worker 70f270c3) (#1365) 2026-10-09 13:16:33 -05:00
coah
f0b3637abe cleanup: RVL SDK (gotos, comma conditions, placeholders) (worker 389d53b9) (#1364) 2026-10-09 13:15:20 -05:00
coah
bc3fd4fe0b cleanup: cleanup2-x8 (gotos, comma conditions, placeholders) (worker cd20e275) (#1363) 2026-10-09 13:13:55 -05:00
coah
f6280e83d3 cleanup: cleanup2-x7 (gotos, comma conditions, placeholders) (worker a2251cc4) (#1362) 2026-10-09 13:12:42 -05:00
coah
c1867e6aa8 cleanup: cleanup2-x9 (gotos, comma conditions, placeholders) (worker a40ed3aa) (#1361) 2026-10-09 13:11:29 -05:00
coah
8f655e0ff6 cleanup: RevoEX (gotos, comma conditions, placeholders) (worker 907584d0) (#1360) 2026-10-09 13:10:05 -05:00
coah
c8b2789812 cleanup: name placeholder struct members in headers (worker 6bc18d30) (#1359) 2026-10-09 13:08:40 -05:00
coah
bdf061817b cleanup(bte): name HCI/UUSB vendorId productId taskId (from #940) (worker 2a498b56) (#1358) 2026-10-09 13:06:20 -05:00
coah
59961aa6a4 fix(jpeg): subtract the column in restart fallback result (#1355) 2026-10-09 13:03:50 -05:00
coah
5ee2a2ee3a cleanup: eZiText (gotos, comma conditions) (worker 0c4d6a91) (#1357) 2026-10-09 13:02:35 -05:00
coah
ec965ad591 cleanup: Bluetooth stack (BTE names, comma conditions) (worker 654140d7) (#1356) 2026-10-09 13:00:42 -05:00
coah
d14d33d0b5 cleanup: src/system and src/utility (gotos, comma conditions, placeholders) (worker 223c077f) (#1354) 2026-10-09 12:59:15 -05:00
882 changed files with 5233 additions and 303460 deletions

View File

@@ -1,21 +0,0 @@
MIT License
Copyright (c) 2026 TypeSafe AI
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,149 +0,0 @@
---
name: typesafe-ai
license: MIT
description: >
Build AI-powered software with TypeSafe: small units of AI intelligence you
can use like programming primitives. Its System One models, including Jev,
turn natural language and application state into typed judgments and
probabilities that code can combine. Use when a feature needs programmable
common sense, when brainstorming what AI could make possible in an app, or
when an LLM prompt-and-parse step could become a structured decision.
Applications include routing, ranking, extraction, verification, and
interactive experiences; these are starting points, not the limits.
Read live docs and cookbooks to find useful patterns and discover new combinations.
---
# Build with TypeSafe
TypeSafe makes units of AI intelligence usable like programming primitives: small
judgments you can compose into larger capabilities. Its **System One models** return
fast, focused judgments that software can consume directly. **Jev** is TypeSafe's
flagship and first System One model. It understands natural language and returns
typed answers and probabilities rather
than generating text or reasoning explanations. Code owns the workflow; the model
supplies programmable common sense where ordinary code needs semantic understanding.
## Read the live docs
**The live TypeSafe docs are the source of truth. Read them as part of the task.**
This skill gives direction; the docs carry current concepts, prompting guidance,
API contracts, SDK usage, models, limits, and worked examples.
- Start with the [documentation index](https://docs.typesafe.ai/llms.txt) to discover
relevant pages and cookbooks. Use targeted reads rather than loading the entire site.
- Mintlify serves Markdown by appending `.md` to a page path, for example
[how to build with TypeSafe](https://docs.typesafe.ai/concepts/how-to-build-with-system-one.md).
Follow links from the index; convert extensionless documentation page links to
`.md` when useful. Resolve relative links against `https://docs.typesafe.ai`.
- Before writing an integration, read the current API or chosen SDK page and the
question guidance relevant to the design. For a new workflow, also inspect the
closest cookbook: it often shows a better decomposition than a generic classifier.
- If the index is unavailable, use the direct links below or the site's navigation.
If Markdown fetching fails, try the normal page. If live access is unavailable,
use available local docs or installed SDK types, state that limitation, and avoid
inventing version-dependent details.
| Task | Start here; follow the relevant details |
| --- | --- |
| Understand the programming model | [System One](https://docs.typesafe.ai/concepts/system-one.md), [building guide](https://docs.typesafe.ai/concepts/how-to-build-with-system-one.md) |
| Explore what to build | [Use-case map](https://docs.typesafe.ai/concepts/use-case-map.md), then relevant cookbooks from the index |
| Prepare inputs and questions | [State](https://docs.typesafe.ai/concepts/state.md), [primitives](https://docs.typesafe.ai/primitives.md), then the chosen primitive's page |
| Decide how to handle uncertainty | [Confidence](https://docs.typesafe.ai/confidence.md) |
| Write API code | [HTTP API](https://docs.typesafe.ai/api.md), [Python SDK](https://docs.typesafe.ai/sdk/python.md), or [JavaScript SDK](https://docs.typesafe.ai/sdk/javascript.md) |
| Update an older integration | [Migration guide](https://docs.typesafe.ai/migrating-to-v1.md) and the installed SDK's current reference |
## Find the useful shape
Start from the behavior the user wants: what will the application show, select,
change, or hand off? Work backward to the judgments it needs. Keep known rules,
calculations, exact lookups, and execution in code. Preserve the user's chosen stack
and scope; add TypeSafe where semantic understanding helps.
When brainstorming or choosing an architecture, consider more than classification.
The patterns below are starting points: combine primitives around the user's goal,
including ideas that do not fit an established recipe.
- **Route and fill known arguments.** A request can select a handler and its typed
parameters. Ask useful branch-specific questions up front and consume only the
relevant answers. Explore [function calling](https://docs.typesafe.ai/cookbooks/function_calling.md)
and [speculative fan-out](https://docs.typesafe.ai/patterns/fan-out.md).
- **Select instead of generate.** Find candidate values or source spans in code,
use a judgment to select the intended one, then copy or normalize it. Code can
also assemble source text into a formatted document or reading guide. Explore
[value extraction](https://docs.typesafe.ai/cookbooks/pre_parsed_value_extraction_cookbook.md)
and [structure recovery](https://docs.typesafe.ai/cookbooks/autoformat.md).
- **Find and judge evidence.** Retrieve candidates, compare their relevance to a
query, and select useful context. Explore [reranking](https://docs.typesafe.ai/cookbooks/rerank_typesafe.md)
and [hierarchical classification](https://docs.typesafe.ai/cookbooks/hierarchical_classification.md).
- **Turn judgments into reusable data.** Score dimensions once, then let code or
user controls change weights, thresholds, rankings, and views. With labeled
outcomes, those signals can become classical ML features. Explore
[composite scoring](https://docs.typesafe.ai/patterns/composite-scoring.md) and
[feature discovery](https://docs.typesafe.ai/cookbooks/autoresearch_feature_discovery.md).
- **Verify and escalate.** Check specific claims or fields against their evidence;
send uncertain or failing cases to a person or reasoning model. Explore
[citation checks](https://docs.typesafe.ai/cookbooks/citation_check.md) and
[extraction cascades](https://docs.typesafe.ai/cookbooks/sde_cascade.md).
- **Respond to changing state.** Code can retain goals and observations while fresh
judgments guide the next bounded step. Keep inferred state distinct from observed
facts, and check freshness before applying a result to a changed situation.
For open-ended requests, offer the few directions that best serve the user's goal
and recommend a starting point. For a concrete request, choose the relevant pattern
and build; a brainstorm is not a mandatory detour.
## Design the judgments
Choose by what the answer means, then read the relevant primitive page:
| Need | Primitive | Important distinction |
| --- | --- | --- |
| One of a defined set | [Choice](https://docs.typesafe.ai/primitives/choice.md) | Picks one option; its distribution compares competing options |
| Whether a condition holds | [Noul](https://docs.typesafe.ai/primitives/noul.md) | Probability of yes; no separate confidence; use one per label when several may apply |
| Degree along a described dimension | [Score](https://docs.typesafe.ai/primitives/score.md) | Probability-weighted position on ordered levels; use comparable per-item Scores for graded ranking |
Give each question enough relevant **state** to answer: source text, identities,
relationships, policies, and current facts. Prefer named JSON fields when context
has several parts. Put the judgment in **instructions** and define its possible
answers in **criteria**. Question IDs are for code and are not sent to the model;
include complete meaning in the question. Reference nested state with backticked
paths such as `ticket.messages[0].text`.
Ask one narrow, coherent judgment per question. Split independently useful dimensions,
without destroying the relationship being judged. A bounded action selection or
contextual interpretation is valid; atomic does not mean literal fact extraction
or a one-sentence limit. Strings work for simple questions. Use structured objects
or arrays when definitions, contrasts, exclusions, or examples clarify instructions
or criteria. Score levels must describe concrete situations and stand on their own.
Keep the needed answers available. Include a no-match outcome when nothing may fit;
use a separate presence judgment when it is independently useful. For source-value
selection, check candidate coverage: the model cannot choose an omitted value.
## Compose and verify
**Ask independent questions over the same state together**, including useful
speculative questions. They run in parallel and cannot see one another's answers.
State each speculative premise explicitly; code consumes the applicable answers.
A second request is warranted when an earlier answer is needed to fetch evidence,
construct new state, or determine the next options. Extra questions still use tokens;
measure actual request budgets, cost, and end-to-end latency.
Use probabilities and confidence to guide behavior, with thresholds evaluated on
the user's data and consequences. Choice/Score confidence summarizes distribution
concentration, not overall workflow correctness or permission to act. A Noul near
0.5 means similar probability for yes and no, not medium intensity. Several
acceptable alternatives can also spread probability; low confidence need not
invalidate a harmless preference choice. Ignore uncertainty on unused branches.
Keep policy explicit and raw judgments reusable. Weighted scores suit compensating
preferences; an “any serious violation” rule needs separate conditions. Changing a
weight or display filter need not rerun inference when evidence and question meanings
are unchanged. Typed output guarantees the interface, not truth. System One models
are trained for calibrated decisions; validate their performance in the target domain.
Test representative cases and the resulting application behavior. For failures,
inspect the exact state, questions, candidates, answers, composition, and observed
outcome. Separate missing evidence, model errors, code errors, and service failures.
Treat cookbook thresholds and demo results as examples to evaluate, not universal
rules or permanent model limitations. Keep API credentials server-side in web apps.

View File

@@ -1 +0,0 @@
../../.agents/skills/typesafe-ai

538
AGENTS.md
View File

@@ -1,536 +1,26 @@
# AGENTS.md
Guidance for AI agents working in this repository.
The Wii Menu 4.3U decompilation is finished: every unit matches and links, and
the build reproduces the retail DOL. There is no matching, linking or cleanup
work left to continue. Work only on what the user asks for.
Keep code comments to cases where they are necessary.
## Never touch upstream
## CRITICAL RULE: never touch upstream
Do not push to, open pull requests or issues against, or comment on
`koopthekoopa/wii-ipl`. Its maintainers do not want AI-authored work. `origin`
(`coah80/wii-ipl`) is this fork; `upstream` has its push URL set to
`DISABLED_never_push_to_upstream` on purpose. Never pass
`--repo koopthekoopa/wii-ipl` to `gh`.
**Do not open a pull request against `koopthekoopa/wii-ipl`. Do not push to it.
Do not open issues on it. Do not comment on it. Never. Not once.**
## Keep the build matching
The upstream maintainers do not want AI-authored commits in their history. This
fork exists solely so that AI-assisted matching work has somewhere to live
without disturbing them. Breaking this rule is worse than producing no matches
at all.
Concretely:
- `origin` is this fork, `coah80/wii-ipl`. Only the orchestrator pushes
validated leaf branches here.
- `upstream` is `koopthekoopa/wii-ipl`. Its push URL is intentionally set to
the sentinel `DISABLED_never_push_to_upstream` so an accidental
`git push upstream` fails instead of uploading.
- Never run `gh pr create` with an upstream base, and never pass
`--repo koopthekoopa/wii-ipl` to any `gh` command.
- If a task appears to require contacting upstream, stop and ask the human.
If you are reading this because you are about to open a PR against upstream:
don't. PRs for validated leaf branches belong only to this fork.
## What this repository is
A matching decompilation of the Wii Menu (system menu) 4.3U. "Matching" means
the compiled output must be byte-identical to the original binary, not merely
functionally equivalent. Correct behaviour that compiles to different assembly
is a failure.
## Build and verify
Any source change must keep the output byte-identical:
```
python3 configure.py --version 43U
ninja
sha1sum build/43U/main.dol # 26116613f624061ba99c8d1a299aaa6efa85670d
```
Ninja lives at `/home/cole/projects/tests/.venv/bin/ninja` in the author's
environment.
The acceptance gate for any change is the DOL hash:
```
build/43U/main.dol -> 26116613f624061ba99c8d1a299aaa6efa85670d
```
Objects listed as `NonMatching` in `configure.py` are **not linked** into the
DOL. Editing a `NonMatching` translation unit cannot change the DOL hash, which
makes it safe to iterate on a partial match without breaking the build. Verify
progress against the object file instead of the DOL:
```
build/43U/src/src/<path>.o # what you just built
build/43U/obj/src/<path>.o # the original object, ground truth
```
## Tooling for measuring progress
`objdiff` scores each function:
```
build/tools/objdiff-cli report generate -p . -o report.json -f json
```
A function counts as matched only at `fuzzy_match_percent == 100.0`. Anything
below that is not a match, regardless of how good it looks.
Helper tools live in `tools/decomp-assist/`:
- `ctxdiff.py <unit> <symbol>` — compact instruction-level diff of one function
between your object and the original. This is the main iteration loop.
- `disasm_fn.py <object> <symbol>` — disassembly with relocation-resolved call
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
original, string by string. See below; this is the highest-signal tool.
- `export_pyghidra.py` — regenerates `ghidra_decomp.txt`, decompiled C for the
functions still missing.
The final completion assertion is machine-checkable:
```
python3 tools/check_decomp_complete.py build/43U/report.json \
--dol build/43U/main.dol
python3 tools/check_asm_inventory.py
```
Both checks must pass before claiming full completion. GitHub Actions runs the same
assertions when manually dispatched with `require_complete=true`.
Normal push and pull-request builds publish progress without failing on the
current incomplete state. Use the manual `require_complete=true` dispatch for
the terminal all-100% gate.
`tools/test_workflow_guards.py` exercises the completion checker, and
`tools/worktree_check.py` validates the main, leaf, and cleanup states before
integration.
## The single most useful finding: the string pool
MWCC emits a translation unit's string literals into `.data` in the order the
compiler encounters them, and the compiler encounters them in **source-token
order**, not runtime order. Every later string's offset therefore depends on
every earlier one.
This matters enormously. If a function is missing from a translation unit, or
references its strings in a different order than the original, then every
string after it lands at the wrong offset, and *every function that reads those
strings fails to match* — even functions you have not touched.
Observable evidence: `TMDFile::Open` sat at 99.92 percent purely because a
string several functions earlier was 8 bytes off. Adding the correct
`checkContentsNum` block moved it to 99.96 without touching `Open`.
**Always run `pool_diff.py` and fix the first divergence before tuning register
allocation.** It points at exactly which function block is wrong or missing.
### Which branch you write changes the pool
Because emission follows source-token order, writing
```cpp
if (cond) { A(); } else { B(); }
```
versus
```cpp
if (!cond) { B(); } else { A(); }
```
emits the strings referenced by `A` and `B` in the opposite order. This is a
free lever: if a function's codegen looks right but its strings are swapped,
invert the condition rather than restructuring the logic. It fixed both the
pool and the instruction stream for `GetValidTicketIndex` in one change.
### Missing functions must all be present
A string block cannot be partially correct. A function that is entirely absent
leaves a hole, and everything downstream is shifted. Implement functions in
**object-order** (the order their addresses appear in `config/43U/symbols.txt`
and `splits.txt`), not in whatever order looks convenient.
## Workflow that produced matches
1. Find the next missing function in object order.
2. Get its decompiled C from `ghidra_decomp.txt` (regenerate with
`export_pyghidra.py` if needed).
3. Write it as literally as possible: same order of operations, same branch
direction, same number of temporaries.
4. Insert it at the correct position in the source file.
5. Build only that object: `ninja build/43U/src/src/<path>.o`.
6. `pool_diff.py` first. Fix ordering divergences before anything else.
7. `ctxdiff.py` next. Work through the instruction diff.
8. Only then look at register allocation.
## Subagent and PR workflow
This repository targets only Wii Menu 4.3U. Do not configure or build 43E,
43J, or 43K while doing matching work.
Most workers should pursue exact matching or safe linking; assign the remainder
to decompilation. Keep every worker slot busy (currently four Codex slots; see
"Orchestrator loop" below). Fill completed slots with disjoint tasks. Never duplicate a source file or function
range. Workers return changed paths, exact objdiff measurements, and validation
results. Fuzzy-only results are not accepted.
Workers must do the work through tool calls and avoid conversational messages.
Send findings to the parent only through the collaboration tool, with concise
paths, measurements, and validation evidence. Put PR discussion on the PR when
needed. Do not send user-facing status chatter; the orchestrator follows the
reporting rule below.
### Worker loop
Workers iterate until exact-name `objdiff` reports `100.0%`. They must not stop
at a fuzzy score, push, open a PR, or merge. A local commit is fine. Compiler
tie-breaks should be reported with evidence, not hidden behind artificial
assembly or uninitialized values. Exact matching is the handoff point, not
acceptance. A candidate is incomplete until every owned code and data section
and its link metrics are 100%; matching a few functions alone is not enough.
Write new matches as readable C or C++ and keep new inline assembly out of the
source unless the existing target structure makes it unavoidable.
Worker measurements are advisory. Only a fresh orchestrator verification can
accept, push, open, or merge a candidate. Workers are persistent across
validation. After reaching a candidate result,
the worker enters a paused or awaiting-parent state while the orchestrator
performs its checks. Keep the worker handle and its leaf assignment alive. If
pool, ctxdiff, source review, or any other gate fails, send the failure evidence
back to that same worker and resume it on the same leaf. Do not discard a
near-match and silently replace it with a new worker. A worker may be closed
only after its leaf is accepted, explicitly abandoned, or the orchestrator is
stopping the entire goal. A wait timeout is not worker termination; poll the
same handle or inspect its authoritative status before taking recovery action.
The orchestrator must independently rebuild the owned object and verify:
1. `pool_diff.py` reports identical pools, with no first divergence.
2. Exact-name `objdiff` reports `100.0%` for the requested symbol.
3. `ctxdiff.py` reports `diffs 0` and identical instruction counts.
4. Unit-level code, data, function, and link measures for the owned range are
100%, including every owned section.
5. The focused source diff is minimal, readable, and free of artificial
assembly, uninitialized values, or unrelated edits.
6. The full 4.3U build passes and `build/43U/main.dol` has SHA1
`26116613f624061ba99c8d1a299aaa6efa85670d`.
If any orchestrator gate fails, do not promote, push, open a PR, or merge the
candidate. Restore it or send the same disjoint task back to its worker with
the failing evidence. Stage the candidate branch for a PR only after every
gate passes, then regenerate the live progress report before accepting the
next candidate.
For each candidate, the worker must:
1. Run `pool_diff.py` before tuning code generation.
2. Build the 43U object with `/home/cole/projects/tests/.venv/bin/ninja -C . build/43U/src/src/<path>.o`.
3. Require `objdiff` to report `100.0%` for the function and `ctxdiff.py` to report `diffs 0`.
4. Iterate until exact-name objdiff reaches `100.0%`, while preserving the
pool and source-quality requirements above.
5. Return the focused exact match to the parent agent for review. The parent
reruns every gate, runs `tools/decomp_status.py` and
`tools/check_decomp_complete.py`, and runs `/home/cole/projects/tests/.venv/bin/ninja -C . build/43U/ok`;
the worker does not push, open a PR, or merge.
The main agent reviews every worker result before accepting it. After each
accepted merge, record the new report from `build/43U/report.json` and keep
the DOL hash at `26116613f624061ba99c8d1a299aaa6efa85670d`. Never push to
`upstream`; only the fork's `origin` is in scope.
### Orchestrator ownership boundary
The orchestrator does not perform decompilation or hand-tune worker source.
All source-level reverse engineering, implementation, compiler experiments,
and match iteration belong to the persistent subagents. The orchestrator may
only select disjoint leaves, start and pause workers, resume a worker with
failure evidence, run independent verification commands, review diffs, record
wave state, commit validated leaf-branch changes, push the leaf branch, open
and merge the PR, fast-forward `origin/main`, and publish progress. If a
candidate fails validation, return it to its worker; do not fix the candidate
inline in the orchestrator.
Two exceptions, both set by the human: once a leaf has failed at `max` effort
(see the effort scale below) the orchestrator itself takes a crack at it, and
the orchestrator may finish PRs whose authors are gone (rebase, drop a
forbidden pattern, close with evidence). Record every such attempt in the
policy log, including the ones that fail.
A new thread must begin by reading this file, checking the live 43U report and
remote branch, and dispatching the worker pool. The parent must not claim a
match without fresh independent verification.
### Worktrees, branches, and PR integration
Every leaf gets its own worktree and branch created from the latest
`origin/main`, for example `agent/<wave>/<leaf>`. No two workers may share a
worktree, branch, or source file. A worker may commit locally on its leaf branch
if that is needed to preserve its exact result, but it must not push, open a PR,
or merge.
Use the repository worktree checker before integration and cleanup:
```
python3 tools/worktree_check.py main --synced
python3 tools/worktree_check.py leaf <leaf-worktree> agent/<wave>/<leaf>
python3 tools/worktree_check.py cleanup <leaf-worktree> agent/<wave>/<leaf>
```
The cleanup check is read-only. It succeeds only for a clean leaf branch that
is already an ancestor of `origin/main`; the orchestrator then performs the
explicit `git worktree remove` and local branch deletion.
After the worker reaches its handoff point, the orchestrator validates the
worker's worktree from a fresh build. If every gate passes, the orchestrator
pushes that leaf branch to the fork, opens a PR against `coah80/wii-ipl:main`,
and merges it only after the same gates are recorded in the PR. Never create a
PR against `koopthekoopa/wii-ipl`.
Merge one accepted leaf at a time. After each merge, fetch the new
`origin/main`, regenerate progress, and rebase or recreate all not-yet-merged
leaf branches before their next validation. Re-run objdiff, pool, ctxdiff, the
full build, and the DOL hash after rebasing. The PR itself is not acceptance;
the post-merge main branch is the authority.
The orchestrator may resolve mechanical branch conflicts such as unchanged
context or generated bookkeeping. It must not resolve a semantic source
conflict by inventing decompilation. Send semantic conflicts back to the same
leaf worker, resume it in its worktree, and require the full gates again. Keep
the worktree and worker handle until the leaf is merged, explicitly abandoned,
or the whole goal is stopped; clean them up only after that terminal state.
After a successful merge:
1. Confirm the PR is merged into the fork's `main` and the leaf worktree has no
uncommitted changes.
2. In the integration/main worktree, run `git fetch origin` followed by
`git merge --ff-only origin/main` (or an equivalent non-destructive fast
forward). Do not use `git reset --hard` or overwrite unrelated user work.
3. Re-run the live progress report and the full 4.3U/DOL gates on the updated
main branch.
4. Rebase each still-active leaf branch onto the new `origin/main` in its own
worktree, resolve only mechanical conflicts centrally, and send semantic
conflicts back to that leaf's worker.
5. Only after the leaf is merged, clean, and no longer needed, remove its
worktree and local branch. A failed or conflicted leaf keeps its worktree
and worker alive.
### User-facing progress reports
Keep user-facing messages to a minimum and use as few tokens as possible.
Do not send routine status updates or commentary while workers are running or
PRs are open. After each matching-work PR is merged and the live progress
report has been regenerated, send only the current linked, fuzzy, and data
percentages in this format:
```
Linked: <percent> | Fuzzy: <percent> | Data: <percent>
```
Do not report stale values, unmerged PR results, or add other text to that
update. Continue all required verification and coordination silently.
## Orchestrator loop (Claude orchestrator, Codex workers)
This is the loop currently in use. One Claude session is the orchestrator.
It does not spawn Claude subagents. All decompilation work goes to Codex CLI
workers running `gpt-6.1-sol`. The orchestrator assigns leaves, verifies,
lands, reviews outside PRs, and only decompiles by hand in the cases listed
under the ownership boundary above.
Only one orchestrator session may run at a time. If a second session resumes
the same thread (for example, the same session opened in two windows), close
one of them. Two orchestrators double-merge PRs and fight over the shared
build tree.
### Worker slots and the effort scale
Run four worker slots, each in its own worktree on a fresh branch from
`origin/main`. Every slot gets a disjoint set of three or four leaves (units),
closest-to-matching first. A slot starts at `medium` (or `low`) reasoning
effort and escalates only when a round produces no new exact function:
```
low/medium -> high -> xhigh -> max -> orchestrator attempt -> parked
```
A round that gains at least one exact function is landed, and the remaining
functions go out again at the same effort or one step up. A set that fails at
`max` goes to the orchestrator. If the orchestrator also fails, the function
is parked as a compiler tie-break with its evidence. Fill freed slots from the
live checklist right away; never leave a slot idle.
Before starting a function, a worker fetches `origin/main` and checks it is
not already matched. Outside contributors land work in parallel, and
duplicated matches waste a round.
### Silent mode for workers
Workers run unattended and must not talk. Every turn is tool calls only: no
plans, no progress notes, no summaries. Progress goes into an attempts log
file in `tools/decomp-assist/`. The only text message in a run is the final
report, at most 8-15 short lines:
- exact functions per unit, before and after;
- the final `GATE` line;
- commit hashes;
- a link to the attempts log.
Runs are audited for text messages, and any chatter is a contract
violation. Workers also must not push, open PRs, merge, rebase, touch other
worktrees, or spawn subagents.
Each worker prompt has this layout:
1. the `<task>` block (leaves, current exact counts, method, report format);
2. the shared `common.md` block with `<silent_mode>`, `<forbidden>`,
`<method>` and `<definition_of_done>`.
Resume a stalled worker on the same session with the failure evidence. Don't
replace it with a fresh one.
### Gate, landing and review
- `gate.py <unit...>` is the acceptance check for workers and for outside
PRs. It covers:
- a full 4.3U build and the DOL SHA1;
- per-unit objdiff and instruction-exact counts;
- regressions against a baseline report of `origin/main`;
- a net forbidden-pattern scan and a readability scan (auto-named
identifiers, raw `*(T*)(p + N)` offset casts).
- A function that disappears because it was renamed is not a regression,
unless the unit's exact count, code or data also drops.
- Landing a worker result builds a branch from `origin/main` with the
worker's diff, gates it, pushes it, then opens and squash-merges a PR on
the fork. After that it regenerates the checklist.
- Never run two full builds in the same build tree at once.
- Never land while the review queue is building. Both use the same
verification worktree.
Outside PRs are reviewed by a daemon. It re-runs the gate on any open PR
whose head commit changed since its last review. A PR is merged
automatically only when all of these hold:
- the PR rebases cleanly;
- the full build passes;
- the DOL hash matches;
- the gate passes, or its only failures are renamed-away functions;
- the diff adds no forbidden pattern and no `.s` file.
Everything else is reviewed by hand:
- **Conflicts:** comment asking for a rebase.
- **Forbidden patterns:** request changes with a concrete honest
alternative.
- **"Linking" by swapping in retail assembly or pinned labels:** close and
explain.
- **Proven split/ownership corrections** (relocation evidence, total data
unchanged): merge even if one unit's numbers move to its neighbour.
Policy additions learned in this loop:
- Linking a unit by building the retail `.s` instead of its C/C++ is
forbidden. "Linked" means the C/C++ itself compiles to the exact bytes.
- Definition-level `volatile` (on the field or object declaration) is allowed
when the target proves it, e.g. back-to-back reloads with no store in
between. Check that it changes no other function in the units that use it.
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
The decompilation loop does not stop after a successful wave, a convenient
near-match, or a code-only milestone. Keep dispatching and resuming workers
until the live 43U report proves all of the following:
- Code is 100.00% exact-matched, not merely fuzzy-matched.
- Code is 100.00% fully linked, with no remaining unlinked code units.
- Data is 100.00% extracted/decompiled and 100.00% fully linked.
- Every source unit and function in the 4.3U target is accounted for; no
`NonMatching`, missing, fuzzy-only, or unlinked unit remains.
- The final full build passes, the DOL hash remains correct, and the report,
object files, and linked DOL agree.
Until every condition is true and independently verified, the goal remains
active. A worker wave with zero accepted matches is a failed attempt, not a
completion condition; preserve useful workers, resume fixable leaves, and
dispatch the next disjoint batch.
## Things that do NOT work
- **Frame pragmas.** `#pragma ppc_iro_level 0` fixed exactly one function out
of roughly forty attempts and made others worse. A search across pragma
variants produced almost no movement. Do not spend time here.
- **Reverting to pristine upstream to unblock.** The unmodified upstream tree
is needed as a baseline, but it does not help you match anything.
- **Searching other forks for the missing functions.** The eleven unimplemented
`iplESMisc` functions do not exist in any of the twenty-three public forks.
## Known hard cases
Many remaining diffs are pure compiler tie-breaks — register allocation and
floating-point scheduling — with no source-level lever. If `ctxdiff.py` shows
the instruction count already matches and the surviving differences are
callee-saved register names, you are probably looking at a tie-break. Record it
and move on rather than thrashing.
## Current status
Do not copy a progress number from this file. Regenerate the live 43U report
with `ninja -C . progress build/43U/report.json`; the report and DOL hash are
the authority for current status. `iplESMisc.cpp` remains `NonMatching` and
unlinked, so work there is DOL-safe.
## Reference
`tools/decomp-assist/iplESMisc.reference.cpp` is a snapshot of `iplESMisc.cpp`
with the matching work applied, kept as a reference for the string order and
function layout that the pool depends on.
Comments in the source that name a compiler requirement mark code shaped to
match the original binary; changing it changes the bytes.

View File

@@ -1,30 +0,0 @@
# Gates: Wii Menu decompilation progress
OWNS: src/**, include/**, configure.py, GATES.md
Scope: raise the 43U Wii Menu code match from the current baseline toward 99 percent while preserving build and matching-object correctness
- [x] G0: this ledger passes structural lint
CHECK: node /home/cole/.agents/skills/unlazy/scripts/gate-lint.mjs GATES.md
EXPECT: LINT OK
EVIDENCE: LINT OK (2026-09-19)
- [ ] G1: the measured 43U matched-code percentage reaches 99 percent
CHECK: /home/cole/projects/tests/.venv/bin/ninja && build/tools/objdiff-cli report generate -p . -o /tmp/wii-ipl-goal-report.json -f json >/dev/null && python3 -c "import json; x=json.load(open('/tmp/wii-ipl-goal-report.json')); p=float(x['measures']['matched_code_percent']); assert p >= 99.0, p; print('99 percent code match passed: %.6f' % p)"
EXPECT: 99 percent code match passed
EVIDENCE: 57.463276 percent, 1721124 / 2995172 code bytes, 8736 / 12563 functions (2026-09-19); threshold not reached
- [x] G2: the complete 43U build succeeds after each matching change
CHECK: python3 configure.py --version 43U && /home/cole/projects/tests/.venv/bin/ninja && test -s build/43U/main.dol && echo 'full 43U build passed'
EXPECT: full 43U build passed
EVIDENCE: full 43U build passed after ipl::scene::ChannelTitle::draw match (2026-09-19)
- [x] G3: existing matching objects remain byte-identical to the original DOL
CHECK: python3 -c "import hashlib; p='build/43U/main.dol'; h=hashlib.sha1(open(p,'rb').read()).hexdigest(); assert h=='26116613f624061ba99c8d1a299aaa6efa85670d', h; print('baseline DOL hash passed')"
EXPECT: baseline DOL hash passed
EVIDENCE: baseline DOL SHA-1 26116613f624061ba99c8d1a299aaa6efa85670d (2026-09-19)
- [x] G4: the final working tree has no whitespace errors
CHECK: git diff --check && echo 'diff check passed'
EXPECT: diff check passed
EVIDENCE: diff check passed (2026-09-19)

View File

@@ -2,8 +2,8 @@
>
> original doesnt like ai commits, so im forking to not disturb them. :)
>
> This is a personal fork for AI-assisted matching work. No pull requests are
> opened against upstream, ever. See [AGENTS.md](AGENTS.md).
> This is a personal fork for AI-assisted matching work. The 4.3U decompilation
> is complete. No pull requests are opened against upstream, ever.
<!--- Github Actions Badge -->

View File

@@ -1,21 +0,0 @@
MIT License
Copyright (c) 2026 TypeSafe AI
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,148 +0,0 @@
---
name: typesafe-ai
description: >
Build AI-powered software with TypeSafe: small units of AI intelligence you
can use like programming primitives. Its System One models, including Jev,
turn natural language and application state into typed judgments and
probabilities that code can combine. Use when a feature needs programmable
common sense, when brainstorming what AI could make possible in an app, or
when an LLM prompt-and-parse step could become a structured decision.
Applications include routing, ranking, extraction, verification, and
interactive experiences; these are starting points, not the limits. Read live
docs and cookbooks to find useful patterns and discover new combinations.
license: MIT
---
# Build with TypeSafe
TypeSafe makes units of AI intelligence usable like programming primitives: small
judgments you can compose into larger capabilities. Its **System One models** return
fast, focused judgments that software can consume directly. **Jev** is TypeSafe's
flagship and first System One model. It understands natural language and returns
typed answers and probabilities rather
than generating text or reasoning explanations. Code owns the workflow; the model
supplies programmable common sense where ordinary code needs semantic understanding.
## Read the live docs
**The live TypeSafe docs are the source of truth. Read them as part of the task.**
This skill gives direction; the docs carry current concepts, prompting guidance,
API contracts, SDK usage, models, limits, and worked examples.
- Start with the [documentation index](https://docs.typesafe.ai/llms.txt) to discover
relevant pages and cookbooks. Use targeted reads rather than loading the entire site.
- Mintlify serves Markdown by appending `.md` to a page path, for example
[how to build with TypeSafe](https://docs.typesafe.ai/concepts/how-to-build-with-system-one.md).
Follow links from the index; convert extensionless documentation page links to
`.md` when useful. Resolve relative links against `https://docs.typesafe.ai`.
- Before writing an integration, read the current API or chosen SDK page and the
question guidance relevant to the design. For a new workflow, also inspect the
closest cookbook: it often shows a better decomposition than a generic classifier.
- If the index is unavailable, use the direct links below or the site's navigation.
If Markdown fetching fails, try the normal page. If live access is unavailable,
use available local docs or installed SDK types, state that limitation, and avoid
inventing version-dependent details.
| Task | Start here; follow the relevant details |
| --- | --- |
| Understand the programming model | [System One](https://docs.typesafe.ai/concepts/system-one.md), [building guide](https://docs.typesafe.ai/concepts/how-to-build-with-system-one.md) |
| Explore what to build | [Use-case map](https://docs.typesafe.ai/concepts/use-case-map.md), then relevant cookbooks from the index |
| Prepare inputs and questions | [State](https://docs.typesafe.ai/concepts/state.md), [primitives](https://docs.typesafe.ai/primitives.md), then the chosen primitive's page |
| Decide how to handle uncertainty | [Confidence](https://docs.typesafe.ai/confidence.md) |
| Write API code | [HTTP API](https://docs.typesafe.ai/api.md), [Python SDK](https://docs.typesafe.ai/sdk/python.md), or [JavaScript SDK](https://docs.typesafe.ai/sdk/javascript.md) |
| Update an older integration | [Migration guide](https://docs.typesafe.ai/migrating-to-v1.md) and the installed SDK's current reference |
## Find the useful shape
Start from the behavior the user wants: what will the application show, select,
change, or hand off? Work backward to the judgments it needs. Keep known rules,
calculations, exact lookups, and execution in code. Preserve the user's chosen stack
and scope; add TypeSafe where semantic understanding helps.
When brainstorming or choosing an architecture, consider more than classification.
The patterns below are starting points: combine primitives around the user's goal,
including ideas that do not fit an established recipe.
- **Route and fill known arguments.** A request can select a handler and its typed
parameters. Ask useful branch-specific questions up front and consume only the
relevant answers. Explore [function calling](https://docs.typesafe.ai/cookbooks/function_calling.md)
and [speculative fan-out](https://docs.typesafe.ai/patterns/fan-out.md).
- **Select instead of generate.** Find candidate values or source spans in code,
use a judgment to select the intended one, then copy or normalize it. Code can
also assemble source text into a formatted document or reading guide. Explore
[value extraction](https://docs.typesafe.ai/cookbooks/pre_parsed_value_extraction_cookbook.md)
and [structure recovery](https://docs.typesafe.ai/cookbooks/autoformat.md).
- **Find and judge evidence.** Retrieve candidates, compare their relevance to a
query, and select useful context. Explore [reranking](https://docs.typesafe.ai/cookbooks/rerank_typesafe.md)
and [hierarchical classification](https://docs.typesafe.ai/cookbooks/hierarchical_classification.md).
- **Turn judgments into reusable data.** Score dimensions once, then let code or
user controls change weights, thresholds, rankings, and views. With labeled
outcomes, those signals can become classical ML features. Explore
[composite scoring](https://docs.typesafe.ai/patterns/composite-scoring.md) and
[feature discovery](https://docs.typesafe.ai/cookbooks/autoresearch_feature_discovery.md).
- **Verify and escalate.** Check specific claims or fields against their evidence;
send uncertain or failing cases to a person or reasoning model. Explore
[citation checks](https://docs.typesafe.ai/cookbooks/citation_check.md) and
[extraction cascades](https://docs.typesafe.ai/cookbooks/sde_cascade.md).
- **Respond to changing state.** Code can retain goals and observations while fresh
judgments guide the next bounded step. Keep inferred state distinct from observed
facts, and check freshness before applying a result to a changed situation.
For open-ended requests, offer the few directions that best serve the user's goal
and recommend a starting point. For a concrete request, choose the relevant pattern
and build; a brainstorm is not a mandatory detour.
## Design the judgments
Choose by what the answer means, then read the relevant primitive page:
| Need | Primitive | Important distinction |
| --- | --- | --- |
| One of a defined set | [Choice](https://docs.typesafe.ai/primitives/choice.md) | Picks one option; its distribution compares competing options |
| Whether a condition holds | [Noul](https://docs.typesafe.ai/primitives/noul.md) | Probability of yes; no separate confidence; use one per label when several may apply |
| Degree along a described dimension | [Score](https://docs.typesafe.ai/primitives/score.md) | Probability-weighted position on ordered levels; use comparable per-item Scores for graded ranking |
Give each question enough relevant **state** to answer: source text, identities,
relationships, policies, and current facts. Prefer named JSON fields when context
has several parts. Put the judgment in **instructions** and define its possible
answers in **criteria**. Question IDs are for code and are not sent to the model;
include complete meaning in the question. Reference nested state with backticked
paths such as `ticket.messages[0].text`.
Ask one narrow, coherent judgment per question. Split independently useful dimensions,
without destroying the relationship being judged. A bounded action selection or
contextual interpretation is valid; atomic does not mean literal fact extraction
or a one-sentence limit. Strings work for simple questions. Use structured objects
or arrays when definitions, contrasts, exclusions, or examples clarify instructions
or criteria. Score levels must describe concrete situations and stand on their own.
Keep the needed answers available. Include a no-match outcome when nothing may fit;
use a separate presence judgment when it is independently useful. For source-value
selection, check candidate coverage: the model cannot choose an omitted value.
## Compose and verify
**Ask independent questions over the same state together**, including useful
speculative questions. They run in parallel and cannot see one another's answers.
State each speculative premise explicitly; code consumes the applicable answers.
A second request is warranted when an earlier answer is needed to fetch evidence,
construct new state, or determine the next options. Extra questions still use tokens;
measure actual request budgets, cost, and end-to-end latency.
Use probabilities and confidence to guide behavior, with thresholds evaluated on
the user's data and consequences. Choice/Score confidence summarizes distribution
concentration, not overall workflow correctness or permission to act. A Noul near
0.5 means similar probability for yes and no, not medium intensity. Several
acceptable alternatives can also spread probability; low confidence need not
invalidate a harmless preference choice. Ignore uncertainty on unused branches.
Keep policy explicit and raw judgments reusable. Weighted scores suit compensating
preferences; an “any serious violation” rule needs separate conditions. Changing a
weight or display filter need not rerun inference when evidence and question meanings
are unchanged. Typed output guarantees the interface, not truth. System One models
are trained for calibrated decisions; validate their performance in the target domain.
Test representative cases and the resulting application behavior. For failures,
inspect the exact state, questions, candidates, answers, composition, and observed
outcome. Separate missing evidence, model errors, code errors, and service failures.
Treat cookbook thresholds and demo results as examples to evaluate, not universal
rules or permanent model limitations. Keep API credentials server-side in web apps.

View File

@@ -1,293 +0,0 @@
# sol-med matching attempts
ATERM pool was identical before iteration. Initial gate: 3/26 instruction-exact, code 72/19204, data 18440/18864, no regressions.
ATERM_814021BC: (1) combined network settings and access-point name, moved member-pointer initialization after clears, bottom-tested host loop: 153/154 instructions, register and addressing differences; (2) aligned the name member and explicit settings pointer: same instruction count and differences; (3) initialized IP pointer before clear: no improvement. Restored original to avoid unrelated aggregate changes.
ATERM_81402424: (1) aligned scan parameters to 32, swapped message/buffer declarations, preserved scan exit result test: 210/210, three condition-register differences; (2) tested scan result != retry error: one branch difference; (3) tested scan result == retry error: 210/210, diffs 0. Retained.
ATERM_8140276C: (1) initialized previous record cursor before outer loop, reset at outer tail, separated result flag, scoped AOSS flags: 174/174, 31 register differences; (2) reordered result/found declarations and scoped previous index: 174/174, 27 register differences. Further experiments below.
ATERM_81403614: (1) switch over hex character ranges, signed index and indexed output: 49/49, two division differences; (2) explicit signed truncation for index/2: one operand-order difference; (3) reversed addition operands: diffs 0. Retained.
ATERMi_AutoConfigThread: (1) real three-field progress object and conditional terminal state: 39/40 instructions; (2) signed equality mask: 40/40, three scheduling/register differences; (3) read progress result before deadline assignment: eight differences. Further experiments below.
ATERMi_ApConfigStart: (1) inclusive state bounds, use stored stack size and callback: 103/103, twelve differences; (2) restore source order of global initialization: six clock-register differences. Further experiments below.
ATERMi_ApConfigEnd: (1) capture initial state only inside active-thread branch, swap message declarations, compute 500ms alarm instead of reciprocal literal: 125/129 instructions, frame/scheduling differences. Further experiments below.
ATERMi_ApConfigGetState: (1) reciprocal first in multiply-high: four register differences; (2) load bus clock in multiply expression: unchanged; (3) direct time conversion expression: unchanged. Restored original, 35/35 instructions with three register differences.
ATERM_8140276C initial 99.166664%
- previous cursor declaration before current cursor: 99.5115%; src 0x2b8 base 0x2b8 insns 174/174; diffs 15: [8, 9, 82, 84, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97]; 8 M addi r27, r4, 4; B addi r31, r3, 4
- signed record indices: 99.166664%; src 0x2b8 base 0x2b8 insns 174/174; diffs 27: [8, 9, 18, 29, 34, 41, 50, 54, 55, 60, 61, 68, 74, 75, 82, 84, 87, 88, 89, 90]; 8 M addi r27, r3, 4; B addi r31, r3, 4
- AOSS flags initialized after clear: 99.54023%; src 0x2b8 base 0x2b8 insns 174/174; diffs 14: [8, 9, 18, 29, 34, 41, 50, 54, 55, 60, 61, 68, 74, 75]; 8 M addi r27, r3, 4; B addi r31, r3, 4
Retained original
ATERM_81402A24 initial 72.47529%
- record capacity includes final descriptor: 71.30038%; src 0x3d4 base 0x41c insns 245/263; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x80(r1); B 0 stwu r1, -0x90(r1)
- allocate nullable buffers before handling failure: 72.380226%; src 0x3cc base 0x41c insns 243/263; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x80(r1); B 0 stwu r1, -0x90(r1)
- multiply-high tick conversion: 75.76426%; src 0x3f4 base 0x41c insns 253/263; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x80(r1); B 0 stwu r1, -0x90(r1)
Retained original
ATERM_81402E40 initial 99.791664%
- payload clear through byte alias: 99.791664%; src 0x180 base 0x180 insns 96/96; diffs 4: [9, 10, 47, 52]; 9 M mr r29, r7; B mr r3, r27
- natural checksum loop: 65.208336%; src 0x108 base 0x180 insns 66/96; --- replace mine 5:12 base 5:12; M 5 mr r28, r5; M 6 mr r26, r3
- end length as packet byte extent: 95.572914%; src 0x180 base 0x180 insns 96/96; diffs 6: [9, 10, 42, 44, 47, 52]; 9 M mr r29, r7; B mr r3, r27
Retained original
ATERM_81402FC0 initial 67.28148%
- full-width checksum accumulator: 64.76296%; src 0x20c base 0x21c insns 131/135; --- insert mine 8:8 base 8:9; B 8 li r31, 0; --- replace mine 9:10 base 10:11
- bottom-tested option loop: compile failed
- early return for bad checksum: 66.94074%; src 0x20c base 0x21c insns 131/135; --- insert mine 8:8 base 8:9; B 8 li r31, 0; --- replace mine 9:10 base 10:11
Retained original
ATERM_814031DC initial 85.7218%
- MAC text uses equal-sized buffers: 85.766914%; src 0x1f4 base 0x214 insns 125/133; --- replace mine 47:48 base 47:48; M 47 beq 288; B 47 beq 320
- nibble conversion advances output cursor: 84.293236%; src 0x204 base 0x214 insns 129/133; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x70(r1); B 0 stwu r1, -0x60(r1)
- inclusive digit bound and pointer-based MAC scan: 85.90225%; src 0x1f4 base 0x214 insns 125/133; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x70(r1); B 0 stwu r1, -0x60(r1)
Retained original
ATERM_814033F0 initial 65.868614%
- option fields retain converted word width: 67.39416%; src 0x214 base 0x224 insns 133/137; --- replace mine 5:6 base 5:6; M 5 addi r30, r3, 8; B 5 addi r29, r3, 8
- bottom-tested parser dispatch: 65.79562%; src 0x21c base 0x224 insns 135/137; --- replace mine 5:6 base 5:6; M 5 addi r28, r3, 8; B 5 addi r29, r3, 8
- signed nibble comparisons: 65.32117%; src 0x21c base 0x224 insns 135/137; --- insert mine 7:7 base 7:8; B 7 li r24, 0; --- replace mine 10:29 base 11:17
Retained original
ATERM_814036D8 initial 73.92742%
- security switch matches original decision tree: 85.22581%; src 0x1ec base 0x1f0 insns 123/124; --- replace mine 14:15 base 14:15; M 14 beq 340; B 14 beq 344
- key text passed through one cursor: 87.0%; src 0x1e4 base 0x1f0 insns 121/124; --- replace mine 14:24 base 14:16; M 14 bne 36; M 15 addi r3, r25, 0
- counted loop over key records: 73.92742%; src 0x1e0 base 0x1f0 insns 120/124; --- replace mine 14:24 base 14:16; M 14 bne 36; M 15 addi r3, r25, 0
Retained original
ATERM_814038C8 initial 35.28917%
- one-shot 500ms wait replaces repeated alarm: 35.700314%; src 0x788 base 0xedc insns 482/951; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0xe0(r1); B 0 stwu r1, -0x180(r1)
- bottom-tested state machine and wait buffer order: 35.288116%; src 0x784 base 0xedc insns 481/951; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0xe0(r1); B 0 stwu r1, -0x180(r1)
- progress uses semantic structure: 35.28917%; src 0x784 base 0xedc insns 481/951; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0xe0(r1); B 0 stwu r1, -0x180(r1)
Retained original
ATERM_81404844 initial 19.615385%
- signed RFC3394 counters: 16.34188%; src 0x1a0 base 0x1d4 insns 104/117; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x150(r1); B 0 stwu r1, -0x190(r1)
- counter represented as big-endian bytes: compile failed
- RFC3394 initial value and block output order: 18.264957%; src 0x1b0 base 0x1d4 insns 108/117; --- replace mine 6:9 base 6:13; M 6 mr r27, r3; M 7 mr r20, r4
Retained original
ATERM_81404A18 initial 51.107437%
ATERM_81404844 initial 19.615385%
- signed RFC3394 counters: 16.34188%; src 0x1a0 base 0x1d4 insns 104/117; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x150(r1); B 0 stwu r1, -0x190(r1)
ATERM_81404844 initial 16.34188%
- signed RFC3394 counters: 16.34188%; src 0x1a0 base 0x1d4 insns 104/117; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x150(r1); B 0 stwu r1, -0x190(r1)
- counter represented as big-endian bytes: compile failed
- RFC3394 initial value and block output order: 18.264957%; src 0x1b0 base 0x1d4 insns 108/117; --- replace mine 6:9 base 6:13; M 6 mr r27, r3; M 7 mr r20, r4
Retained original
ATERM_81404A18 initial 51.107437%
- signed RFC3394 counters: 52.05785%; src 0x1c8 base 0x1e4 insns 114/121; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x150(r1); B 0 stwu r1, -0x1a0(r1)
- counter represented as big-endian bytes: compile failed
- RFC3394 initial value and block output order: 54.991737%; src 0x1c4 base 0x1e4 insns 113/121; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x190(r1); B 0 stwu r1, -0x1a0(r1)
Retained original
ATERM_81404BFC initial 36.869404%
- AES byte assembly uses XOR instead of OR: 37.063435%; src 0x400 base 0x430 insns 256/268; --- replace mine 0:6 base 0:20; M 0 lbz r7, 1(r4); M 1 cmplwi r5, 0x80
- key schedule reads preceding round and chains fourth key word: 36.925373%; src 0x3dc base 0x430 insns 247/268; --- replace mine 0:6 base 0:20; M 0 lbz r7, 1(r4); M 1 cmplwi r5, 0x80
- signed round count drives key expansion termination: 49.21642%; src 0x3e0 base 0x430 insns 248/268; --- replace mine 0:3 base 0:47; M 0 lbz r8, 1(r4); M 1 cmplwi r5, 0x80
Retained original
ATERM_8140502C initial 35.666668%
- interleaved key-word swaps: 42.355072%; src 0x280 base 0x228 insns 160/138; --- insert mine 5:5 base 5:8; B 5 stw r30, 8(r1); B 6 lis r30, 0
- signed indexed round reversal: 38.746376%; src 0x290 base 0x228 insns 164/138; --- insert mine 5:5 base 5:8; B 5 stw r30, 8(r1); B 6 lis r30, 0
- counted transformation loop: 11.731884%; src 0x288 base 0x228 insns 162/138; --- insert mine 5:5 base 5:8; B 5 stw r30, 8(r1); B 6 lis r30, 0
Retained original
ATERM_81405254 initial 30.464945%
- AES byte assembly uses XOR: 34.23247%; src 0x3c4 base 0x43c insns 241/271; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x40(r1); B 0 stwu r1, -0x50(r1)
- two-round loop with final round exit: compile failed
- signed round count with separately combined key XOR: compile failed
Retained original
ATERM_81405690 initial 26.601477%
- AES byte assembly uses XOR: 34.64945%; src 0x3d4 base 0x43c insns 245/271; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x40(r1); B 0 stwu r1, -0x50(r1)
- two-round loop with final round exit: compile failed
- signed round count with separately combined key XOR: compile failed
Retained original
ATERM_81405ACC initial 0%
- natural byte copy instead of explicit eight-byte loop: 0%; src 0x10c base 0x240 insns 67/144; --- insert mine 2:2 base 2:3; B 2 slwi r7, r5, 3; --- replace mine 3:12 base 4:10
- separate 32-bit count carry updates: 0%; src 0x184 base 0x240 insns 97/144; --- insert mine 2:2 base 2:3; B 2 slwi r7, r5, 3; --- replace mine 3:5 base 4:11
- indexed full-block walk retains input length: 0%; src 0x17c base 0x240 insns 95/144; --- insert mine 2:2 base 2:3; B 2 slwi r7, r5, 3; --- replace mine 3:12 base 4:10
Retained original
ATERM_81405D0C initial 32.62639%
- decode words with XOR: 25.144444%; src 0xa5c base 0xb40 insns 663/720; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x90(r1); B 0 stwu r1, -0xa0(r1)
- MD5 first-round select expressed as xor mask: 30.945833%; src 0x9fc base 0xb40 insns 639/720; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x90(r1); B 0 stwu r1, -0xa0(r1)
- flat byte-to-word decode loop: 27.13889%; src 0x904 base 0xb40 insns 577/720; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x90(r1); B 0 stwu r1, -0xa0(r1)
Retained original
ATERMi_AutoConfigThread initial 91.325%
- remaining time assigned before terminal state: 91.475%; src 0xa0 base 0xa0 insns 40/40; diffs 7: [20, 22, 23, 26, 28, 29, 30]; 20 M nor r0, r3, r0; B nor r3, r3, r0
- terminal mask reuses result variable: 85.075%; src 0xa0 base 0xa0 insns 40/40; diffs 9: [21, 22, 23, 25, 26, 28, 29, 30, 31]; 21 M lwz r4, 0(0); B li r4, -1
- state stores preceding deadline store: 85.2%; src 0xa0 base 0xa0 insns 40/40; diffs 8: [21, 22, 23, 25, 26, 29, 30, 31]; 21 M lwz r4, 0(0); B li r4, -1
Retained original
ATERMi_ApConfigStart initial 99.70874%
- allocate via stored callback: 99.70874%; src 0x19c base 0x19c insns 103/103; diffs 6: [46, 47, 48, 49, 75, 76]; 46 M lis r31, -0x8000; B lis r30, -0x8000
- tick multiplier commutes operands: 97.76699%; src 0x19c base 0x19c insns 103/103; diffs 7: [48, 49, 51, 75, 76, 77, 78]; 48 M lwz r6, 0xf8(r30); B lwz r0, 0xf8(r30)
- progress state populated before zeroing result buffer: 90.72816%; src 0x19c base 0x19c insns 103/103; diffs 18: [46, 47, 48, 49, 56, 58, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 75, 76]; 46 M lis r31, -0x8000; B lis r30, -0x8000
Retained original
ATERMi_ApConfigEnd initial 93.94574%
- message queues declared within their wait scopes: 91.89922%; src 0x1f4 base 0x204 insns 125/129; --- replace mine 3:5 base 3:7; M 3 addi r11, r1, 0xe0; M 4 bl 0
- join loop expressed as do-while: 91.54263%; src 0x200 base 0x204 insns 128/129; --- replace mine 3:5 base 3:7; M 3 addi r11, r1, 0xe0; M 4 bl 0
- time conversion evaluated directly: 93.94574%; src 0x1f4 base 0x204 insns 125/129; --- replace mine 3:5 base 3:7; M 3 addi r11, r1, 0xe0; M 4 bl 0
Retained original
ATERM_81404844 initial 19.615385%
- big-endian counter union assigned after declarations: 23.931623%; src 0x1a0 base 0x1d4 insns 104/117; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x150(r1); B 0 stwu r1, -0x190(r1)
Retained original
ATERM_81404A18 initial 51.107437%
- big-endian counter union assigned after declarations: 57.677685%; src 0x1c8 base 0x1e4 insns 114/121; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x150(r1); B 0 stwu r1, -0x1a0(r1)
Retained original
ATERM_81405254 initial 30.464945%
- two-round iteration with scoped second round: 25.00369%; src 0x4b8 base 0x43c insns 302/271; --- replace mine 5:42 base 5:230; M 5 lbz r9, 1(r5); M 6 lis r12, 0
- signed round index: 30.464945%; src 0x3a4 base 0x43c insns 233/271; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x40(r1); B 0 stwu r1, -0x50(r1)
- round key XOR before table combination: 30.464945%; src 0x3a4 base 0x43c insns 233/271; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x40(r1); B 0 stwu r1, -0x50(r1)
Retained original
ATERM_81405690 initial 26.601477%
- two-round iteration with scoped second round: 23.239853%; src 0x4d8 base 0x43c insns 310/271; --- replace mine 5:13 base 5:7; M 5 lbz r10, 1(r5); M 6 lis r7, 0
- signed round index: 26.601477%; src 0x3b4 base 0x43c insns 237/271; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x40(r1); B 0 stwu r1, -0x50(r1)
- round key XOR before table combination: 26.601477%; src 0x3b4 base 0x43c insns 237/271; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x40(r1); B 0 stwu r1, -0x50(r1)
Retained original
ATERM_81402FC0 initial 67.28148%
- option loop with explicit continuation test: 67.28148%; src 0x210 base 0x21c insns 132/135; --- insert mine 8:8 base 8:9; B 8 li r31, 0; --- replace mine 9:10 base 10:11
Retained original
ATERM final source retains only exact scan and hex-conversion changes. All unsuccessful experiments restored. Remaining 21 functions are open; their instruction counts and experiment outcomes are recorded above. Cryptographic routines require substantial reconstruction, not just register allocation.
AOSS initial gate: 7/21 instruction-exact; code 2540/16192; data 3896/3928. String pool identical.
AOSS_814001B4: early returns and opcode switch: 75/79, remaining differences are save/restore helper versus individual stores.
AOSS_81401BBC: (1) reverse rounding addition: same one operand-order difference; (2) signed rounding temporary: same difference; (3) inline signed rounding expression: 56/56, diffs 0. Retained.
AOSS_81401DC0: (1) reuse seed parameter: 48/48, four last-step register differences; (2) split shift/XOR statements: 64/48 instructions; (3) eight-iteration CRC loop: 16/48 instructions. Restored original.
AOSS_Init_old initial 28.42298%
- full-width wait counters instead of narrowing every update: 28.546717%; src 0x1758 base 0x18c0 insns 1494/1584; --- replace mine 0:1 base 0:4; M 0 stwu r1, -0x100(r1); B 0 clrlwi r11, r1, 0x1b
AOSS_Init_old initial 28.42298%
- full-width wait counters instead of narrowing every update: 28.546717%; src 0x1758 base 0x18c0 insns 1494/1584; --- replace mine 0:1 base 0:4; M 0 stwu r1, -0x100(r1); B 0 clrlwi r11, r1, 0x1b
- packet length conversion retains full width: 28.42298%; src 0x1794 base 0x18c0 insns 1509/1584; --- replace mine 0:1 base 0:4; M 0 stwu r1, -0x100(r1); B 0 clrlwi r11, r1, 0x1b
- poll arguments given semantic socket events structure: 28.42298%; src 0x1794 base 0x18c0 insns 1509/1584; --- replace mine 0:1 base 0:4; M 0 stwu r1, -0x100(r1); B 0 clrlwi r11, r1, 0x1b
Retained original
AOSS_813FFD68 initial 96.981735%
- validation loops use signed char: 93.69406%; src 0x364 base 0x36c insns 217/219; --- replace mine 3:5 base 3:7; M 3 addi r11, r1, 0x20; M 4 bl 0
- return failure immediately on invalid character: 82.05023%; src 0x2ec base 0x36c insns 187/219; --- replace mine 3:5 base 3:7; M 3 addi r11, r1, 0x20; M 4 bl 0
- ascending validation cursor loop: 94.76712%; src 0x374 base 0x36c insns 221/219; --- replace mine 3:5 base 3:7; M 3 addi r11, r1, 0x20; M 4 bl 0
Retained original
AOSS_814001B4 initial 88.78481%
- converted packet length stays full width: 88.78481%; src 0x12c base 0x13c insns 75/79; --- replace mine 3:5 base 3:10; M 3 addi r11, r1, 0x20; M 4 bl 0
- direct opcode return cases: 83.27848%; src 0x124 base 0x13c insns 73/79; --- replace mine 3:5 base 3:10; M 3 addi r11, r1, 0x20; M 4 bl 0
- full-width validation and branch nesting: 88.78481%; src 0x12c base 0x13c insns 75/79; --- replace mine 3:5 base 3:10; M 3 addi r11, r1, 0x20; M 4 bl 0
Retained original
AOSS_814002F0 initial 79.525%
- read manufacturer only after state validation: 85.058334%; src 0x1c4 base 0x1e0 insns 113/120; --- replace mine 6:8 base 6:8; M 6 mr r30, r3; M 7 mr r26, r4
- packet sequence values remain full-width: 76.441666%; src 0x1c4 base 0x1e0 insns 113/120; --- replace mine 5:7 base 5:8; M 5 mr r30, r3; M 6 mr r26, r4
- direct address error branch: 79.525%; src 0x1c8 base 0x1e0 insns 114/120; --- replace mine 5:7 base 5:8; M 5 mr r30, r3; M 6 mr r26, r4
Retained original
AOSS_81400830 initial 77.619934%
- single-byte RC4 generation loop instead of manual pairs: 65.65109%; src 0x3c0 base 0x504 insns 240/321; --- insert mine 6:6 base 6:7; B 6 addi r29, r3, 0x18; --- insert mine 7:7 base 8:9
- natural CRC byte loop: 60.13084%; src 0x3c4 base 0x504 insns 241/321; --- replace mine 5:6 base 5:7; M 5 mr r27, r3; B 5 mr r26, r3
- narrow RC4 state indices at assignment: 77.619934%; src 0x4b8 base 0x504 insns 302/321; --- insert mine 6:6 base 6:7; B 6 addi r29, r3, 0x18; --- insert mine 7:7 base 8:9
Retained original
AOSS_81400E0C initial 77.52105%
- signed option lengths and iteration indices: 77.778946%; src 0x2bc base 0x2f8 insns 175/190; --- insert mine 5:5 base 5:6; B 5 mr r29, r4; --- replace mine 6:8 base 7:8
- natural integer byte decode for both address options: 44.963158%; src 0x188 base 0x2f8 insns 98/190; --- insert mine 5:5 base 5:6; B 5 mr r29, r4; --- replace mine 6:8 base 7:8
- address decode accumulation uses OR: 61.963158%; src 0x284 base 0x2f8 insns 161/190; --- replace mine 5:8 base 5:8; M 5 mr r29, r3; M 6 mr r30, r4
Retained original
AOSS_814013AC initial 91.70175%
- signed option lengths: 91.70175%; src 0x1cc base 0x1c8 insns 115/114; --- insert mine 6:6 base 6:7; B 6 mr r27, r3; --- delete mine 7:8 base 8:8
- apply flags after successful parser call: 84.68421%; src 0x1ec base 0x1c8 insns 123/114; --- insert mine 6:6 base 6:7; B 6 mr r27, r3; --- delete mine 7:8 base 8:8
- bounded while loop over selected reply payload: 88.2807%; src 0x1d4 base 0x1c8 insns 117/114; --- insert mine 6:6 base 6:7; B 6 mr r27, r3; --- delete mine 7:8 base 8:8
Retained original
AOSS_81401574 initial 92.558136%
- semantic payload extent expression: 92.558136%; src 0x1fc base 0x204 insns 127/129; --- replace mine 5:7 base 5:7; M 5 lwz r30, 0(0); M 6 mr r27, r4
- request length remains full-width: 92.209305%; src 0x1f8 base 0x204 insns 126/129; --- replace mine 5:7 base 5:7; M 5 lwz r30, 0(0); M 6 mr r27, r4
- initialize destination length before port conversion: 88.31783%; src 0x1fc base 0x204 insns 127/129; --- replace mine 5:7 base 5:7; M 5 lwz r30, 0(0); M 6 mr r27, r4
Retained original
AOSS_81401778 initial 71.93407%
- CRC checksum stays full width until header store: 71.93407%; src 0x434 base 0x444 insns 269/273; --- replace mine 5:7 base 5:6; M 5 lis r31, 0; M 6 lwz r30, 0(0)
- signed RC4 byte loop index: 71.93407%; src 0x434 base 0x444 insns 269/273; --- replace mine 5:7 base 5:6; M 5 lis r31, 0; M 6 lwz r30, 0(0)
- copy hello payload before manufacturer encoding: 71.91575%; src 0x434 base 0x444 insns 269/273; --- replace mine 5:7 base 5:6; M 5 lis r31, 0; M 6 lwz r30, 0(0)
Retained original
AOSS_81401C9C initial 71.9315%
- natural RC4 state initialization loop: 43.342464%; src 0x98 base 0x124 insns 38/73; --- replace mine 0:1 base 0:2; M 0 li r9, 0; B 0 stwu r1, -0x10(r1)
- schedule state reset before obtaining byte pointer: 71.9315%; src 0x12c base 0x124 insns 75/73; --- replace mine 0:6 base 0:2; M 0 stwu r1, -0x20(r1); M 1 mflr r0
- signed key and state indices: 71.9315%; src 0x12c base 0x124 insns 75/73; --- replace mine 0:6 base 0:2; M 0 stwu r1, -0x20(r1); M 1 mflr r0
Retained original
AOSS_81401E80 initial 91.80272%
- natural XOR loop over half-packet: 56.455784%; src 0x168 base 0x24c insns 90/147; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x30(r1); B 0 stwu r1, -0x40(r1)
- half-length via signed division: 87.04082%; src 0x240 base 0x24c insns 144/147; --- replace mine 5:19 base 5:13; M 5 srawi r0, r4, 1; M 6 mr r28, r3
- count-down rounds: 88.734695%; src 0x244 base 0x24c insns 145/147; --- replace mine 6:7 base 6:7; M 6 mr r28, r3; B 6 mr r21, r3
Retained original
AOSS_814020CC initial 76.066666%
- sleep tick product stays 64-bit: 67.51667%; src 0xfc base 0xf0 insns 63/60; --- replace mine 3:6 base 3:7; M 3 addi r11, r1, 0x20; M 4 bl 0
- tick duration via explicit multiply-high: 81.65%; src 0xe4 base 0xf0 insns 57/60; --- replace mine 3:5 base 3:6; M 3 addi r11, r1, 0x20; M 4 bl 0
- do-while host acquisition loop: 65.066666%; src 0xf8 base 0xf0 insns 62/60; --- replace mine 3:6 base 3:7; M 3 addi r11, r1, 0x20; M 4 bl 0
Retained original
AOSS final: retained exact packet builder AOSS_81401BBC only. Other experiments restored; remaining differences include loop expansion, register allocation, missing original compiler control flow.
## src/scene/memoryCard/iplMemoryCardBase
Baseline absent source: 0/34, code 0/3640, data 0/152. Implemented all real functions in target address order from original disassembly using typed classes and fields. Initial build: 33/34 exact, code 3240/3640, data 144/152; pool identical.
onCmdRecv initial 96.35%: 101/100 instructions.
- Signed lower/upper bounds for command range: extra comparison and branch.
- Switch cases 1/2/3: 95.35%, 102/100 instructions, compiler produces signed comparison tree.
- Unsigned command range distance: 100%, 100/100 instructions, diffs 0. Retained.
Data limitation: original .sdata2 contains -1.0 plus trailing alignment, while source also emits the required integer-to-float conversion double constant. No forced data or padding added. Full DOL gate determines acceptance; no configure Matching changes.
## Remaining functions at final handoff
src/scene/setting/ATERM: ATERM_814021BC 67.655846% — src 0x264 base 0x268 insns 153/154; --- insert mine 7:7 base 7:9; B 7 addi r30, r30, 0; B 8 li r4, 0; remaining control-flow/codegen differences
src/scene/setting/ATERM: ATERM_8140276C 92.10345% — src 0x2ac base 0x2b8 insns 171/174; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x90(r1); B 0 stwu r1, -0x80(r1); remaining control-flow/codegen differences
src/scene/setting/ATERM: ATERM_81402A24 72.47529% — src 0x3d0 base 0x41c insns 244/263; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x80(r1); B 0 stwu r1, -0x90(r1); remaining control-flow/codegen differences
src/scene/setting/ATERM: ATERM_81402E40 99.791664% — src 0x180 base 0x180 insns 96/96; diffs 4: [9, 10, 47, 52]; 9 M mr r29, r7; B mr r3, r27; remaining register/scheduling differences
src/scene/setting/ATERM: ATERM_81402FC0 67.28148% — src 0x210 base 0x21c insns 132/135; --- insert mine 8:8 base 8:9; B 8 li r31, 0; --- replace mine 9:10 base 10:11; remaining control-flow/codegen differences
src/scene/setting/ATERM: ATERM_814031DC 85.7218% — src 0x1f4 base 0x214 insns 125/133; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x70(r1); B 0 stwu r1, -0x60(r1); remaining control-flow/codegen differences
src/scene/setting/ATERM: ATERM_814033F0 65.868614% — src 0x21c base 0x224 insns 135/137; --- insert mine 7:7 base 7:8; B 7 li r24, 0; --- replace mine 10:29 base 11:17; remaining control-flow/codegen differences
src/scene/setting/ATERM: ATERM_814036D8 73.92742% — src 0x1e0 base 0x1f0 insns 120/124; --- replace mine 14:24 base 14:16; M 14 bne 36; M 15 addi r3, r25, 0; remaining control-flow/codegen differences
src/scene/setting/ATERM: ATERM_814038C8 35.28917% — src 0x784 base 0xedc insns 481/951; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0xe0(r1); B 0 stwu r1, -0x180(r1); remaining control-flow/codegen differences
src/scene/setting/ATERM: ATERMi_AutoConfigThread 94.6% — src 0xa0 base 0xa0 insns 40/40; diffs 9: [0, 2, 3, 20, 22, 23, 34, 36, 38]; 0 M stwu r1, -0x30(r1); B stwu r1, -0x20(r1); remaining register/scheduling differences
src/scene/setting/ATERM: ATERM_81404844 19.615385% — src 0x19c base 0x1d4 insns 103/117; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x150(r1); B 0 stwu r1, -0x190(r1); remaining control-flow/codegen differences
src/scene/setting/ATERM: ATERM_81404A18 51.107437% — src 0x1c4 base 0x1e4 insns 113/121; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x150(r1); B 0 stwu r1, -0x1a0(r1); remaining control-flow/codegen differences
src/scene/setting/ATERM: ATERM_81404BFC 36.869404% — src 0x3dc base 0x430 insns 247/268; --- replace mine 0:6 base 0:20; M 0 lbz r7, 1(r4); M 1 cmplwi r5, 0x80; remaining control-flow/codegen differences
src/scene/setting/ATERM: ATERM_8140502C 35.666668% — src 0x280 base 0x228 insns 160/138; --- insert mine 5:5 base 5:8; B 5 stw r30, 8(r1); B 6 lis r30, 0; remaining control-flow/codegen differences
src/scene/setting/ATERM: ATERM_81405254 30.464945% — src 0x3a4 base 0x43c insns 233/271; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x40(r1); B 0 stwu r1, -0x50(r1); remaining control-flow/codegen differences
src/scene/setting/ATERM: ATERM_81405690 26.601477% — src 0x3b4 base 0x43c insns 237/271; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x40(r1); B 0 stwu r1, -0x50(r1); remaining control-flow/codegen differences
src/scene/setting/ATERM: ATERM_81405ACC None% — src 0x17c base 0x240 insns 95/144; --- insert mine 2:2 base 2:3; B 2 slwi r7, r5, 3; --- replace mine 3:12 base 4:10; remaining control-flow/codegen differences
src/scene/setting/ATERM: ATERM_81405D0C 32.62639% — src 0x9e4 base 0xb40 insns 633/720; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x90(r1); B 0 stwu r1, -0xa0(r1); remaining control-flow/codegen differences
src/scene/setting/ATERM: ATERMi_ApConfigStart 86.49515% — src 0x1a4 base 0x19c insns 105/103; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x30(r1); B 0 stwu r1, -0x20(r1); remaining control-flow/codegen differences
src/scene/setting/ATERM: ATERMi_ApConfigEnd 87.54263% — src 0x1dc base 0x204 insns 119/129; --- replace mine 3:5 base 3:7; M 3 addi r11, r1, 0xe0; M 4 bl 0; remaining control-flow/codegen differences
src/scene/setting/ATERM: ATERMi_ApConfigGetState 99.42857% — src 0x8c base 0x8c insns 35/35; diffs 3: [17, 18, 20]; 17 M lwz r6, 0xf8(r6); B lwz r0, 0xf8(r6); remaining register/scheduling differences
src/scene/setting/AOSS: AOSS_Init_old 28.42298% — src 0x1794 base 0x18c0 insns 1509/1584; --- replace mine 0:1 base 0:4; M 0 stwu r1, -0x100(r1); B 0 clrlwi r11, r1, 0x1b; remaining control-flow/codegen differences
src/scene/setting/AOSS: AOSS_813FFD68 96.981735% — src 0x364 base 0x36c insns 217/219; --- replace mine 3:5 base 3:7; M 3 addi r11, r1, 0x20; M 4 bl 0; remaining control-flow/codegen differences
src/scene/setting/AOSS: AOSS_814001B4 41.518986% — src 0x118 base 0x13c insns 70/79; --- replace mine 3:5 base 3:10; M 3 addi r11, r1, 0x20; M 4 bl 0; remaining control-flow/codegen differences
src/scene/setting/AOSS: AOSS_814002F0 79.525% — src 0x1c8 base 0x1e0 insns 114/120; --- replace mine 5:7 base 5:8; M 5 mr r30, r3; M 6 mr r26, r4; remaining control-flow/codegen differences
src/scene/setting/AOSS: AOSS_81400830 77.619934% — src 0x4b8 base 0x504 insns 302/321; --- insert mine 6:6 base 6:7; B 6 addi r29, r3, 0x18; --- insert mine 7:7 base 8:9; remaining control-flow/codegen differences
src/scene/setting/AOSS: AOSS_81400E0C 77.52105% — src 0x2c4 base 0x2f8 insns 177/190; --- insert mine 5:5 base 5:6; B 5 mr r29, r4; --- replace mine 6:8 base 7:8; remaining control-flow/codegen differences
src/scene/setting/AOSS: AOSS_814013AC 91.70175% — src 0x1cc base 0x1c8 insns 115/114; --- insert mine 6:6 base 6:7; B 6 mr r27, r3; --- delete mine 7:8 base 8:8; remaining control-flow/codegen differences
src/scene/setting/AOSS: AOSS_81401574 92.558136% — src 0x1fc base 0x204 insns 127/129; --- replace mine 5:7 base 5:7; M 5 lwz r30, 0(0); M 6 mr r27, r4; remaining control-flow/codegen differences
src/scene/setting/AOSS: AOSS_81401778 71.93407% — src 0x434 base 0x444 insns 269/273; --- replace mine 5:7 base 5:6; M 5 lis r31, 0; M 6 lwz r30, 0(0); remaining control-flow/codegen differences
src/scene/setting/AOSS: AOSS_81401C9C 71.9315% — src 0x12c base 0x124 insns 75/73; --- replace mine 0:6 base 0:2; M 0 stwu r1, -0x20(r1); M 1 mflr r0; remaining control-flow/codegen differences
src/scene/setting/AOSS: AOSS_81401DC0 99.375% — src 0xc0 base 0xc0 insns 48/48; diffs 4: [39, 41, 42, 43]; 39 M srwi r0, r3, 1; B srwi r3, r3, 1; remaining register/scheduling differences
src/scene/setting/AOSS: AOSS_81401E80 91.80272% — src 0x244 base 0x24c insns 145/147; --- replace mine 6:7 base 6:7; M 6 mr r28, r3; B 6 mr r21, r3; remaining control-flow/codegen differences
src/scene/setting/AOSS: AOSS_814020CC 76.066666% — src 0xf0 base 0xf0 insns 60/60; diffs 39: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 26]; 3 M addi r11, r1, 0x20; B stw r31, 0x1c(r1); remaining register/scheduling differences
MemoryBase full clean gate: 34/34 instruction-exact, code 3640/3640, data 144/152, pool identical, regressions 0, forbidden patterns 0, readability warnings 0, DOL SHA1 26116613f624061ba99c8d1a299aaa6efa85670d, GATE PASS. Data remains incomplete in objdiff; no artificial fix attempted.

View File

@@ -1,326 +0,0 @@
# ATERM and AOSS continuation
Baseline ATERM: 5/26, code 1108/19204, data 18440/18864, fuzzy 50.973755. Baseline AOSS: 8/21, code 2764/16192, data 3896/3928, fuzzy 63.720604. All functions have bodies; existing large state machine and crypto bodies remain incomplete reconstructions. No absent symbols or empty bodies found.
ATERM_8140276C initial 92.10345%
- previous cursor declaration before current cursor: no source change; skipped
- signed record indices: 92.10345%; src 0x2ac base 0x2b8 insns 171/174; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x90(r1); B 0 stwu r1, -0x80(r1)
- AOSS flags initialized after clear: 91.72988%; src 0x2ac base 0x2b8 insns 171/174; --- replace mine 5:10 base 5:13; M 5 mr r25, r3; M 6 mr r26, r4
Retained best candidate
ATERM_81402A24 initial 72.47529%
- record byte count kept signed: no source change; skipped
- allocate nullable buffers before handling failure: 72.380226%; src 0x3cc base 0x41c insns 243/263; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x80(r1); B 0 stwu r1, -0x90(r1)
- multiply-high tick conversion: 75.76426%; src 0x3f4 base 0x41c insns 253/263; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x80(r1); B 0 stwu r1, -0x90(r1)
Retained best candidate
ATERM_81402E40 initial 99.791664%
- payload clear through byte alias: 99.791664%; src 0x180 base 0x180 insns 96/96; diffs 4: [9, 10, 47, 52]; 9 M mr r29, r7; B mr r3, r27
- natural checksum loop: 65.208336%; src 0x108 base 0x180 insns 66/96; --- replace mine 5:12 base 5:12; M 5 mr r28, r5; M 6 mr r26, r3
- end length as packet byte extent: 95.572914%; src 0x180 base 0x180 insns 96/96; diffs 6: [9, 10, 42, 44, 47, 52]; 9 M mr r29, r7; B mr r3, r27
Retained best candidate
ATERM_81402FC0 initial 67.28148%
- full-width checksum accumulator: 64.76296%; src 0x20c base 0x21c insns 131/135; --- insert mine 8:8 base 8:9; B 8 li r31, 0; --- replace mine 9:10 base 10:11
- bottom-tested option loop: compile failed
- early return for bad checksum: 66.94074%; src 0x20c base 0x21c insns 131/135; --- insert mine 8:8 base 8:9; B 8 li r31, 0; --- replace mine 9:10 base 10:11
Retained best candidate
ATERM_814031DC initial 85.7218%
- MAC text uses equal-sized buffers: 85.766914%; src 0x1f4 base 0x214 insns 125/133; --- replace mine 47:48 base 47:48; M 47 beq 288; B 47 beq 320
- nibble conversion advances output cursor: 84.293236%; src 0x204 base 0x214 insns 129/133; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x70(r1); B 0 stwu r1, -0x60(r1)
- inclusive digit bound and pointer-based MAC scan: 85.90225%; src 0x1f4 base 0x214 insns 125/133; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x70(r1); B 0 stwu r1, -0x60(r1)
Retained best candidate
ATERM_814033F0 initial 65.868614%
- option fields retain converted word width: 67.39416%; src 0x214 base 0x224 insns 133/137; --- replace mine 5:6 base 5:6; M 5 addi r30, r3, 8; B 5 addi r29, r3, 8
- bottom-tested parser dispatch: 65.79562%; src 0x21c base 0x224 insns 135/137; --- replace mine 5:6 base 5:6; M 5 addi r28, r3, 8; B 5 addi r29, r3, 8
- signed nibble comparisons: 65.32117%; src 0x21c base 0x224 insns 135/137; --- insert mine 7:7 base 7:8; B 7 li r24, 0; --- replace mine 10:29 base 11:17
Retained best candidate
ATERM_814036D8 initial 73.92742%
- security switch matches original decision tree: 85.22581%; src 0x1ec base 0x1f0 insns 123/124; --- replace mine 14:15 base 14:15; M 14 beq 340; B 14 beq 344
- key text passed through one cursor: 87.0%; src 0x1e4 base 0x1f0 insns 121/124; --- replace mine 14:24 base 14:16; M 14 bne 36; M 15 addi r3, r25, 0
- counted loop over key records: 73.92742%; src 0x1e0 base 0x1f0 insns 120/124; --- replace mine 14:24 base 14:16; M 14 bne 36; M 15 addi r3, r25, 0
Retained best candidate
ATERM_814038C8 initial 35.28917%
- one-shot 500ms wait replaces repeated alarm: 35.700314%; src 0x788 base 0xedc insns 482/951; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0xe0(r1); B 0 stwu r1, -0x180(r1)
- bottom-tested state machine and wait buffer order: 35.288116%; src 0x784 base 0xedc insns 481/951; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0xe0(r1); B 0 stwu r1, -0x180(r1)
- progress uses semantic structure: 35.28917%; src 0x784 base 0xedc insns 481/951; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0xe0(r1); B 0 stwu r1, -0x180(r1)
Retained best candidate
ATERM_81404844 initial 19.615385%
- complete RFC3394 block handling with target initial value and byte counter: 89.89744%; src 0x1bc base 0x1d4 insns 111/117; --- replace mine 6:13 base 6:13; M 6 lwz r8, 0(0); M 7 lwz r0, 0(0)
- hoist signed pass product outside block loop: 89.89744%; src 0x1bc base 0x1d4 insns 111/117; --- replace mine 6:13 base 6:13; M 6 lwz r8, 0(0); M 7 lwz r0, 0(0)
- natural bytewise counter XOR loop: 62.299145%; src 0x178 base 0x1d4 insns 94/117; --- replace mine 6:13 base 6:13; M 6 lwz r8, 0(0); M 7 lwz r0, 0(0)
Retained best candidate
ATERM_81404A18 initial 51.107437%
- complete RFC3394 block handling with target initial value and byte counter: 74.38843%; src 0x1c0 base 0x1e4 insns 112/121; --- replace mine 6:13 base 6:14; M 6 lwz r8, 0(0); M 7 lwz r0, 0(0)
- hoist signed pass product outside block loop: 74.38843%; src 0x1c0 base 0x1e4 insns 112/121; --- replace mine 6:13 base 6:14; M 6 lwz r8, 0(0); M 7 lwz r0, 0(0)
- natural bytewise counter XOR loop: 55.96694%; src 0x180 base 0x1e4 insns 96/121; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x190(r1); B 0 stwu r1, -0x1a0(r1)
Retained best candidate
ATERM_81404BFC initial 36.869404%
- complete AES schedules with bounded final expansion for all three key sizes: 52.50746%; src 0x408 base 0x430 insns 258/268; --- replace mine 0:6 base 0:20; M 0 lbz r7, 1(r4); M 1 cmplwi r5, 0x80
- direct expanded-key parameter used as advancing cursor: 52.50746%; src 0x408 base 0x430 insns 258/268; --- replace mine 0:6 base 0:20; M 0 lbz r7, 1(r4); M 1 cmplwi r5, 0x80
- round limit at loop bottom for 128-bit key: 53.074627%; src 0x404 base 0x430 insns 257/268; --- replace mine 0:6 base 0:20; M 0 lbz r7, 1(r4); M 1 cmplwi r5, 0x80
Retained best candidate
ATERM_8140502C initial 35.666668%
- interleaved key-word swaps: 42.355072%; src 0x280 base 0x228 insns 160/138; --- insert mine 5:5 base 5:8; B 5 stw r30, 8(r1); B 6 lis r30, 0
- signed indexed round reversal: 38.746376%; src 0x290 base 0x228 insns 164/138; --- insert mine 5:5 base 5:8; B 5 stw r30, 8(r1); B 6 lis r30, 0
- counted transformation loop: 11.731884%; src 0x288 base 0x228 insns 162/138; --- insert mine 5:5 base 5:8; B 5 stw r30, 8(r1); B 6 lis r30, 0
Retained best candidate
ATERM_81405254 initial 30.464945%
- AES byte assembly uses XOR: 34.23247%; src 0x3c4 base 0x43c insns 241/271; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x40(r1); B 0 stwu r1, -0x50(r1)
- two-round loop with final round exit: compile failed
- signed round count with separately combined key XOR: compile failed
Retained best candidate
ATERM_81405690 initial 26.601477%
- AES byte assembly uses XOR: 34.64945%; src 0x3d4 base 0x43c insns 245/271; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x40(r1); B 0 stwu r1, -0x50(r1)
- two-round loop with final round exit: compile failed
- signed round count with separately combined key XOR: compile failed
Retained best candidate
ATERM_81405254 initial 34.23247%
- two-round AES loop with final round exit matching target structure: 16.295202%; src 0x4a8 base 0x43c insns 298/271; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x40(r1); B 0 stwu r1, -0x50(r1)
- signed remaining round-pair count: 16.295202%; src 0x4a8 base 0x43c insns 298/271; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x40(r1); B 0 stwu r1, -0x50(r1)
- separate round exit before key advancement: 17.630997%; src 0x4a8 base 0x43c insns 298/271; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x40(r1); B 0 stwu r1, -0x50(r1)
Retained best candidate
ATERM_81405690 initial 34.64945%
- two-round AES loop with final round exit matching target structure: 33.738007%; src 0x4c8 base 0x43c insns 306/271; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x40(r1); B 0 stwu r1, -0x50(r1)
- signed remaining round-pair count: 33.738007%; src 0x4c8 base 0x43c insns 306/271; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x40(r1); B 0 stwu r1, -0x50(r1)
- separate round exit before key advancement: 31.90037%; src 0x4c8 base 0x43c insns 306/271; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x40(r1); B 0 stwu r1, -0x50(r1)
Retained best candidate
ATERM_81405D0C initial 32.62639%
- complete MD5 accumulator rotation with per-step argument-relative selectors: 53.851387%; src 0xa50 base 0xb40 insns 660/720; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x90(r1); B 0 stwu r1, -0xa0(r1)
- MD5 selectors expressed as XOR masks: 44.879166%; src 0xa48 base 0xb40 insns 658/720; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x90(r1); B 0 stwu r1, -0xa0(r1)
- natural sixteen-word little-endian block decode: 47.679165%; src 0x970 base 0xb40 insns 604/720; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x90(r1); B 0 stwu r1, -0xa0(r1)
Retained best candidate
ATERMi_ApConfigGetState initial 99.42857%
- read bus clock before current time call: 72.942856%; src 0x94 base 0x8c insns 37/35; --- replace mine 4:6 base 4:5; M 4 stw r30, 8(r1); M 5 mr r30, r3
- direct timer division using clock conversion expression: 99.42857%; src 0x8c base 0x8c insns 35/35; diffs 3: [17, 18, 20]; 17 M lwz r6, 0xf8(r6); B lwz r0, 0xf8(r6)
- timer load narrowed to native clock register width: 99.42857%; src 0x8c base 0x8c insns 35/35; diffs 4: [15, 16, 17, 18]; 15 M lis r5, -0x8000; B lis r6, -0x8000
Retained best candidate
ATERM_81402E40 initial 99.791664%
- checksum terminal pointer declared before byte length: 99.791664%; src 0x180 base 0x180 insns 96/96; diffs 4: [9, 10, 47, 52]; 9 M mr r29, r7; B mr r3, r27
- payload encryption size retained as signed integer: 99.791664%; src 0x180 base 0x180 insns 96/96; diffs 4: [9, 10, 47, 52]; 9 M mr r29, r7; B mr r3, r27
- end pointer assigned only after header conversion: 94.947914%; src 0x180 base 0x180 insns 96/96; diffs 8: [9, 10, 42, 44, 45, 46, 47, 52]; 9 M mr r29, r7; B mr r3, r27
Retained best candidate
ATERMi_AutoConfigThread initial 94.6%
- callback progress uses three-field structure: 94.75%; src 0xa0 base 0xa0 insns 40/40; diffs 3: [20, 22, 23]; 20 M nor r0, r3, r0; B nor r3, r3, r0
- signed completion state mask in correctly sized progress buffer: 94.75%; src 0xa0 base 0xa0 insns 40/40; diffs 3: [20, 22, 23]; 20 M nor r0, r3, r0; B nor r3, r3, r0
- explicit completion state branch in progress structure: 85.25%; src 0x9c base 0xa0 insns 39/40; --- replace mine 18:21 base 18:22; M 18 addi r0, r31, -1; M 19 li r5, -1
Retained best candidate
ATERM_814021BC initial 67.655846%
- interface configuration pointer initialized before IP setup: 64.266235%; src 0x264 base 0x268 insns 153/154; --- replace mine 7:8 base 7:8; M 7 addi r28, r30, 0; B 7 addi r30, r30, 0
- wait queue message and buffer order follows target stack slots: 67.64286%; src 0x264 base 0x268 insns 153/154; --- insert mine 7:7 base 7:9; B 7 addi r30, r30, 0; B 8 li r4, 0
- host wait expressed as while with shared converted host value: 92.77922%; src 0x274 base 0x268 insns 157/154; --- replace mine 5:8 base 5:8; M 5 lis r31, 0; M 6 li r28, 0
Retained best candidate
ATERM_8140276C initial 92.10345%
- previous-record cursor reset at outer loop tail and scoped fallback flags: 94.04023%; src 0x2b0 base 0x2b8 insns 172/174; --- replace mine 5:11 base 5:13; M 5 mr r25, r3; M 6 mr r26, r4
- previous record initialized before current record: 94.0115%; src 0x2b0 base 0x2b8 insns 172/174; --- replace mine 5:11 base 5:13; M 5 mr r25, r3; M 6 mr r26, r4
- fallback flags set after SSID clear: 94.04023%; src 0x2b0 base 0x2b8 insns 172/174; --- replace mine 5:11 base 5:13; M 5 mr r25, r3; M 6 mr r26, r4
Retained best candidate
ATERM_81405ACC initial 0%
- complete two-phase update copy with target eight-byte group bounds: 55.54861%; src 0x21c base 0x240 insns 135/144; --- insert mine 2:2 base 2:3; B 2 slwi r7, r5, 3; --- replace mine 3:7 base 4:10
- signed byte-copy loop cursors: 55.54861%; src 0x21c base 0x240 insns 135/144; --- insert mine 2:2 base 2:3; B 2 slwi r7, r5, 3; --- replace mine 3:7 base 4:10
- cursor-pair copies instead of repeated indexed addresses: 55.54861%; src 0x21c base 0x240 insns 135/144; --- insert mine 2:2 base 2:3; B 2 slwi r7, r5, 3; --- replace mine 3:7 base 4:10
Retained best candidate
Retained complete update implementation: objdiff 55.54861%, 135/144 instructions. Older source had no reported function score; no exact claim.
ATERMi_ApConfigStart initial 86.49515%
- allocate via stored callback: 86.49515%; src 0x1a4 base 0x19c insns 105/103; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x30(r1); B 0 stwu r1, -0x20(r1)
- tick multiplier commutes operands: 84.11651%; src 0x1a4 base 0x19c insns 105/103; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x30(r1); B 0 stwu r1, -0x20(r1)
- progress callback loaded from installed function pointer: 93.718445%; src 0x1a0 base 0x19c insns 104/103; --- delete mine 4:5 base 4:4; M 4 mr r31, r3; --- replace mine 6:7 base 5:6
Retained best candidate
ATERMi_ApConfigEnd initial 87.54263%
- message queues declared within their wait scopes: 85.496124%; src 0x1dc base 0x204 insns 119/129; --- replace mine 3:5 base 3:7; M 3 addi r11, r1, 0xe0; M 4 bl 0
- join loop expressed as do-while: 85.28682%; src 0x1e8 base 0x204 insns 122/129; --- replace mine 3:5 base 3:7; M 3 addi r11, r1, 0xe0; M 4 bl 0
- time conversion evaluated directly: 87.54263%; src 0x1dc base 0x204 insns 119/129; --- replace mine 3:5 base 3:7; M 3 addi r11, r1, 0xe0; M 4 bl 0
Retained best candidate
ATERM_81402FC0 initial 67.28148%
- signed option payload cursor length: no source change; skipped
- checksum receive pointer read after length decode: 67.28148%; src 0x210 base 0x21c insns 132/135; --- insert mine 8:8 base 8:9; B 8 li r31, 0; --- replace mine 9:10 base 10:11
- option traversal explicit continuation: 67.28148%; src 0x210 base 0x21c insns 132/135; --- insert mine 8:8 base 8:9; B 8 li r31, 0; --- replace mine 9:10 base 10:11
Retained best candidate
ATERM_81402A24 initial 75.76426%
- record allocation size held as size_t: no source change; skipped
Retained best candidate
ATERM_81402FC0 initial 67.28148%
- packet and option values stay full-width until usage: 68.577774%; src 0x208 base 0x21c insns 130/135; --- insert mine 8:8 base 8:9; B 8 li r31, 0; --- delete mine 15:16 base 16:16
- full-width checksum accumulated before explicit final narrowing: 67.28148%; src 0x210 base 0x21c insns 132/135; --- insert mine 8:8 base 8:9; B 8 li r31, 0; --- replace mine 9:10 base 10:11
- option lengths retained as signed word count: 67.28148%; src 0x210 base 0x21c insns 132/135; --- insert mine 8:8 base 8:9; B 8 li r31, 0; --- replace mine 9:10 base 10:11
Retained best candidate
ATERM_81402A24 initial 75.76426%
- record allocation byte count stored in size_t: 75.76426%; src 0x3f4 base 0x41c insns 253/263; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x80(r1); B 0 stwu r1, -0x90(r1)
- iteration counter narrowed to signed timer range: 76.20532%; src 0x3f4 base 0x41c insns 253/263; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x80(r1); B 0 stwu r1, -0x90(r1)
- record pointer walk and indexed record walk share cursor: 75.76426%; src 0x3f4 base 0x41c insns 253/263; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x80(r1); B 0 stwu r1, -0x90(r1)
Retained best candidate
ATERM reconstruction evidence: all 26 target function names have source bodies. Reconstructed RFC3394 wrap/unwrap initial value, signed counters, block writeback and unwrap ordering; corrected all three AES key schedules; corrected MD5 per-step accumulator/selector semantics and low/high bit counts; reconstructed the missing authentication timestamp digest and protocol option-id bytes in the main state machine. These are partial instruction matches, not completion.
Native validation of extracted unchanged crypto implementations: NIST AES 128/192/256 encryption and decryption vectors passed. MD5 messages of length 0, 1, 3, 55, 56, 64, 130 matched hashlib. Native correctness is supplemental evidence only; MWCC objdiff remains the matching authority.
Data attempts: ordinary local option-id initialization restored the real seven-byte constant sequence; .sdata2 reached 100%. Genuine MD5 fill array emitted locally, then as an ordinary named global after the state-machine function to preserve jump-table/source order. .data remains incomplete because the three generated jump tables still differ. AES tables and round constants remain byte-identical .rodata.
Data attempt: restored the genuine request-options pointer initializer shown in target .sdata; it completed .sdata but moved the response buffer before the thread in .bss and caused objdiff .bss 100 -> 83.33333 and a matched-data regression. Tried source declaration order, original thread name, and original section-aligned network buffer declaration; none passed the regression gate. Restored the pointer attempt and kept the existing BSS layout. No artificial padding, address symbols, or forced sections retained. .sdata and .sbss remain open.
Initial AOSS trial batch failed to compile because of a mistaken message-length field name in the packet dispatcher; corrected the field and reran all trials successfully. Failed batch not counted as attempts.
AOSS_Init_old initial 28.42298%
- full-width wait counters instead of narrowing every update: 28.546717%; src 0x1758 base 0x18c0 insns 1494/1584; --- replace mine 0:1 base 0:4; M 0 stwu r1, -0x100(r1); B 0 clrlwi r11, r1, 0x1b
- packet length conversion retains full width: 28.42298%; src 0x1794 base 0x18c0 insns 1509/1584; --- replace mine 0:1 base 0:4; M 0 stwu r1, -0x100(r1); B 0 clrlwi r11, r1, 0x1b
- poll arguments given semantic socket events structure: 28.42298%; src 0x1794 base 0x18c0 insns 1509/1584; --- replace mine 0:1 base 0:4; M 0 stwu r1, -0x100(r1); B 0 clrlwi r11, r1, 0x1b
Retained best candidate
AOSS_813FFD68 initial 96.981735%
- validation loops use signed char: 93.69406%; src 0x364 base 0x36c insns 217/219; --- replace mine 3:5 base 3:7; M 3 addi r11, r1, 0x20; M 4 bl 0
- return failure immediately on invalid character: 82.05023%; src 0x2ec base 0x36c insns 187/219; --- replace mine 3:5 base 3:7; M 3 addi r11, r1, 0x20; M 4 bl 0
- ascending validation cursor loop: 94.76712%; src 0x374 base 0x36c insns 221/219; --- replace mine 3:5 base 3:7; M 3 addi r11, r1, 0x20; M 4 bl 0
Retained best candidate
AOSS_814001B4 initial 88.78481%
- converted packet length stays full width: 88.78481%; src 0x12c base 0x13c insns 75/79; --- replace mine 3:5 base 3:10; M 3 addi r11, r1, 0x20; M 4 bl 0
- direct opcode return cases: 83.27848%; src 0x124 base 0x13c insns 73/79; --- replace mine 3:5 base 3:10; M 3 addi r11, r1, 0x20; M 4 bl 0
- full-width validation and branch nesting: no source change; skipped
Retained best candidate
AOSS_814002F0 initial 79.525%
- read manufacturer only after state validation: 85.058334%; src 0x1c4 base 0x1e0 insns 113/120; --- replace mine 6:8 base 6:8; M 6 mr r30, r3; M 7 mr r26, r4
- packet sequence values remain full-width: 76.441666%; src 0x1c4 base 0x1e0 insns 113/120; --- replace mine 5:7 base 5:8; M 5 mr r30, r3; M 6 mr r26, r4
- direct address error branch: 79.525%; src 0x1c8 base 0x1e0 insns 114/120; --- replace mine 5:7 base 5:8; M 5 mr r30, r3; M 6 mr r26, r4
Retained best candidate
AOSS_81400830 initial 77.619934%
- single-byte RC4 generation loop instead of manual pairs: 65.65109%; src 0x3c0 base 0x504 insns 240/321; --- insert mine 6:6 base 6:7; B 6 addi r29, r3, 0x18; --- insert mine 7:7 base 8:9
- natural CRC byte loop: 60.13084%; src 0x3c4 base 0x504 insns 241/321; --- replace mine 5:6 base 5:7; M 5 mr r27, r3; B 5 mr r26, r3
- narrow RC4 state indices at assignment: 77.619934%; src 0x4b8 base 0x504 insns 302/321; --- insert mine 6:6 base 6:7; B 6 addi r29, r3, 0x18; --- insert mine 7:7 base 8:9
Retained best candidate
AOSS_81400E0C initial 77.52105%
- signed option lengths and iteration indices: 77.778946%; src 0x2bc base 0x2f8 insns 175/190; --- insert mine 5:5 base 5:6; B 5 mr r29, r4; --- replace mine 6:8 base 7:8
- natural integer byte decode for both address options: 44.963158%; src 0x188 base 0x2f8 insns 98/190; --- insert mine 5:5 base 5:6; B 5 mr r29, r4; --- replace mine 6:8 base 7:8
- address decode accumulation uses OR: 61.963158%; src 0x284 base 0x2f8 insns 161/190; --- replace mine 5:8 base 5:8; M 5 mr r29, r3; M 6 mr r30, r4
Retained best candidate
AOSS_814013AC initial 91.70175%
- signed option lengths: 91.70175%; src 0x1cc base 0x1c8 insns 115/114; --- insert mine 6:6 base 6:7; B 6 mr r27, r3; --- delete mine 7:8 base 8:8
- apply flags after successful parser call: 84.68421%; src 0x1ec base 0x1c8 insns 123/114; --- insert mine 6:6 base 6:7; B 6 mr r27, r3; --- delete mine 7:8 base 8:8
- bounded while loop over selected reply payload: 88.2807%; src 0x1d4 base 0x1c8 insns 117/114; --- insert mine 6:6 base 6:7; B 6 mr r27, r3; --- delete mine 7:8 base 8:8
Retained best candidate
AOSS_81401574 initial 92.558136%
- semantic payload extent expression: 92.558136%; src 0x1fc base 0x204 insns 127/129; --- replace mine 5:7 base 5:7; M 5 lwz r30, 0(0); M 6 mr r27, r4
- request length remains full-width: 92.209305%; src 0x1f8 base 0x204 insns 126/129; --- replace mine 5:7 base 5:7; M 5 lwz r30, 0(0); M 6 mr r27, r4
- initialize destination length before port conversion: 88.31783%; src 0x1fc base 0x204 insns 127/129; --- replace mine 5:7 base 5:7; M 5 lwz r30, 0(0); M 6 mr r27, r4
Retained best candidate
AOSS_81401778 initial 71.93407%
- CRC checksum stays full width until header store: 71.93407%; src 0x434 base 0x444 insns 269/273; --- replace mine 5:7 base 5:6; M 5 lis r31, 0; M 6 lwz r30, 0(0)
- signed RC4 byte loop index: 71.93407%; src 0x434 base 0x444 insns 269/273; --- replace mine 5:7 base 5:6; M 5 lis r31, 0; M 6 lwz r30, 0(0)
- copy hello payload before manufacturer encoding: 71.91575%; src 0x434 base 0x444 insns 269/273; --- replace mine 5:7 base 5:6; M 5 lis r31, 0; M 6 lwz r30, 0(0)
Retained best candidate
AOSS_81401C9C initial 71.9315%
- natural RC4 state initialization loop: 43.342464%; src 0x98 base 0x124 insns 38/73; --- replace mine 0:1 base 0:2; M 0 li r9, 0; B 0 stwu r1, -0x10(r1)
- schedule state reset before obtaining byte pointer: 71.9315%; src 0x12c base 0x124 insns 75/73; --- replace mine 0:6 base 0:2; M 0 stwu r1, -0x20(r1); M 1 mflr r0
- signed key and state indices: 71.9315%; src 0x12c base 0x124 insns 75/73; --- replace mine 0:6 base 0:2; M 0 stwu r1, -0x20(r1); M 1 mflr r0
Retained best candidate
AOSS_81401E80 initial 91.80272%
- natural XOR loop over half-packet: 56.455784%; src 0x168 base 0x24c insns 90/147; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x30(r1); B 0 stwu r1, -0x40(r1)
- half-length via signed division: 87.04082%; src 0x240 base 0x24c insns 144/147; --- replace mine 5:19 base 5:13; M 5 srawi r0, r4, 1; M 6 mr r28, r3
- count-down rounds: 88.734695%; src 0x244 base 0x24c insns 145/147; --- replace mine 6:7 base 6:7; M 6 mr r28, r3; B 6 mr r21, r3
Retained best candidate
AOSS_814020CC initial 76.066666%
- sleep tick product stays 64-bit: 67.51667%; src 0xfc base 0xf0 insns 63/60; --- replace mine 3:6 base 3:7; M 3 addi r11, r1, 0x20; M 4 bl 0
- tick duration via explicit multiply-high: 81.65%; src 0xe4 base 0xf0 insns 57/60; --- replace mine 3:5 base 3:6; M 3 addi r11, r1, 0x20; M 4 bl 0
- do-while host acquisition loop: 65.066666%; src 0xf8 base 0xf0 insns 62/60; --- replace mine 3:6 base 3:7; M 3 addi r11, r1, 0x20; M 4 bl 0
Retained best candidate
AOSS_81401DC0 initial 99.375%
- CRC output accumulator reuses incoming seed value: 99.375%; src 0xc0 base 0xc0 insns 48/48; diffs 4: [39, 41, 42, 43]; 39 M srwi r0, r3, 1; B srwi r3, r3, 1
- last CRC bit combined with conditional polynomial: 80.916664%; src 0xc8 base 0xc0 insns 50/48; --- delete mine 0:1 base 0:0; M 0 lis r3, -0x1247; --- replace mine 2:4 base 1:2
- ordinary counted loop for eight CRC polynomial steps: 24.833334%; src 0x40 base 0xc0 insns 16/48; --- insert mine 0:0 base 0:1; B 0 li r0, 0x100; --- delete mine 1:3 base 2:2
Retained best candidate
AOSS_Init_old initial 28.546717%
- network settings alignment follows target 32-byte stack contract: 24.69697%; src 0x17f8 base 0x18c0 insns 1534/1584; --- replace mine 8:9 base 8:11; M 8 li r14, 0; B 8 lhz r4, 0(0)
- request records alignment follows target stack offset a0: 24.69697%; src 0x17f8 base 0x18c0 insns 1534/1584; --- replace mine 8:9 base 8:11; M 8 li r14, 0; B 8 lhz r4, 0(0)
- both network settings and request records use observed stack alignment: 24.69697%; src 0x17f8 base 0x18c0 insns 1534/1584; --- replace mine 8:9 base 8:11; M 8 li r14, 0; B 8 lhz r4, 0(0)
Retained best candidate
AOSS_814001B4 initial 88.78481%
- opcode uses full-width switch expression after conversion: 88.78481%; src 0x12c base 0x13c insns 75/79; --- replace mine 3:5 base 3:10; M 3 addi r11, r1, 0x20; M 4 bl 0
- rejection increments written as explicit count stores: 88.78481%; src 0x12c base 0x13c insns 75/79; --- replace mine 3:5 base 3:10; M 3 addi r11, r1, 0x20; M 4 bl 0
- validation represented by a named result before rejection: 88.78481%; src 0x12c base 0x13c insns 75/79; --- replace mine 3:5 base 3:10; M 3 addi r11, r1, 0x20; M 4 bl 0
Retained best candidate
AOSS_814013AC initial 91.70175%
- outer response stride evaluated once before cursor advancement: 91.70175%; src 0x1cc base 0x1c8 insns 115/114; --- insert mine 6:6 base 6:7; B 6 mr r27, r3; --- delete mine 7:8 base 8:8
- one option cursor serves outer and inner traversal: 91.70175%; src 0x1cc base 0x1c8 insns 115/114; --- insert mine 6:6 base 6:7; B 6 mr r27, r3; --- delete mine 7:8 base 8:8
- config flags initialization delayed until matching response is located: 89.60526%; src 0x1cc base 0x1c8 insns 115/114; --- insert mine 6:6 base 6:7; B 6 mr r27, r3; --- delete mine 7:8 base 8:8
Retained best candidate
AOSS .sbss source-order reconstruction: moved real existing address/status declarations into original address order; 28.57143 -> 57.14286.
- explicit zero initialization of owned pointer globals: 42.857143%; original source restored if no improvement.
- explicit zero initialization of runtime status globals: 57.14286%; original source restored if no improvement.
- ordinary zero initialization of access-point address bytes: 28.57143%; original source restored if no improvement.
AOSS dispatch reconstruction: rejected empty/type/validation failures return immediately and opcode dispatch uses a switch; 41.518986 -> 88.78481%, 75/79 instructions. Remaining four instructions are prologue/epilogue save helpers versus individual register saves; three additional real source variations did not change them.
AOSS_Init_old has a body for every observed state path; six distinct attempts logged. Restored narrow wait counters despite a small fuzzy gain from widening, because the original performs signed 16-bit wrapping assignments. Observed 32-byte stack alignment trials all worsened codegen and were restored. Renamed existing decompiler labels to meaningful state/cleanup names.
AOSS .data/.bss/.sdata/.sdata2 remain 100%; ordinary source declaration reordering improves .sbss to 57.14286 but does not finish its symbol associations. Three normal initialization forms produced no further improvement and were restored. No forced sections, padding, address-pinning symbols, or table blobs added.
Current handoff: remaining functions and instruction evidence
ATERM_814021BC 92.77922%: src 0x274 base 0x268 insns 157/154; --- replace mine 5:8 base 5:8; M 5 lis r31, 0; M 6 li r28, 0; M 7 addi r3, r31, 0
ATERM_8140276C 94.04023%: src 0x2b0 base 0x2b8 insns 172/174; --- replace mine 5:11 base 5:13; M 5 mr r25, r3; M 6 mr r26, r4; M 7 mr r27, r5
ATERM_81402A24 76.20532%: src 0x3f4 base 0x41c insns 253/263; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x80(r1); B 0 stwu r1, -0x90(r1); --- replace mine 2:4 base 2:4
ATERM_81402E40 99.791664%: src 0x180 base 0x180 insns 96/96; diffs 4: [9, 10, 47, 52]; 9 M mr r29, r7; B mr r3, r27; 10 M mr r3, r27
ATERM_81402FC0 68.577774%: src 0x208 base 0x21c insns 130/135; --- insert mine 8:8 base 8:9; B 8 li r31, 0; --- delete mine 15:16 base 16:16; M 15 li r31, 0
ATERM_814031DC 85.90225%: src 0x1f4 base 0x214 insns 125/133; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x70(r1); B 0 stwu r1, -0x60(r1); --- replace mine 4:6 base 4:6
ATERM_814033F0 67.39416%: src 0x214 base 0x224 insns 133/137; --- replace mine 5:6 base 5:6; M 5 addi r30, r3, 8; B 5 addi r29, r3, 8; --- insert mine 7:7 base 7:8
ATERM_814036D8 87.0%: src 0x1e4 base 0x1f0 insns 121/124; --- replace mine 14:24 base 14:16; M 14 bne 36; M 15 addi r3, r25, 0; M 16 li r0, 4
ATERM_814038C8 41.043114%: src 0x9b4 base 0xedc insns 621/951; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x140(r1); B 0 stwu r1, -0x180(r1); --- replace mine 2:4 base 2:4
ATERMi_AutoConfigThread 94.75%: src 0xa0 base 0xa0 insns 40/40; diffs 3: [20, 22, 23]; 20 M nor r0, r3, r0; B nor r3, r3, r0; 22 M srawi r3, r0, 0x1f
ATERM_81404844 92.62393%: src 0x1bc base 0x1d4 insns 111/117; --- replace mine 8:13 base 8:13; M 8 mr r29, r3; M 9 mr r22, r4; M 10 mr r23, r5
ATERM_81404A18 75.82645%: src 0x1c0 base 0x1e4 insns 112/121; --- replace mine 8:13 base 8:14; M 8 mr r29, r3; M 9 mr r21, r4; M 10 mr r22, r5
ATERM_81404BFC 74.36194%: src 0x46c base 0x430 insns 283/268; --- replace mine 6:7 base 6:7; M 6 cmplwi r5, 0x80; B 6 cmpwi r5, 0x80; --- delete mine 38:40 base 38:38
ATERM_8140502C 42.355072%: src 0x280 base 0x228 insns 160/138; --- insert mine 5:5 base 5:8; B 5 stw r30, 8(r1); B 6 lis r30, 0; B 7 addi r30, r30, 0
ATERM_81405254 34.23247%: src 0x3c4 base 0x43c insns 241/271; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x40(r1); B 0 stwu r1, -0x50(r1); --- replace mine 2:4 base 2:4
ATERM_81405690 34.64945%: src 0x3d4 base 0x43c insns 245/271; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x40(r1); B 0 stwu r1, -0x50(r1); --- replace mine 2:4 base 2:4
ATERM_81405ACC 55.54861%: src 0x21c base 0x240 insns 135/144; --- insert mine 2:2 base 2:3; B 2 slwi r7, r5, 3; --- replace mine 3:7 base 4:10; M 3 addi r11, r1, 0x20
ATERM_81405D0C 53.851387%: src 0xa50 base 0xb40 insns 660/720; --- replace mine 0:1 base 0:1; M 0 stwu r1, -0x90(r1); B 0 stwu r1, -0xa0(r1); --- replace mine 2:4 base 2:4
ATERMi_ApConfigStart 93.718445%: src 0x1a0 base 0x19c insns 104/103; --- delete mine 4:5 base 4:4; M 4 mr r31, r3; --- replace mine 6:7 base 5:6; M 6 mr r30, r8
ATERMi_ApConfigEnd 87.54263%: src 0x1dc base 0x204 insns 119/129; --- replace mine 3:5 base 3:7; M 3 addi r11, r1, 0xe0; M 4 bl 0; B 3 stw r31, 0xdc(r1)
ATERMi_ApConfigGetState 99.42857%: src 0x8c base 0x8c insns 35/35; diffs 3: [17, 18, 20]; 17 M lwz r6, 0xf8(r6); B lwz r0, 0xf8(r6); 18 M addi r0, r5, 0x4dd3
AOSS_Init_old 28.42298%: src 0x1794 base 0x18c0 insns 1509/1584; --- replace mine 0:1 base 0:4; M 0 stwu r1, -0x100(r1); B 0 clrlwi r11, r1, 0x1b; B 1 mr r12, r1
AOSS_813FFD68 96.981735%: src 0x364 base 0x36c insns 217/219; --- replace mine 3:5 base 3:7; M 3 addi r11, r1, 0x20; M 4 bl 0; B 3 stw r31, 0x1c(r1)
AOSS_814001B4 88.78481%: src 0x12c base 0x13c insns 75/79; --- replace mine 3:5 base 3:10; M 3 addi r11, r1, 0x20; M 4 bl 0; B 3 stw r31, 0x1c(r1)
AOSS_814002F0 85.058334%: src 0x1c4 base 0x1e0 insns 113/120; --- replace mine 6:8 base 6:8; M 6 mr r30, r3; M 7 mr r26, r4; B 6 mr r26, r3
AOSS_81400830 77.619934%: src 0x4b8 base 0x504 insns 302/321; --- insert mine 6:6 base 6:7; B 6 addi r29, r3, 0x18; --- insert mine 7:7 base 8:9; B 8 li r5, 8
AOSS_81400E0C 77.778946%: src 0x2bc base 0x2f8 insns 175/190; --- insert mine 5:5 base 5:6; B 5 mr r29, r4; --- replace mine 6:8 base 7:8; M 6 mr r29, r4
AOSS_814013AC 91.70175%: src 0x1cc base 0x1c8 insns 115/114; --- insert mine 6:6 base 6:7; B 6 mr r27, r3; --- delete mine 7:8 base 8:8; M 7 mr r27, r3
AOSS_81401574 92.558136%: src 0x1fc base 0x204 insns 127/129; --- replace mine 5:7 base 5:7; M 5 lwz r30, 0(0); M 6 mr r27, r4; B 5 lwz r27, 0(0)
AOSS_81401778 71.93407%: src 0x434 base 0x444 insns 269/273; --- replace mine 5:7 base 5:6; M 5 lis r31, 0; M 6 lwz r30, 0(0); B 5 lwz r28, 0(0)
AOSS_81401C9C 71.9315%: src 0x12c base 0x124 insns 75/73; --- replace mine 0:6 base 0:2; M 0 stwu r1, -0x20(r1); M 1 mflr r0; M 2 stw r0, 0x24(r1)
AOSS_81401DC0 99.375%: src 0xc0 base 0xc0 insns 48/48; diffs 4: [39, 41, 42, 43]; 39 M srwi r0, r3, 1; B srwi r3, r3, 1; 41 M xoris r0, r0, 0xedb8
AOSS_81401E80 91.80272%: src 0x244 base 0x24c insns 145/147; --- replace mine 6:7 base 6:7; M 6 mr r28, r3; B 6 mr r21, r3; --- replace mine 8:20 base 8:13
AOSS_814020CC 81.65%: src 0xe4 base 0xf0 insns 57/60; --- replace mine 3:5 base 3:6; M 3 addi r11, r1, 0x20; M 4 bl 0; B 3 stw r31, 0x1c(r1)
Supplemental native crypto validation: NIST AES-128/192/256 encrypt/decrypt vectors passed; MD5 lengths 0, 1, 3, 55, 56, 64, 130 and streaming chunks 1, 7, 55, 63, 64, 65, 127 over 512 bytes passed against hashlib. RFC3394 wrap/unwrap passed using a temporary native test copy that explicitly emulates Wii big-endian counter bytes; unchanged x86 union byte order does not emulate the target. Tests reside under /tmp; MWCC object and gate remain matching authority.

View File

@@ -1,12 +1,11 @@
# Assembly inventory
4.3U, 2026-10-09. 165 functions contain 167 assembly
bodies/blocks: 162 ORIGINAL functions and 3 PLACEHOLDER functions.
4.3U, 2026-10-09. 162 functions contain 164 assembly
bodies/blocks: 162 ORIGINAL functions and 0 PLACEHOLDER functions.
Run `python3 tools/check_asm_inventory.py`. Completion requires exit 0, complete
coverage and zero placeholders. The checker also rejects stale/duplicate rows,
invalid classifications and syntax it cannot inspect. This audit supersedes the
historical inventory in `tools/decomp-assist/asm-inventory.md`.
invalid classifications and syntax it cannot inspect.
Scope: C/C++ sources and headers in `src/` and `libs/`, including inactive
platform branches, plus standalone assembly there or referenced by
@@ -21,8 +20,7 @@ The rvl_dec family follows the original decoder convention specified for this
audit; ASH/ASR also show unsigned `lis @h`/`ori @l` address construction and
hand-built `stmw` frames. C scores below are recorded rejected trials, not fresh
measurements or scores of the retained assembly. Unrecorded means no C score was
found. Historical logs absent from this branch have commit IDs and excerpts in
[the audit log](../tools/decomp-assist/rx36.attempts.md).
found. Historical audit logs are in git history.
| File | Function | Classification | Evidence |
| --- | --- | --- | --- |
@@ -37,7 +35,6 @@ found. Historical logs absent from this branch have commit IDs and excerpts in
| `libs/NW4R/include/nw4r/math/types.h` | `VEC3Scale` | ORIGINAL | psq_l/ps_muls0/psq_st implements paired-single vector/matrix operations. |
| `libs/NW4R/src/math/math_arithmetic.cpp` | `FrSqrt` | ORIGINAL | frsqrte plus fixed refinement matches the public [NW4R arithmetic assembly][arithmetic-cpp]. |
| `libs/NW4R/src/math/math_types.cpp` | `MTX44Identity` | ORIGINAL | psq_st/ps_merge01/ps_merge10 implements paired-single vector/matrix operations. |
| `libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jdec_main.c` | `TMCJPEGDEC_err_restart` | PLACEHOLDER | JPEG marker scan; best C 95.73913%, 114/115 instructions, folded exit branch, [rx19](../tools/decomp-assist/rx19.attempts.md), [rx24][rx24]. |
| `libs/RVL_SDK/include/revolution/os/OSFastCast.h` | `OSInitFastCast` | ORIGINAL | mtspr programs the GQR quantization registers. |
| `libs/RVL_SDK/include/revolution/os/OSFastCast.h` | `__OSu16tof32` | ORIGINAL | psq_l uses a GQR integer conversion format for the fast cast. |
| `libs/RVL_SDK/include/revolution/os/OSFastCast.h` | `__OSf32tou8` | ORIGINAL | psq_st uses a GQR integer conversion format for the fast cast. |
@@ -88,7 +85,6 @@ found. Historical logs absent from this branch have commit IDs and excerpts in
| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCSetFpIEEEMode` | ORIGINAL | Special-register or synchronization operation: `mtfsb0 FPSCR_NI_BIT`. |
| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCSetFpNonIEEEMode` | ORIGINAL | Special-register or synchronization operation: `mtfsb1 FPSCR_NI_BIT`. |
| `libs/RVL_SDK/src/base/PPCArch.c` | `PPCMthid4` | ORIGINAL | Both branches write HID4 with mtspr; the fallback preserves the Broadway H4A bit. |
| `libs/RVL_SDK/src/cntcache/cntcache.c` | `CNTCACHEClear` | PLACEHOLDER | NAND/token logic; best C 47/151 differing, 149/151 instructions; pool solved with stripped writer literals, two post-delete compares missing, [rx30][rx30], [opus-cntc](../tools/decomp-assist/opus-cntc.attempts.md). |
| `libs/RVL_SDK/src/db/db.c` | `__DBExceptionDestination` | ORIGINAL | mfmsr/mtmsr enable address translation before the exception-handler tail branch. |
| `libs/RVL_SDK/src/gx/GXLight.c` | `PushLight` | ORIGINAL | psq_l/psq_st transfers paired-single values for the GX command stream. |
| `libs/RVL_SDK/src/gx/GXTransform.c` | `WriteProjPS` | ORIGINAL | psq_l/psq_st transfers paired-single values for the GX command stream. |
@@ -186,16 +182,11 @@ found. Historical logs absent from this branch have commit IDs and excerpts in
| `src/BS2/BS2Start.c` | `__start` | ORIGINAL | Runs before the C stack and ABI registers exist; constructs the initial stack. |
| `src/BS2/BS2Start.c` | `__init_registers` | ORIGINAL | Initializes GPRs, r1, r2, and r13 for the C runtime. |
| `src/scene/nakamuraTest/gamespy/common/gsPlatformUtil.c` | `GetTicks` | ORIGINAL | Inactive PS2 branch reads the CP0 Count register with mfc0 $9. |
| `src/system/iplSystem.cpp` | `System::warning_run` | PLACEHOLDER | Scene/render calls; best C 98.66477%, 176/176 instructions, 47 saved-register differences, [rx17][rx17]. |
| `src/system/rvl_dec.c` | `Rvl_decode` | ORIGINAL | Direct beq decoder entries preserve r3/r4 and LR; lis/ori builds the format signatures. |
| `src/system/rvl_dec.c` | `Rvl_decode_szs` | ORIGINAL | Original SZS decoder convention: nofralloc, r0 retains output length, fixed r3..r10/CTR byte-copy pipeline. |
| `src/system/rvl_dec.c` | `Rvl_decode_ash` | ORIGINAL | nofralloc hand-built 0x40 frame saves r21..31 with stmw; work address uses lis @h/ori @l. |
| `src/system/rvl_dec.c` | `Rvl_decode_asr` | ORIGINAL | nofralloc hand-built 0x40 frame saves r21..31 with stmw; work address uses lis @h/ori @l. |
[rx17]: ../tools/decomp-assist/rx36.attempts.md#rx17
[rx24]: ../tools/decomp-assist/rx36.attempts.md#rx24
[rx30]: ../tools/decomp-assist/rx36.attempts.md#rx30
[rx36-osinit]: ../tools/decomp-assist/rx36.attempts.md#osinit
[sdk-init]: https://github.com/doldecomp/ogws/blob/master/src/revolution/OS/__ppc_eabi_init.c
[runtime]: https://github.com/doldecomp/ogws/blob/master/src/runtime/runtime.c
[arithmetic-h]: https://github.com/doldecomp/ogws/blob/master/include/nw4r/math/math_arithmetic.h

View File

@@ -19,7 +19,7 @@ extern "C" {
#define CHANS_VM_CLASS_NAME_LEN 32
CHANSVmErr CHANSVmInit(CHANSVm* vm, vmPtr work, vmU32 size);
CHANSVmErr CHANSVmLinkModules(CHANSVm* vm, vmS32 unk0);
CHANSVmErr CHANSVmLinkModules(CHANSVm* vm, vmS32 reserved);
void CHANSVmSetSignal(CHANSVm* vm, vmBool* signal);
@@ -30,7 +30,7 @@ void CHANSVmSetSignal(CHANSVm* vm, vmBool* signal);
vmU32 CHANSVmGetFreeExeSize(CHANSVm* vm);
vmPtr CHANSVmGetFreeExeBufp(CHANSVm* vm);
CHANSVmErr CHANSVmAddExe(CHANSVm* vm, vmS32 unk0, CHANSVm* execCtx);
CHANSVmErr CHANSVmAddExe(CHANSVm* vm, vmS32 reserved, CHANSVm* execCtx);
CHANSVmErr CHANSVmStep(CHANSVm* vm, int stepCount);

View File

@@ -10,7 +10,7 @@ namespace ipl {
volatile u16 size; // 0x02
u8 canCopy; // 0x04
u8 canMove; // 0x05
u16 unk_0x06; // 0x06
u16 transferBlocked; // 0x06
u32 key; // 0x08
} FileInfo; // 0x0C
@@ -21,21 +21,21 @@ namespace ipl {
vu16 reservedSlot; // 0x04
vu16 reservedCommand; // 0x06
vu32 key; // 0x08
vu16 unk_0x0C; // 0x0C
vu16 unk_0x0E; // 0x0E
vu16 totalBlocks; // 0x0C
vu16 freeFiles; // 0x0E
vu16 freeBlocks; // 0x10
vu16 unk_0x12; // 0x12
vu16 titleBlocks; // 0x12
} CardState; // 0x14
typedef struct IconState {
volatile u8 bannerEnable; // 0x00
u8 unk_0x01; // 0x01
u8 unk_0x02; // 0x02
u8 iconEnable; // 0x01
u8 iconCount; // 0x02
u8 bannerType; // 0x03
s8 anmDelta; // 0x04
u8 anmType; // 0x05
u8 unk_0x06; // 0x06
u8 unk_0x07; // 0x07
u8 anmFirstFrameDuration; // 0x06
u8 anmLastFrameDuration; // 0x07
u8 iconFmt[8]; // 0x08
#ifdef IPL_MEMORY_CARD_MANAGER_CPP
volatile u16 anmFrameBits;

View File

@@ -190,6 +190,7 @@ namespace ipl {
PointerCore mCore; // 0x40
friend class System;
friend class PointerCoreObject;
friend class PointerCore;
friend class utility::BScroller;

View File

@@ -55,7 +55,7 @@ namespace ipl {
void init() {
mState = 0;
mScroll = 0.0f;
unk_0x3C = 0.0f;
mScrollVelocity = 0.0f;
mUpLimit = 0.0f;
mDownLimit = 0.0f;
}
@@ -92,7 +92,7 @@ namespace ipl {
int mState; // 0x30
f32 mDownLimit; // 0x34
f32 mUpLimit; // 0x38
f32 unk_0x3C;
f32 mScrollVelocity;
f32 mScroll; // 0x40
f32 mButtonScrollOrigin;
f32 mVelocityDecay;

View File

@@ -4,7 +4,7 @@
#include <nw4r/snd.h>
#include <revolution/os.h>
#pragma sym on
namespace EGG {
ArcPlayer::ArcPlayer(nw4r::snd::SoundHeap* pHeap) : mpSoundHeap(pHeap) {
mStorage = SARC_STORAGE_NONE;

View File

@@ -74,8 +74,7 @@ namespace EGG {
return MEMAllocFromFrmHeapEx(mHeapHandle, size, align);
}
void FrmHeap::free(void* ptr) {
#pragma unused(ptr)
void FrmHeap::free(void*) {
}
u32 FrmHeap::resizeForMBlock(void* ptr, u32 size) {

View File

@@ -36,8 +36,6 @@ namespace EGG {
}
void* Heap::alloc(u32 size, int align, Heap* heap) {
void* ptr = NULL;
if (sAllocatableHeap != NULL) {
if (sCurrentHeap != NULL && heap == NULL) {
heap = sCurrentHeap;
@@ -53,13 +51,7 @@ namespace EGG {
}
if (sCurrentHeap != NULL) {
ptr = sCurrentHeap->alloc(size, align);
if (ptr == NULL) {
// stripped out EGG_PRINT
}
return ptr;
return sCurrentHeap->alloc(size, align);
}
return NULL;
@@ -170,7 +162,7 @@ void* operator new[](size_t size, EGG::Heap* heap, int align) {
void operator delete(void* ptr) {
EGG::Heap::free(ptr, NULL);
// don't inline. (NO_INLINE did not want to work)
// MWCC needs these no-op statements to keep operator delete out of Heap's destructor.
(void)0;
(void)0;
(void)0;

View File

@@ -18,29 +18,29 @@ namespace nw4r {
inline u32 CalcOffsetSheetData(u16 countNames) {
return ROUNDUP(CalcOffsetNameOffsetData() + countNames * sizeof(u16), 4);
}
inline u32 CalcOffset0AData(u16 countNames, u16 countSheets) {
inline u32 CalcOffsetCWDHData(u16 countNames, u16 countSheets) {
return ROUNDUP(CalcOffsetSheetData(countNames) + countSheets * sizeof(u32), 4);
}
inline u32 CalcOffset0CData(u16 countNames, u16 countSheets, u16 count0A) {
return ROUNDUP(CalcOffset0AData(countNames, countSheets) + count0A * sizeof(u32), 4);
inline u32 CalcOffsetCMAPData(u16 countNames, u16 countSheets, u16 countCWDH) {
return ROUNDUP(CalcOffsetCWDHData(countNames, countSheets) + countCWDH * sizeof(u32), 4);
}
inline u32 CalcSizeFlagSet(u32 entries) {
return ((s32)entries + 0x1f) / 32 * 4;
}
inline u32 CalcOffsetSheetFlags(u16 countNames, u16 countSheets, u16 count0A, u16 count0C) {
return ROUNDUP(CalcOffset0CData(countNames, countSheets, count0A) + count0C * sizeof(u32), 4);
inline u32 CalcOffsetSheetFlags(u16 countNames, u16 countSheets, u16 countCWDH, u16 countCMAP) {
return ROUNDUP(CalcOffsetCMAPData(countNames, countSheets, countCWDH) + countCMAP * sizeof(u32), 4);
}
inline u32 CalcOffset0AFlags(u16 countNames, u16 countSheets, u16 count0A, u16 count0C) {
u32 offsetSheetFlags = CalcOffsetSheetFlags(countNames, countSheets, count0A, count0C);
inline u32 CalcOffsetCWDHFlags(u16 countNames, u16 countSheets, u16 countCWDH, u16 countCMAP) {
u32 offsetSheetFlags = CalcOffsetSheetFlags(countNames, countSheets, countCWDH, countCMAP);
u32 stepSheet = CalcSizeFlagSet(countSheets);
return ROUNDUP(offsetSheetFlags + stepSheet * countNames, 4);
}
inline u32 CalcOffset0CFlags(u16 countNames, u16 countSheets, u16 count0A, u16 count0C) {
u32 offset0AFlags = CalcOffset0AFlags(countNames, countSheets, count0A, count0C);
u32 step0A = CalcSizeFlagSet(count0A);
return ROUNDUP(offset0AFlags + step0A * countNames, 4);
inline u32 CalcOffsetCMAPFlags(u16 countNames, u16 countSheets, u16 countCWDH, u16 countCMAP) {
u32 offsetCWDHFlags = CalcOffsetCWDHFlags(countNames, countSheets, countCWDH, countCMAP);
u32 stepCWDH = CalcSizeFlagSet(countCWDH);
return ROUNDUP(offsetCWDHFlags + stepCWDH * countNames, 4);
}
inline u32 CalcSizeSheetOffsets(u32 countSheets) {

View File

@@ -92,8 +92,8 @@ namespace nw4r {
u16 sheetGlyphCount; // 0x04
u16 nameCount; // 0x06
u16 sheetCount; // 0x08
u16 smthCount_0x0a; // 0x0A
u16 smthCount_0x0c; // 0x0C
u16 cwdhCount; // 0x0A
u16 cmapCount; // 0x0C
u16 nameOffsets[0];
} GlyphGroups;

View File

@@ -207,56 +207,50 @@ namespace nw4r {
}
static void DoDrawConsole_(ConsoleHandle console, ut::TextWriter* writer) {
{
s32 viewOffset;
u16 line;
u16 printLines;
s32 viewOffset;
u16 line;
u16 printLines;
viewOffset = console->viewTopLine - console->ringTopLineCnt;
printLines = 0;
viewOffset = console->viewTopLine - console->ringTopLineCnt;
printLines = 0;
if (viewOffset < 0) {
viewOffset = 0;
} else if (viewOffset > GetActiveLines_(console)) {
goto end;
}
line = static_cast<u16>(console->ringTop + viewOffset);
if (line >= console->height) {
line -= console->height;
}
while (true) {
if (line == console->printTop && !console->printTopUsed) {
goto end;
}
DoDrawString_(console, printLines, GetTextPtr_(console, line, 0), writer);
printLines++;
if (line == console->printTop) {
goto end;
}
line++;
if (line == console->height) {
if (console->attr & (1 << 1)) {
goto end;
}
line = 0;
}
if (printLines >= console->viewLines) {
goto end;
}
}
if (viewOffset < 0) {
viewOffset = 0;
} else if (viewOffset > GetActiveLines_(console)) {
return;
}
// maybe not, with this end label?
end:
return;
line = static_cast<u16>(console->ringTop + viewOffset);
if (line >= console->height) {
line -= console->height;
}
while (true) {
if (line == console->printTop && !console->printTopUsed) {
break;
}
DoDrawString_(console, printLines, GetTextPtr_(console, line, 0), writer);
printLines++;
if (line == console->printTop) {
break;
}
line++;
if (line == console->height) {
if (console->attr & (1 << 1)) {
break;
}
line = 0;
}
if (printLines >= console->viewLines) {
break;
}
}
}
void Console_DrawDirect(ConsoleHandle console) {

View File

@@ -108,7 +108,7 @@ namespace {
} else if (operation == ut::OPERATION_CHAR_SPACE) {
bCharSpace = true;
} else if (operation == ut::OPERATION_NEXT_LINE) {
goto end_draw;
break;
}
} else {
if (bCharSpace) {
@@ -128,12 +128,11 @@ namespace {
if (pRect->GetWidth() > maxWidth) {
*pbOver = true;
goto end_draw;
break;
}
}
}
end_draw:
if (*pbOver && prStrPos) {
*pRect = prMaxRect;
return prStrPos - str;
@@ -223,7 +222,7 @@ namespace nw4r {
} else if (void* fontRes = resBlockSet.pResAccessor->GetResource('font', fontName, NULL)) {
if (void* pMemFont = Layout::AllocMemory(sizeof(ut::ResFont))) {
ut::ResFont* pResFont = new (pMemFont) ut::ResFont();
bool bSuccess = pResFont->SetResource(fontRes);
pResFont->SetResource(fontRes);
mpFont = pResFont;
mTextBoxFlag.allocFont = true;

View File

@@ -18,14 +18,15 @@ extern "C" const u8 scLytFatalColorA;
extern "C" char scLytFatalMsg[];
#undef NW4R_ASSERT
#define NW4R_GLOBAL_ASSERT(x) \
{ \
if (!(x)) { \
GXColor front = {*((volatile const u8*)&::scLytFatalColorR), *((volatile const u8*)&::scLytFatalColorG), \
*((volatile const u8*)&::scLytFatalColorB), *((volatile const u8*)&::scLytFatalColorA)}; \
GXColor back = {0, 0, 0, 0}; \
OSFatal(front, back, ::scLytFatalMsg); \
} \
// MWCC needs byte loads from the named color constants instead of folding their values.
#define NW4R_GLOBAL_ASSERT(x) \
{ \
if (!(x)) { \
GXColor front = {*((volatile const u8*)&::scLytFatalColorR), *((volatile const u8*)&::scLytFatalColorG), \
*((volatile const u8*)&::scLytFatalColorB), *((volatile const u8*)&::scLytFatalColorA)}; \
GXColor back = {0, 0, 0, 0}; \
OSFatal(front, back, ::scLytFatalMsg); \
} \
}
#define NW4R_ASSERT(x) \

View File

@@ -20,25 +20,24 @@ namespace nw4r {
const HeaderedGlyphGroups* pGlgr;
const ArchiveFontBinaryLayout* font;
u16 countName, countSheet, count0A, count0C;
u16 countName, countSheet, countCWDH, countCMAP;
u32 stepSheets, step0A, step0C;
u32 stepSheets, stepCWDH, stepCMAP;
u32 dataSheetsOff, data0AOff, data0COff;
const u32* dataSheets;
const u32* data0A;
const u32* data0C;
u32 dataSheetsOff, dataCWDHOff, dataCMAPOff;
const u32* dataCWDH;
const u32* dataCMAP;
u32 flagsSheetsOff, flags0AOff, flags0COff;
u32 flagsSheetsOff, flagsCWDHOff, flagsCMAPOff;
const u32* flagsSheets;
const u32* flags0A;
const u32* flags0C;
const u32* flagsCWDH;
const u32* flagsCMAP;
int i;
int entryI;
const HeaderedGlyphGroups* offsetPGlgr;
const HeaderedGlyphGroups* groupHeaderCursor;
const u8* offsetFlags;
u32 loadedSheetCount, loadedSmth0ASize, loadedSmth0CSize;
u32 loadedSheetCount, loadedCWDHSize, loadedCMAPSize;
u32 flagWord;
const char* groupName;
const u32* offsetData;
@@ -49,11 +48,10 @@ namespace nw4r {
u32 neededCharacterSize;
u32 baseSize;
u32 count0CWork;
// MWCC needs this widened CMAP count for the original temporary allocation.
u32 cmapCountForLayout;
u32& neededCharacterSizeRef = neededCharacterSize;
u32 loadedSizeRef;
u32 loadedCharacterSize;
u32 groupOffset;
@@ -61,46 +59,45 @@ namespace nw4r {
return 0;
}
font = (ArchiveFontBinaryLayout*)fontData;
font = static_cast<const ArchiveFontBinaryLayout*>(fontData);
pGlgr = &font->glgr;
countName = pGlgr->inner.nameCount;
countSheet = pGlgr->inner.sheetCount;
count0A = pGlgr->inner.smthCount_0x0a;
count0C = pGlgr->inner.smthCount_0x0c;
count0CWork = count0C;
countCWDH = pGlgr->inner.cwdhCount;
countCMAP = pGlgr->inner.cmapCount;
cmapCountForLayout = countCMAP;
stepSheets = ((s32)countSheet + 0x1f) / 32 * 4;
step0A = ((s32)count0A + 0x1f) / 32 * 4;
step0C = ((s32)count0CWork + 0x1f) / 32 * 4;
stepCWDH = ((s32)countCWDH + 0x1f) / 32 * 4;
stepCMAP = ((s32)cmapCountForLayout + 0x1f) / 32 * 4;
dataSheetsOff = ROUNDUP(offsetof(ArchiveFontBinaryLayout, glgr.inner.nameOffsets) + countName * sizeof(u16), 4);
data0AOff = ROUNDUP(dataSheetsOff + countSheet * sizeof(u32), 4);
data0COff = ROUNDUP(data0AOff + count0A * sizeof(u32), 4);
dataSheets = (const u32*)(dataSheetsOff + (u32)fontData);
data0A = (const u32*)(data0AOff + (u32)fontData);
data0C = (const u32*)(data0COff + (u32)fontData);
dataCWDHOff = ROUNDUP(dataSheetsOff + countSheet * sizeof(u32), 4);
dataCMAPOff = ROUNDUP(dataCWDHOff + countCWDH * sizeof(u32), 4);
dataCWDH = (const u32*)(dataCWDHOff + (u32)fontData);
dataCMAP = (const u32*)(dataCMAPOff + (u32)fontData);
flagsSheetsOff = ROUNDUP(data0COff + count0CWork * sizeof(u32), 4);
flags0AOff = ROUNDUP(flagsSheetsOff + stepSheets * countName, 4);
flags0COff = ROUNDUP(flags0AOff + step0A * countName, 4);
flagsSheetsOff = ROUNDUP(dataCMAPOff + cmapCountForLayout * sizeof(u32), 4);
flagsCWDHOff = ROUNDUP(flagsSheetsOff + stepSheets * countName, 4);
flagsCMAPOff = ROUNDUP(flagsCWDHOff + stepCWDH * countName, 4);
flagsSheets = (const u32*)(flagsSheetsOff + (u32)fontData);
flags0A = (const u32*)(flags0AOff + (u32)fontData);
flags0C = (const u32*)(flags0COff + (u32)fontData);
flagsCWDH = (const u32*)(flagsCWDHOff + (u32)fontData);
flagsCMAP = (const u32*)(flagsCMAPOff + (u32)fontData);
loadedSheetCount = 0;
loadedSmth0ASize = 0;
loadedSmth0CSize = 0;
loadedCWDHSize = 0;
loadedCMAPSize = 0;
// Get the NUMBER of sheets that should be loaded
for (i = 0, entryI = 0; entryI < pGlgr->inner.sheetCount; entryI += 0x20, i++) {
offsetFlags = (const u8*)flagsSheets + i * sizeof(u32);
flagWord = 0;
for (j = 0, offsetPGlgr = pGlgr; j < pGlgr->inner.nameCount;
offsetPGlgr = (const HeaderedGlyphGroups*)((const u8*)offsetPGlgr + 2), j++) {
groupName = (const char*)((u32)offsetPGlgr->inner.nameOffsets[0] + (u32)fontData);
// MWCC needs the header as the induction base for the name-offset loads.
for (j = 0, groupHeaderCursor = pGlgr; j < pGlgr->inner.nameCount;
groupHeaderCursor = (const HeaderedGlyphGroups*)((const u8*)groupHeaderCursor + 2), j++) {
groupName = (const char*)((u32)groupHeaderCursor->inner.nameOffsets[0] + (u32)fontData);
if (*includedGroups == '\0' || detail::ArchiveFontBase::IncludeName(includedGroups, groupName)) {
flagWord |= *(const u32*)(offsetFlags + ROUNDDOWN(j * stepSheets, 4));
}
@@ -108,60 +105,52 @@ namespace nw4r {
loadedSheetCount += math::CntBit1(flagWord);
}
// getLoadedSheetCount(pGlgr, flagsSheets, stepSheets, fontData, includedGroups, &loadedSheetCount);
// Get the SIZE of unk_0x0a that should be loaded
for (i = 0; i * 32 < pGlgr->inner.smthCount_0x0a; i++) {
offsetFlags = (const u8*)flags0A + i * sizeof(u32);
for (i = 0; i * 32 < pGlgr->inner.cwdhCount; i++) {
offsetFlags = (const u8*)flagsCWDH + i * sizeof(u32);
flagWord = 0;
for (j = 0; j < pGlgr->inner.nameCount; j++) {
groupOffset = pGlgr->inner.nameOffsets[j];
groupName = (const char*)(groupOffset + (u32)fontData);
if (*includedGroups == '\0' || detail::ArchiveFontBase::IncludeName(includedGroups, groupName)) {
flagWord |= *(const u32*)(offsetFlags + ROUNDDOWN(j * step0A, 4));
flagWord |= *(const u32*)(offsetFlags + ROUNDDOWN(j * stepCWDH, 4));
}
}
offsetData = data0A + i * 32;
offsetData = dataCWDH + i * 32;
for (j = 0; j < 32; j++) {
if ((flagWord << j) & 0x80000000U) {
loadedSmth0ASize += offsetData[j] - sizeof(BinaryBlockHeader);
loadedCWDHSize += offsetData[j] - sizeof(BinaryBlockHeader);
}
}
}
// Get the SIZE of unk_0x0C that should be loaded
for (i = 0; i * 32 < pGlgr->inner.smthCount_0x0c; i++) {
offsetFlags = (const u8*)flags0C + i * sizeof(u32);
for (i = 0; i * 32 < pGlgr->inner.cmapCount; i++) {
offsetFlags = (const u8*)flagsCMAP + i * sizeof(u32);
flagWord = 0;
for (j = 0; j < pGlgr->inner.nameCount; j++) {
groupOffset = pGlgr->inner.nameOffsets[j];
groupName = (const char*)(groupOffset + (u32)fontData);
if (*includedGroups == '\0' || detail::ArchiveFontBase::IncludeName(includedGroups, groupName)) {
flagWord |= *(const u32*)(offsetFlags + ROUNDDOWN(j * step0C, 4));
flagWord |= *(const u32*)(offsetFlags + ROUNDDOWN(j * stepCMAP, 4));
}
}
offsetData = data0C + i * 32;
offsetData = dataCMAP + i * 32;
for (j = 0; j < 32; j++) {
if ((flagWord << j) & 0x80000000U) {
loadedSmth0CSize += offsetData[j] - sizeof(BinaryBlockHeader);
loadedCMAPSize += offsetData[j] - sizeof(BinaryBlockHeader);
}
}
}
// Calculate the final buffer size based on the three previously
// accessed components
sheetOffsetsSize = ROUNDUP(pGlgr->inner.sheetCount * 2, 4);
loadedSheetsSize = ROUNDUP(loadedSheetCount * pGlgr->inner.uncompSheetSize, 4);
loadedSizeRef = loadedSmth0ASize + loadedSmth0CSize;
neededCharacterSizeRef = sizeof(CXUncompContextHuffman);
if (loadedSizeRef >= sizeof(CXUncompContextHuffman)) {
neededCharacterSize = loadedSizeRef;
}
loadedCharacterSize = loadedCWDHSize + loadedCMAPSize;
neededCharacterSize = ut::Max<u32>(loadedCharacterSize, sizeof(CXUncompContextHuffman));
baseSize = OSRoundUp32B(sizeof(FontInformation) + sizeof(FontTextureGlyph) + sheetOffsetsSize);
return (baseSize + loadedSheetsSize) + neededCharacterSize;

View File

@@ -74,16 +74,6 @@ namespace nw4r {
}
}
// u32 ArchiveFontBase::ConstructContext::updateTextureBlockPtr() {
// u32 imgDataOffset;
// imgDataOffset = (u32)pFontInfo->pGlyph->sheetImage;
// pWorkCurr = (u8*)ROUNDUP((u32)pWorkCurr, 0x20);
// pFontInfo->pGlyph->sheetImage = pWorkCurr;
// return imgDataOffset;
// }
ArchiveFontBase::ArchiveFontBase() : pSheetOffsets(NULL) {
}
@@ -126,24 +116,6 @@ namespace nw4r {
return false;
}
// Check that there is nothing but spaces between the substr
// and the preceeding comma
// - Fails:
// - groupList = "foo, BAD bar, baz"
// - substr ^
// - Succeeds:
// - groupList = "foo, bar, baz"
// - substr ^
// - Succeeds:
// - groupList = "foo,bar,baz"
// - substr ^
// - Succeeds:
// - groupList = "foo,bar,baz"
// - substr ^
// - Fails (I think this is a bug):
// - groupList = " foo, bar, baz"
// - substr ^
// @bug Should allow for leading spaces in groupList (maybe?)
if (substr != groupList) {
const char* backsearchStr = substr - 1;
while (backsearchStr > groupList && *backsearchStr == ' ') {
@@ -154,11 +126,6 @@ namespace nw4r {
}
}
// Get the length of the section up until the next comma or
// the end
// - substr = "foo bar, baz" -> sectionLen = 7
// - substr = "foo , baz" -> sectionLen = 11
// - substr = "foo" -> sectionLen = 3
const char* nextComma = strchr(substr, ',');
u32 sectionLen;
if (nextComma != NULL) {
@@ -167,17 +134,6 @@ namespace nw4r {
sectionLen = strlen(substr);
}
// Check to make sure there is nothing except spaces between
// the end of the group name and the next comma:
// - Fails:
// - substr = "foo bar, baz"
// - group = "foo"
// - Succeeds:
// - substr = "foo , baz"
// - group = "foo"
// - Succeeds:
// - substr = "foo, baz"
// - group = "foo"
const char* sectionEnd = substr + groupLen;
while (sectionEnd < substr + sectionLen && (*sectionEnd == ' ')) {
sectionEnd++;
@@ -313,11 +269,6 @@ namespace nw4r {
ctx->pSheetOffsets = (u16*)sheetOffsets;
}
// inline u32 getOffsetSize(void* fontData, u32 remWorkSpace, u16 countSheet, u16** sheetOffsetsScratch) {
// u32 sheetOffsetsSize = ROUNDUP(countSheet * sizeof(u16), 4);
// *sheetOffsetsScratch = (u16*)ROUNDDOWN((u32)((u8*)fontData + remWorkSpace) - sheetOffsetsSize, 2);
// return sheetOffsetsSize;
// }
class FontGlyphGroupsAcs {
public:
explicit FontGlyphGroupsAcs(const ArchiveFontBinaryLayout* font)
@@ -393,8 +344,8 @@ namespace nw4r {
dataBlockCount = font->hdr.dataBlocks;
countSheet = gg.GetNumSheet();
const u32 stepSheetFlags = detail::CalcSizeFlagSet(countSheet);
flagsSheetsOff = detail::CalcOffsetSheetFlags(gg.GetGroups().nameCount, countSheet, gg.GetGroups().smthCount_0x0a,
gg.GetGroups().smthCount_0x0c);
flagsSheetsOff = detail::CalcOffsetSheetFlags(gg.GetGroups().nameCount, countSheet, gg.GetGroups().cwdhCount,
gg.GetGroups().cmapCount);
flagsSheets = (const u32*)((flagsSheetsOff & ~3) + (u32)font);
gg.SetSheetFlags(stepSheetFlags, flagsSheets);

View File

@@ -343,7 +343,7 @@ void RFLSetExpression(RFLCharModel* charModel, RFLExpression expression) {
}
RFLExpression RFLGetExpression(const RFLCharModel* charModel) {
const RFLiCharModel* charModel_ = (RFLiCharModel*)charModel;
const RFLiCharModel* charModel_ = (const RFLiCharModel*)charModel;
RFLi_ASSERTLINE_NULL(charModel, 499);
@@ -351,7 +351,7 @@ RFLExpression RFLGetExpression(const RFLCharModel* charModel) {
}
BOOL RFLIsAvailableExpression(const RFLCharModel* charModel, RFLExpression expression) {
const RFLiCharModel* charModel_ = (RFLiCharModel*)charModel;
const RFLiCharModel* charModel_ = (const RFLiCharModel*)charModel;
RFLi_ASSERTLINE_NULL(charModel, 518);
@@ -459,13 +459,13 @@ void RFLLoadMaterialSetting(const RFLDrawCoreSetting* setting) {
}
void RFLDrawOpaCore(const RFLCharModel* charModel, const RFLDrawCoreSetting* setting) {
const RFLiCharModel* charModel_ = (RFLiCharModel*)charModel;
const RFLiCharModel* charModel_ = (const RFLiCharModel*)charModel;
const RFLiCharModelRes* charModelRes;
RFLi_ASSERTLINE_NULL(charModel, 760);
RFLi_ASSERTLINE_NULL(setting, 761);
charModelRes = (RFLiCharModelRes*)charModel_->resource;
charModelRes = (const RFLiCharModelRes*)charModel_->resource;
GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_KONST);
@@ -550,13 +550,13 @@ void RFLDrawOpaCore(const RFLCharModel* charModel, const RFLDrawCoreSetting* set
}
void RFLDrawXluCore(const RFLCharModel* charModel, const RFLDrawCoreSetting* setting) {
const RFLiCharModel* charModel_ = (RFLiCharModel*)charModel;
const RFLiCharModel* charModel_ = (const RFLiCharModel*)charModel;
const RFLiCharModelRes* charModelRes;
RFLi_ASSERTLINE_NULL(charModel, 897);
RFLi_ASSERTLINE_NULL(setting, 898);
charModelRes = (RFLiCharModelRes*)charModel_->resource;
charModelRes = (const RFLiCharModelRes*)charModel_->resource;
GXSetTevOrder(GX_TEVSTAGE0, setting->txcID, setting->texMapID, GX_COLOR_NULL);
GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_TEXA);
@@ -1127,7 +1127,7 @@ void RFLiTransformCoordinate(s16* to, const s16* from) {
}
void RFLDrawShape(const RFLCharModel* charModel) {
const RFLiCharModel* charModel_ = (RFLiCharModel*)charModel;
const RFLiCharModel* charModel_ = (const RFLiCharModel*)charModel;
const RFLiCharModelRes* res;
GXCullMode cullMode;

View File

@@ -318,6 +318,7 @@ s32 RFLGetLastReason() {
}
RFLErrcode RFLWaitAsync() {
/* MWCC needs the status spill and reload on each polling iteration. */
volatile RFLErrcode errcode;
do {
errcode = RFLGetAsyncStatus();

View File

@@ -15,26 +15,32 @@ extern "C" {
#define TMCC_JPEG_DEC_WORK_SIZE 0x1C00
enum TMCCJPEGOutputFormat {
TMCC_JPEG_OUTPUT_RGB565 = 0,
TMCC_JPEG_OUTPUT_RGBA8 = 1,
TMCC_JPEG_OUTPUT_Y8U8V8 = 2
};
typedef struct TMCCJPEGDecWork_t TMCCJPEGDecWork;
typedef s32(TMCCReadCallback)(void*, u8*, unsigned int);
typedef struct {
u8 unk_0x00[0x10];
u8 reserved[0x10];
void* pBuf2; // 0x10
u32 buf2Size; // 0x14
u32 dataSize; // 0x18
TMCCReadCallback* pCallback; // 0x1C
void* pContext; // 0x20
u8 unk_0x24; // 0x24
u8 pad_0x25[0x03];
u8 thumbnailMode; // 0x24
u8 workBufferPadding[0x03];
TMCCJPEGDecWork* pBuf1; // 0x28
u8 unk_0x2C; // 0x2C
u8 pad_0x2D[0x03];
u8 outputFormat; // 0x2C
u8 alignmentPadding[0x03];
} TMCCJPEGDecInitParam;
typedef struct {
u8 unk_0x00[0x0C];
u8 reserved[0x0C];
u16 orientation; // 0x0C
u32 xResNum; // 0x10
u32 xResDen; // 0x14
@@ -70,7 +76,7 @@ typedef struct {
u16 posX;
u16 posY;
s32 position; // 0x04
u8 unk_0x08[0x04];
u8 reserved[0x04];
u32 state; // 0x0C
u16 maxX;
u16 maxY;
@@ -80,8 +86,8 @@ typedef struct {
u8 stepYExt;
u32 dataSizeX;
u32 dataSizeY;
u8 exifFlags; // 0x20
u8 thumbFlag; // 0x21
u8 scaleFactor; // 0x20
u8 noEoiCheck; // 0x21
u8 componentCount;
u8 dimensionPadding;
u16 jpegWidth;
@@ -107,7 +113,7 @@ typedef struct {
u16 posX; // 0x00
u16 posY; // 0x02
s32 position; // 0x04
u8 unk_0x08[0x04];
u8 reserved[0x04];
u32 result; // 0x0C
u16 maxX; // 0x10
u16 maxY; // 0x12
@@ -118,30 +124,26 @@ typedef struct {
u32 dataSizeX; // 0x18
u32 dataSizeY; // 0x1C
u8 scaleFactor; // 0x20
u8 unk_0x21; // 0x21
u8 noEoiCheck; // 0x21
u8 componentCount; // 0x22
u8 unk_0x23; // 0x23
u8 dimensionPadding;
u16 jpegWidth; // 0x24
u16 jpegHeight; // 0x26
u16 outputWidth; // 0x28
u16 outputHeight; // 0x2A
u32 convWidth; // 0x2C
u32 convHeight; // 0x30
#ifdef TMC_JPEG_PLANAR_OUTPUT
u32 chromaWidth;
u32 chromaHeight;
u8* pLumaBuffer;
u8* pCbBuffer;
u8* pCrBuffer;
#else
u8 unk_0x34[0x14]; // 0x34
#endif
void* pTexBuffer; // 0x48
u8 unk_0x4C[0x67C];
TMCCJPEGDecExifData exifData; // 0x4C
TMCCJPEGDecWork* pWorkBuf; // 0x6C8
s32 decodeResult; // 0x6CC
u8 converterType; // 0x6D0
u8 unk_0x6D1[0x03];
u8 alignmentPadding[0x03];
} TMCCJPEGDecState;
s32 TMCCJPEGDecInit(TMCCJPEGDecState* state, TMCCJPEGDecInitParam* param);

View File

@@ -5,12 +5,6 @@
#include <tmc_jpeg.h>
enum TMCCJPEGOutputFormat {
TMCC_JPEG_OUTPUT_RGB565 = 0,
TMCC_JPEG_OUTPUT_RGBA8 = 1,
TMCC_JPEG_OUTPUT_Y8U8V8 = 2
};
enum TMCJpegMarker {
TMC_JPEG_MARKER_SOF0 = 0xFFC0,
TMC_JPEG_MARKER_SOF2 = 0xFFC2,

View File

@@ -1,6 +1,28 @@
#include <string.h>
#include <tmc_jpeg_internal.h>
static inline s32 finishImageStart(TMCCJPEGDecWork* work, s32 result) {
if (result < 0) {
return result;
}
if (work->frameWidth == 0) {
return TMCC_ERROR_HEADER;
}
work->mcuCount = work->mcuXCount * work->mcuYCount;
work->mcuRemCount = work->mcuXRem * work->mcuXCount2;
return result;
}
static inline s32 finishScanStart(TMCCJPEGDecWork* work, s32 result) {
if (result < 0) {
return result;
}
if (work->scanCount == 1) {
return 0;
}
return result;
}
s32 TMCCJPEGDecInit(TMCCJPEGDecState* state, TMCCJPEGDecInitParam* param) {
s32 result;
TMCCJPEGDecWork* work;
@@ -15,16 +37,16 @@ s32 TMCCJPEGDecInit(TMCCJPEGDecState* state, TMCCJPEGDecInitParam* param) {
work->pState = state;
state->pWorkBuf = work;
if (param->unk_0x24 != 0) {
if (param->thumbnailMode != 0) {
result = -1;
} else if (param->unk_0x2C != TMCC_JPEG_OUTPUT_RGB565 && param->unk_0x2C != TMCC_JPEG_OUTPUT_RGBA8 &&
param->unk_0x2C != TMCC_JPEG_OUTPUT_Y8U8V8) {
} else if (param->outputFormat != TMCC_JPEG_OUTPUT_RGB565 && param->outputFormat != TMCC_JPEG_OUTPUT_RGBA8 &&
param->outputFormat != TMCC_JPEG_OUTPUT_Y8U8V8) {
result = -1;
} else {
state->unk_0x21 = param->unk_0x24;
state->noEoiCheck = param->thumbnailMode;
result = 0;
state->scaleFactor = 1;
state->converterType = param->unk_0x2C;
state->converterType = param->outputFormat;
}
if (result < 0) {
@@ -37,17 +59,13 @@ s32 TMCCJPEGDecInit(TMCCJPEGDecState* state, TMCCJPEGDecInitParam* param) {
}
result = TMCJPEGDEC_imagestart(work);
result = (result < 0) ?
result :
((work->frameWidth == 0) ?
TMCC_ERROR_HEADER :
((work->mcuCount = work->mcuXCount * work->mcuYCount, work->mcuRemCount = work->mcuXRem * work->mcuXCount2), result));
result = finishImageStart(work, result);
if (result < 0) {
goto error;
}
result = TMCJPEGDEC_scanstart(work);
result = (result < 0) ? result : ((work->scanCount == 1) ? 0 : result);
result = finishScanStart(work, result);
if (result < 0) {
goto error;
}

View File

@@ -10,9 +10,12 @@ static TMCHuffmanEntry readHuffmanEntry(const TMCHuffmanEntry* entries, u32 inde
return entries[index];
}
static void readHuffmanLimit(const TMCHuffmanEntry* entries, TMCHuffmanEntry* limit) {
limit->bitLength = entries->bitLength;
limit->symbol = entries->symbol;
static inline BOOL exceedsHuffmanLimit(u32 code, const u16* entry, TMCHuffmanEntry* limit, TMCHuffmanEntry* decoded) {
limit->bitLength = entry[0];
limit->symbol = entry[1];
/* MWCC needs the entry copy before reloading its bit length. */
*decoded = *limit;
return code > decoded->bitLength;
}
static inline s32 decodeLongHuffman(s32 bitCount, u32* huff_tbl, u8* symbols, TMCCJPEGDecWork* work, TMCHuffmanEntry* limit, TMCHuffmanEntry* decoded) {
@@ -34,8 +37,7 @@ static inline s32 decodeLongHuffman(s32 bitCount, u32* huff_tbl, u8* symbols, TM
bitCount -= 9;
code = (bitData >> bitCount) & 0x1FF;
work->bitCount = bitCount;
goto read_entry;
while (1) {
while (exceedsHuffmanLimit(code, entry, limit, decoded)) {
length++;
entry += 2;
if (length > 16) {
@@ -47,69 +49,11 @@ static inline s32 decodeLongHuffman(s32 bitCount, u32* huff_tbl, u8* symbols, TM
bitCount--;
work->bitCount = bitCount;
code |= (bitData >> bitCount) & 1;
read_entry:
{
limit->bitLength = entry[0];
limit->symbol = entry[1];
*decoded = *limit;
if (code > decoded->bitLength) {
continue;
}
{
u32 relativeCode = code - limit->bitLength;
u32 symbolIndex = relativeCode + limit->symbol;
return symbols[symbolIndex & 0xFF];
}
}
}
}
static inline s32 decodeACHuffman(s32 bitCount, u32* huff_tbl, u8* symbols, TMCCJPEGDecWork* work, TMCHuffmanEntry* limit, TMCHuffmanEntry* decoded) {
u16* entry;
u32 bitData;
u32 code;
u32 length;
if (bitCount <= 17) {
s32 result = TMCJPEGDEC_load_buff(work);
if (result < 0) {
return result;
}
}
bitCount = work->bitCount;
entry = (u16*)(huff_tbl + 9);
bitData = work->bitBuf;
length = 9;
bitCount -= 9;
code = (bitData >> bitCount) & 0x1FF;
work->bitCount = bitCount;
goto read_entry;
while (1) {
length++;
entry += 2;
if (length > 16) {
return TMCC_ERROR_OVERFLOW;
}
bitCount = work->bitCount;
code <<= 1;
bitData = work->bitBuf;
bitCount--;
work->bitCount = bitCount;
code |= (bitData >> bitCount) & 1;
read_entry:
{
limit->bitLength = entry[0];
limit->symbol = entry[1];
*decoded = *limit;
if (code > decoded->bitLength) {
continue;
}
{
u32 relativeCode = code - limit->bitLength;
u32 symbolIndex = relativeCode + limit->symbol;
return symbols[symbolIndex & 0xFF];
}
}
{
u32 relativeCode = code - limit->bitLength;
u32 symbolIndex = relativeCode + limit->symbol;
return symbols[symbolIndex & 0xFF];
}
}
@@ -225,7 +169,7 @@ s32 TMCJPEGDEC_decode_iquant(s32* block, u8* conv_row_ptr, u32* dc_predict_row_p
r = acEntry.symbol;
} else {
bit_pos = work->bitCount;
r = decodeACHuffman(bit_pos, ac_huff_tbl, ac_huff_sym, work, &acLimit, &acDecoded);
r = decodeLongHuffman(bit_pos, ac_huff_tbl, ac_huff_sym, work, &acLimit, &acDecoded);
if (r < 0) {
return r;
}

View File

@@ -221,11 +221,11 @@ s32 TMCCJPEGDecGetInfoEXIF(TMCCJPEGDecExifInfo* pInfo, TMCCJPEGDecInitParam* pPa
return result;
}
if (pParam->unk_0x24 == 0) {
if (pParam->thumbnailMode == 0) {
return 0;
}
if (pParam->unk_0x24 == 1) {
if (pParam->thumbnailMode == 1) {
result = TMCJPEGDEC_ThumbnailCheck(pParam, pInfo, segSizeP2);
if (result < 0) {
return result;
@@ -668,7 +668,7 @@ static void TMCJPEGDEC_IFD1_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder,
static s32 TMCJPEGDEC_ThumbnailCheck(TMCCJPEGDecInitParam* param, TMCCJPEGDecExifInfo* info, u32 totalSize) {
s32 total;
s32 length;
s32 tmp;
s32 thumbnailBufferOffset;
total = (s32)info->exifData.thumbnailOffset;
if (total == 0) {
@@ -684,8 +684,8 @@ static s32 TMCJPEGDEC_ThumbnailCheck(TMCCJPEGDecInitParam* param, TMCCJPEGDecExi
return -0xA0;
}
tmp = (s32)info->exifData.thumbnailData - (s32)param->pBuf2;
total = length + total + tmp;
thumbnailBufferOffset = (s32)info->exifData.thumbnailData - (s32)param->pBuf2;
total = length + total + thumbnailBufferOffset;
if ((u32)total > param->buf2Size) {
return -0xF1;
@@ -695,19 +695,19 @@ static s32 TMCJPEGDEC_ThumbnailCheck(TMCCJPEGDecInitParam* param, TMCCJPEGDecExi
return -0xF1;
}
info->exifFlags = 1;
info->scaleFactor = 1;
if (param->unk_0x24 != 1) {
if (param->thumbnailMode != 1) {
return -1;
}
info->thumbFlag = 0;
info->noEoiCheck = 0;
if (param->unk_0x2C != TMCC_JPEG_OUTPUT_RGB565 && param->unk_0x2C != TMCC_JPEG_OUTPUT_RGBA8 &&
param->unk_0x2C != TMCC_JPEG_OUTPUT_Y8U8V8) {
if (param->outputFormat != TMCC_JPEG_OUTPUT_RGB565 && param->outputFormat != TMCC_JPEG_OUTPUT_RGBA8 &&
param->outputFormat != TMCC_JPEG_OUTPUT_Y8U8V8) {
return -1;
}
info->converterType = param->unk_0x2C;
info->converterType = param->outputFormat;
return 0;
}

View File

@@ -1,5 +1,6 @@
#define TMC_JPEG_FRAME_PARSER
#include <tmc_jpeg_internal.h>
#include <stddef.h>
extern void* memset(void* dest, s32 val, u32 count);
@@ -68,7 +69,7 @@ s32 TMCJPEGDEC_decompmcu(u32 maxMCU, u32 mcuCount, TMCCJPEGDecWork* work, void*
blockCountPtr = frameInfo + mcuIdx;
blockIdx = 0;
while (blockIdx < *(blockCountPtr + 0x1c)) {
while (blockIdx < *(blockCountPtr + offsetof(TMCJpegFrameInfo, blockCount))) {
s32 stackBlock[64];
s32 ret;
@@ -146,7 +147,7 @@ s32 TMCJPEGDEC_imagestart(TMCCJPEGDecWork* work) {
}
s32 TMCJPEGDEC_imageend(TMCCJPEGDecWork* work) {
if (work->pState->unk_0x21 == 1)
if (work->pState->noEoiCheck == 1)
return 0;
if (work->scanCount == 0) {
@@ -816,7 +817,7 @@ static s32 TMCJPEGDEC_parse_sos(TMCCJPEGDecWork* work) {
s32 idx;
TMCFrameComponents* components;
TMCJpegTableInfo* scalePtr;
TMCFrameComponents* mapPtr;
u8* mapPtr;
s32 dcTbl;
s32 acTbl;
@@ -858,7 +859,7 @@ static s32 TMCJPEGDEC_parse_sos(TMCCJPEGDecWork* work) {
for (ci = 0; ci < work->compCount; ci++) {
if ((s32)scanByte == (s32)components->id[ci]) {
components->map[idx] = ci;
mapPtr = (TMCFrameComponents*)&components->map[idx];
mapPtr = &components->map[idx];
goto componentFound;
}
}
@@ -877,8 +878,8 @@ componentFound:
return -0x51;
}
components->dcTable[mapPtr->map[0]] = dcTbl;
components->acTable[mapPtr->map[0]] = acTbl;
components->dcTable[*mapPtr] = dcTbl;
components->acTable[*mapPtr] = acTbl;
if (scalePtr->dcTblFlag[dcTbl] != 1) {
return -0x40;
@@ -888,7 +889,7 @@ componentFound:
return -0x40;
}
if (scalePtr->quantTblFlag[mapPtr->quantTable[0]] != 1) {
if (scalePtr->quantTblFlag[components->quantTable[idx]] != 1) {
return -0x41;
}
}
@@ -900,237 +901,91 @@ componentFound:
return 0;
}
#ifdef __MWERKS__
asm s32 TMCJPEGDEC_err_restart(register TMCCJPEGDecWork* work) {
nofralloc
static inline s32 restartFromMarker(TMCCJPEGDecWork* work, TMCCJPEGDecState* state, u8 marker) {
u8 skip;
u16 pitch;
u32 pos;
u16 row;
u16 column;
s32 mcuIndex;
u16 y;
u16 x;
s32 result;
stwu r1, -0x20(r1)
mflr r0
stw r0, 0x24(r1)
stw r31, 0x1c(r1)
stw r30, 0x18(r1)
mr r30, r3
stw r29, 0x14(r1)
stw r28, 0x10(r1)
lbz r0, 0x181c(r3)
lwz r31, 0x19e4(r3)
cmplwi r0, 1
bne _err_restart_rewind
li r0, 0
li r3, 0
stw r0, 0x6cc(r31)
b _err_restart_return
_err_restart_rewind:
bl TMCJPEGDEC_rewind_ptr
cmpwi r3, 0
bge _err_restart_load_byte
b _err_restart_return
_err_restart_load_byte:
lwz r3, 0xc(r30)
lbz r0, 0(r3)
stb r0, 8(r1)
b _err_restart_check_byte
_err_restart_read_byte:
mr r4, r30
addi r3, r1, 8
bl TMCJPEGDEC_get_byte
cmpwi r3, 0
bge _err_restart_check_byte
b _err_restart_return
_err_restart_check_byte:
lbz r0, 8(r1)
cmplwi r0, 0xff
bne _err_restart_read_byte
mr r4, r30
addi r3, r1, 8
bl TMCJPEGDEC_get_byte
lbz r6, 8(r1)
cmplwi r6, 0xd9
bne _err_restart_check_result
cmpwi r3, 0
bge _err_restart_eoi
cmpwi r3, -0x90
beq _err_restart_eoi
b _err_restart_return
_err_restart_eoi:
li r3, 0
b _err_restart_return
_err_restart_check_result:
cmpwi r3, 0
bge _err_restart_check_marker
b _err_restart_return
_err_restart_check_marker:
cmplwi r6, 0xd0
blt _err_restart_check_byte
cmplwi r6, 0xd7
ble _err_restart_marker
b _err_restart_check_byte
_err_restart_marker:
lhz r3, 0x52(r30)
addi r0, r6, 8
addi r3, r3, 0xcf
cmpw r6, r3
subf r0, r3, r0
clrlwi r5, r0, 0x18
ble _err_restart_have_diff
subf r0, r3, r6
clrlwi r5, r0, 0x18
_err_restart_have_diff:
lhz r4, 0x181a(r30)
addi r0, r6, 1
clrlwi r3, r0, 0x1d
lhz r7, 0x10(r31)
mullw r5, r5, r4
li r0, 0
lwz r6, 0x54(r30)
sth r3, 0x52(r30)
mr r3, r30
clrlwi r4, r6, 0x18
clrlwi r8, r5, 0x18
srwi r6, r6, 0x10
mullw r5, r4, r7
stw r0, 0x30(r30)
add r4, r8, r6
stw r0, 0x34(r30)
stw r0, 0x38(r30)
add r5, r5, r4
divw r4, r5, r7
stw r0, 0x3c(r30)
sth r0, 0x50(r30)
mullw r0, r4, r7
clrlwi r28, r4, 0x10
subf r4, r0, r5
slwi r0, r4, 0x10
add r0, r0, r28
clrlwi r29, r4, 0x10
stw r0, 0x54(r30)
bl TMCJPEGDEC_init_buff
cmpwi r3, 0
bge _err_restart_store_position
b _err_restart_return
_err_restart_store_position:
sth r29, 0(r31)
mr r3, r30
sth r28, 2(r31)
bl TMCJPEGDEC_get_position
stw r3, 4(r31)
lhz r4, 2(r31)
lhz r3, 0x10(r31)
lwz r0, 0xc(r31)
mullw r3, r4, r3
lhz r4, 0(r31)
subf r0, r3, r0
subf r3, r4, r0
_err_restart_return:
lwz r0, 0x24(r1)
lwz r31, 0x1c(r1)
lwz r30, 0x18(r1)
lwz r29, 0x14(r1)
lwz r28, 0x10(r1)
mtlr r0
addi r1, r1, 0x20
blr
if (marker > work->rstMarkerIdx + 0xCF) {
skip = marker - (work->rstMarkerIdx + 0xCF);
} else {
skip = (marker + 8) - (work->rstMarkerIdx + 0xCF);
}
skip *= work->restartInterval;
pitch = state->maxX;
pos = work->mcuPos;
row = pos & 0xFF;
column = pos >> 16;
mcuIndex = row * pitch + (skip + column);
work->rstMarkerIdx = (marker + 1) & 7;
y = mcuIndex / pitch;
x = mcuIndex % pitch;
work->components.dcPredict[0] = 0;
work->components.dcPredict[1] = 0;
work->components.dcPredict[2] = 0;
work->components.dcPredict[3] = 0;
work->restartCnt = 0;
work->mcuPos = (x << 16) + y;
result = TMCJPEGDEC_init_buff(work);
if (result < 0) {
return result;
}
state->posX = x;
state->posY = y;
state->position = TMCJPEGDEC_get_position(work);
return state->result - state->posY * state->maxX - state->posX;
}
#else
s32 TMCJPEGDEC_err_restart(TMCCJPEGDecWork* work) {
TMCCJPEGDecState* state;
u16 interval;
u16 pitch;
u32 val;
s32 rem;
s32 div;
s32 next;
u8 rstDiff;
TMCCJPEGDecWork* stream;
s32 result;
u8 byte;
s32 r;
u8 marker;
state = work->pState;
if (work->scanCount == 1) {
state->decodeResult = 0;
return 0;
}
r = TMCJPEGDEC_rewind_ptr(work);
if (r < 0) {
return r;
stream = work;
result = TMCJPEGDEC_rewind_ptr(stream);
if (result < 0) {
return result;
}
byte = *work->pBufCur;
while (TRUE) {
byte = *stream->pBufCur;
for (;;) {
while (byte != 0xFF) {
r = TMCJPEGDEC_get_byte(&byte, work);
if (r < 0) {
return r;
result = TMCJPEGDEC_get_byte(&byte, stream);
if (result < 0) {
return result;
}
}
r = TMCJPEGDEC_get_byte(&byte, work);
if (byte == 0xD9) {
if (r < 0 && r != TMCC_ERROR_UNDERFLOW) {
return r;
result = TMCJPEGDEC_get_byte(&byte, stream);
marker = byte;
if (marker == 0xD9) {
if (result < 0 && result != TMCC_ERROR_UNDERFLOW) {
return result;
}
return 0;
}
if (r < 0) {
return r;
if (result < 0) {
return result;
}
if (byte < 0xD0 || byte > 0xD7) {
continue;
if (marker >= 0xD0 && marker <= 0xD7) {
break;
}
if (byte > work->rstMarkerIdx + 0xCF) {
rstDiff = byte - (work->rstMarkerIdx + 0xCF);
} else {
rstDiff = (byte + 0x08) - (work->rstMarkerIdx + 0xCF);
}
work->rstMarkerIdx = (byte + 1) & 7;
interval = work->restartInterval;
pitch = state->maxX;
val = work->mcuPos;
work->components.dcPredict[0] = 0;
work->components.dcPredict[1] = 0;
work->components.dcPredict[2] = 0;
work->components.dcPredict[3] = 0;
work->restartCnt = 0;
next = (u8)(val & 0xFF) * (s32)pitch + (val >> 16) + (s32)(u8)(rstDiff * interval);
div = next / (s32)pitch;
rem = next - div * (s32)pitch;
work->mcuPos = (rem << 16) + (u16)div;
r = TMCJPEGDEC_init_buff(work);
if (r < 0) {
return r;
}
state->posX = rem;
state->posY = div;
state->position = TMCJPEGDEC_get_position(work);
return state->result - (state->posY * state->maxX) - state->posY;
// MWCC needs the stream reset here to keep the retail loop-exit branch layout.
stream = work;
}
return restartFromMarker(work, state, marker);
}
#endif
void TMCJPEGDEC_set_entropytbl(TMCJpegTableInfo* work, s32 idx, u8 data) {
switch (idx) {
@@ -1148,18 +1003,15 @@ void TMCJPEGDEC_set_entropytbl(TMCJpegTableInfo* work, s32 idx, u8 data) {
}
}
if ((s32)data == 1) {
goto ac1;
if ((s32)data != 1) {
if ((s32)data < 1 && (s32)data >= 0) {
work->pACFast = work->huffDecTblAC0;
work->pACHuffSym = work->maxCodeAC0;
work->pACHuffTbl = work->valPtrAC0;
}
} else {
work->pACFast = work->huffDecTblAC1;
work->pACHuffSym = work->maxCodeAC1;
work->pACHuffTbl = work->valPtrAC1;
}
if ((s32)data < 1 && (s32)data >= 0) {
work->pACFast = work->huffDecTblAC0;
work->pACHuffSym = work->maxCodeAC0;
work->pACHuffTbl = work->valPtrAC0;
}
return;
ac1:
work->pACFast = work->huffDecTblAC1;
work->pACHuffSym = work->maxCodeAC1;
work->pACHuffTbl = work->valPtrAC1;
}

View File

@@ -2,6 +2,18 @@
extern void* memset(void* dest, int value, unsigned long size);
typedef struct {
u16 bitLength;
u16 symbol;
} TMCHuffmanEntry;
static inline BOOL exceedsHuffmanLimit(u32 code, const u16* entry, TMCHuffmanEntry* limit, TMCHuffmanEntry* decoded) {
*limit = *(const TMCHuffmanEntry*)entry;
/* MWCC needs the entry copy before reloading its bit length. */
*decoded = *limit;
return code > decoded->bitLength;
}
static s32 TMCJPEGDEC_vl_decode_rc(u32* huff_tbl, u8* huff_sym, TMCCJPEGDecWork* work);
static inline s32 readCoefficientBits(TMCCJPEGDecWork* work, s32 count) {
@@ -150,6 +162,8 @@ static s32 TMCJPEGDEC_vl_decode_rc(u32* huff_tbl, u8* huff_sym, TMCCJPEGDecWork*
u32 code;
unsigned int i;
s32 r;
TMCHuffmanEntry limit;
TMCHuffmanEntry decoded;
bit_pos = work->bitCount;
@@ -168,9 +182,7 @@ static s32 TMCJPEGDEC_vl_decode_rc(u32* huff_tbl, u8* huff_sym, TMCCJPEGDecWork*
code = (bit_data >> bit_pos) & 0x1FF;
work->bitCount = bit_pos;
goto entry_check;
do {
while (exceedsHuffmanLimit(code, entry, &limit, &decoded)) {
i++;
entry += 2;
if (i > 16) {
@@ -183,24 +195,11 @@ static s32 TMCJPEGDEC_vl_decode_rc(u32* huff_tbl, u8* huff_sym, TMCCJPEGDecWork*
bit_pos--;
work->bitCount = bit_pos;
code |= (bit_data >> bit_pos) & 1;
entry_check: {
typedef struct {
u16 t;
u16 o;
} HuffEnt;
HuffEnt local = *(HuffEnt*)entry;
u32 combined = *(u32*)&local;
u16 th = *(u16*)&combined;
s32 tmp;
if (code > th) {
continue;
}
tmp = code - local.t;
code = tmp + (u32)local.o;
}
return huff_sym[code & 0xFF];
} while (1);
{
s32 relativeCode = code - limit.bitLength;
code = relativeCode + (u32)limit.symbol;
}
return huff_sym[code & 0xFF];
}

View File

@@ -1,4 +1,3 @@
#define TMC_JPEG_PLANAR_OUTPUT
#include <tmc_jpeg_internal.h>
static void TMCJPEG_814EFEAC(TMCCJPEGDecWork*, s32, s32);

View File

@@ -213,6 +213,7 @@ Zi8UInt Zi8SpellingZY(ziU16 *output,Zi8UInt key,ziU8 includeTone)
initialIndex = (ziU16)(((key & 0xffff) >> 9) & 0x3f);
finalIndex = (ziU16)(((key & 0xffff) >> 3) & 0x3f);
tone = (ziU16)(key & 7);
/* MWCC needs the stored initial character as the branch value. */
if ((output[0] = zi8ZYinitialSpelling[initialIndex]) != 0) {
length = 1;
}
@@ -250,7 +251,7 @@ Zi8UInt Zi8SpellingPY(ziU16 *output,Zi8UInt key,ziU8 includeTone)
Zi8UInt length = 0;
ziU16 initialIndex = (ziU16)(((key & 0xffff) >> 9) & 0x3f);
ziU16 finalIndex = (ziU16)(((key & 0xffff) >> 3) & 0x3f);
volatile ziU16 tone = (ziU16)(key & 7);
ziU16 tone = (ziU16)(key & 7);
output[0] = zi8PYinitialSpelling[initialIndex][0];
output[1] = zi8PYinitialSpelling[initialIndex][1];
@@ -354,16 +355,13 @@ ziU8 MatchAltSound1Key(ziU16 *spelling,Zi8UInt spellingLength,Zi8UInt requireFul
if ((keyHigh == records[recordIndex].keyHigh) &&
(keyLow == records[recordIndex].keyLow)) {
searchIndex = recordIndex;
goto START_PROCESS;
} else {
if (keyHigh != records[searchIndex].keyHigh || keyLow != records[searchIndex].keyLow) {
goto BINARY_SEARCH;
}
}
if ((keyHigh == records[searchIndex].keyHigh) &&
(keyLow == records[searchIndex].keyLow)) {
goto START_PROCESS;
}
goto BINARY_SEARCH;
START_PROCESS:
recordIndex = searchIndex;
PROCESS:
do {
if (((records[recordIndex].flags & 0xeU) == 0) ||
((modifierFlags & records[recordIndex].flags) != 0)) {
@@ -402,7 +400,6 @@ BACKWARD_PROCESS:
}
}
}
goto BACKWARD_TEST;
BACKWARD_TEST:
recordIndex = recordIndex - 1;
if ((((int)recordIndex < 0) || (keyHigh != records[recordIndex].keyHigh)) ||
@@ -458,30 +455,25 @@ static int ZiIsSupportedPhonetic(ziU8 language,ziPtr work)
return 1;
}
switch (language) {
case 0x79:
case 0x7a:
case 0x7d:
goto LAB_group_b;
case 0x77:
case 0x78:
case 0x7c:
goto LAB_group_a;
if ((Zi8LangSupported(0x77,work) != 0) || (Zi8LangSupported(0x78,work) != 0) ||
(Zi8LangSupported(0x7c,work) != 0)) {
return 1;
}
case 0x79:
case 0x7a:
case 0x7d:
if ((Zi8LangSupported(0x79,work) == 0) && (Zi8LangSupported(0x7a,work) == 0) &&
(Zi8LangSupported(0x7d,work) == 0)) {
break;
}
return 1;
default:
goto LAB_return_false;
break;
}
LAB_group_a:
if ((Zi8LangSupported(0x77,work) != 0) || (Zi8LangSupported(0x78,work) != 0) ||
(Zi8LangSupported(0x7c,work) != 0)) {
return 1;
}
LAB_group_b:
if ((Zi8LangSupported(0x79,work) == 0) && (Zi8LangSupported(0x7a,work) == 0) &&
(Zi8LangSupported(0x7d,work) == 0)) {
goto LAB_return_false;
}
return 1;
LAB_return_false:
return 0;
return 0;
}
ziU32 Zi8Get1KeyPressSpelling(ziGetParam *params,Zi8OneKeyOptions *options,Zi8OneKeyWork *work)
@@ -938,6 +930,7 @@ ziU32 Zi8Get1KeyPressSpelling(ziGetParam *params,Zi8OneKeyOptions *options,Zi8On
for (;;) {
if (tableCount == 0) break;
spellingEntry = (ziU8 *)Zi8GetTableAddress(1,0xc,work);
/* MWCC needs the spelling-entry advance in the loop body. */
for (tableIndex = 0; tableIndex < tableCount; tableIndex++) {
if ((*spellingEntry & languageMask) != 0) {
if (usePinyin) entryLength = *spellingEntry & 0xf;
@@ -1493,40 +1486,41 @@ ziU32 Zi8Get1KeyPressCandidates(ziGetParam *params,Zi8OneKeyOptions *options,Zi8
elementIndex = MatchAltSound1Key(spelling,inputLimit,matchFull,(Zi8AltSoundRecord *)alternateTable,phoneticMask,phoneticTable,
phraseCharacter,tone,includeTone,languageMask,work);
}
if (elementIndex == 0) goto nextPhrase;
if (!emitWords) {
if (trackDuplicates && (ziU8)Zi8SetFindCand(params->scratch,phraseCharacter,work) != 0) goto nextPhrase;
for (index = 0; index < candidateCount; index++) {
if (firstOrdinal == output[index]) goto nextPhrase;
}
} else {
wordLength = 0;
do {
phraseCharacter = ((ziU16)entryCursor[1] << 8) | *entryCursor;
entryCursor += 2;
output[outputIndex + wordLength++] = Zi8Ord2Uni(phraseCharacter & 0x7fff,work);
} while ((phraseCharacter & 0x8000) == 0);
if (prefixSearch != 0 || params->elementCount != 0) wordLength = 1;
if (Zi8IsDupWordW(output + outputIndex,wordLength,work) != 0) goto nextPhrase;
output[outputIndex + wordLength] = 0;
}
if (optionsMask == 5) {
if (++totalCandidates >= options->maxCount) goto finishCandidates;
} else if (remaining == 0) {
totalCandidates++;
candidateCount++;
if (emitWords) {
outputIndex += wordLength;
output[outputIndex++] = 0x20;
if (elementIndex != 0) {
if (!emitWords) {
if (trackDuplicates && (ziU8)Zi8SetFindCand(params->scratch,phraseCharacter,work) != 0) goto nextPhrase;
for (index = 0; index < candidateCount; index++) {
if (firstOrdinal == output[index]) goto nextPhrase;
}
} else {
output[outputIndex++] = firstOrdinal;
wordLength = 0;
do {
phraseCharacter = ((ziU16)entryCursor[1] << 8) | *entryCursor;
entryCursor += 2;
output[outputIndex + wordLength++] = Zi8Ord2Uni(phraseCharacter & 0x7fff,work);
} while ((phraseCharacter & 0x8000) == 0);
if (prefixSearch != 0 || params->elementCount != 0) wordLength = 1;
if (Zi8IsDupWordW(output + outputIndex,wordLength,work) != 0) goto nextPhrase;
output[outputIndex + wordLength] = 0;
}
if (candidateCount >= params->maxCandidates || outputIndex > outputLimit) {
params->count = candidateCount;
goto finishCandidates;
if (optionsMask == 5) {
if (++totalCandidates >= options->maxCount) goto finishCandidates;
} else if (remaining == 0) {
totalCandidates++;
candidateCount++;
if (emitWords) {
outputIndex += wordLength;
output[outputIndex++] = 0x20;
} else {
output[outputIndex++] = firstOrdinal;
}
if (candidateCount >= params->maxCandidates || outputIndex > outputLimit) {
params->count = candidateCount;
goto finishCandidates;
}
} else {
remaining--;
}
} else {
remaining--;
}
}
nextPhrase:
@@ -1557,7 +1551,7 @@ finishPhrases:
for (index = 0; index < 4; index++) {
if (keyValues[index] != (keyMasks[index] & phraseTable[index])) break;
}
if (index < 4) goto nextSortedOrdinal;
if (index < 4) continue;
}
entryFlags = false;
if (work->phoneticFilter != 0) {
@@ -1574,17 +1568,17 @@ finishPhrases:
elementIndex = MatchAltSound1Key(spelling,inputLimit,matchFull,(Zi8AltSoundRecord *)alternateTable,phoneticMask,phoneticTable,ordinal,
tone,includeTone,languageMask,work);
}
if (elementIndex == 0) goto nextSortedOrdinal;
if (elementIndex == 0) continue;
if (!emitWords) {
if (trackDuplicates && (ziU8)Zi8SetFindCand(params->scratch,ordinal,work) != 0) goto nextSortedOrdinal;
if (trackDuplicates && (ziU8)Zi8SetFindCand(params->scratch,ordinal,work) != 0) continue;
ordinal = Zi8Ord2Uni(ordinal,work);
for (index = 0; index < candidateCount; index++) {
if (ordinal == output[index]) break;
}
if (index < candidateCount) goto nextSortedOrdinal;
if (index < candidateCount) continue;
} else {
ordinal = Zi8Ord2Uni(ordinal,work);
if (Zi8IsDupWordW(&ordinal,1,work) != 0) goto nextSortedOrdinal;
if (Zi8IsDupWordW(&ordinal,1,work) != 0) continue;
}
if (remaining == 0) {
totalCandidates++;
@@ -1600,12 +1594,11 @@ finishPhrases:
remaining--;
}
}
nextSortedOrdinal:
;
}
}
if ((options->countOnly == '\0') && (ziU8)Zi8GetZHuwdPtr(&userEntriesAddress,&userCount,work) != 0)
{
/* MWCC needs both user-entry cursor advances in the loop body. */
for (phraseOrdinal = 0; phraseOrdinal < userCount;) {
if ((params->elementCount == '\0') || ((((ziU8*)userEntriesAddress)[1] & 0x80) != 0)) {
userOrdinal = (ziU16)(((ziU8*)userEntriesAddress)[1] & 0x7f) << 8 | (ziU16)((ziU8*)userEntriesAddress)[2];
@@ -1627,26 +1620,27 @@ nextSortedOrdinal:
elementIndex = MatchAltSound1Key(spelling,inputLimit,matchFull,(Zi8AltSoundRecord *)alternateTable,phoneticMask,phoneticTable,userOrdinal,
tone,includeTone,languageMask,work);
}
if (elementIndex == 0) goto nextUserOrdinal;
if (!emitWords) {
if (trackDuplicates && (ziU8)Zi8SetFindCand(params->scratch,userOrdinal,work) != 0) goto nextUserOrdinal;
userCharacter = Zi8Ord2Uni(userOrdinal,work);
for (duplicateIndex = 0; duplicateIndex < candidateCount; duplicateIndex++) {
if (userCharacter == output[duplicateIndex]) break;
if (elementIndex != 0) {
if (!emitWords) {
if (trackDuplicates && (ziU8)Zi8SetFindCand(params->scratch,userOrdinal,work) != 0) goto nextUserOrdinal;
userCharacter = Zi8Ord2Uni(userOrdinal,work);
for (duplicateIndex = 0; duplicateIndex < candidateCount; duplicateIndex++) {
if (userCharacter == output[duplicateIndex]) break;
}
if (duplicateIndex < candidateCount) goto nextUserOrdinal;
} else {
userCharacter = Zi8Ord2Uni(userOrdinal,work);
if (Zi8IsDupWordW(&userCharacter,1,work) != 0) goto nextUserOrdinal;
}
if (remaining == 0) {
totalCandidates++;
candidateCount++;
output[outputIndex++] = userCharacter;
if (emitWords) output[outputIndex++] = 0x20;
if (candidateCount >= params->maxCandidates || outputIndex > outputLimit) goto finishCandidates;
} else {
remaining--;
}
if (duplicateIndex < candidateCount) goto nextUserOrdinal;
} else {
userCharacter = Zi8Ord2Uni(userOrdinal,work);
if (Zi8IsDupWordW(&userCharacter,1,work) != 0) goto nextUserOrdinal;
}
if (remaining == 0) {
totalCandidates++;
candidateCount++;
output[outputIndex++] = userCharacter;
if (emitWords) output[outputIndex++] = 0x20;
if (candidateCount >= params->maxCandidates || outputIndex > outputLimit) goto finishCandidates;
} else {
remaining--;
}
}
}
@@ -1657,6 +1651,7 @@ nextUserOrdinal:
}
phraseTable = syllableTable;
previousCharacter = 0;
/* MWCC needs both ordinal cursor advances in the loop body. */
for (ordinal = 0; ordinal < ordinalCount;) {
if (((*phraseTable & languageMask) != 0) &&
((characterSetTable == 0 || ((characterSet & characterSetTable[(Zi8UInt)ordinal]) != 0)))) {
@@ -1680,31 +1675,33 @@ nextUserOrdinal:
elementIndex = MatchAltSound1Key(spelling,inputLimit,matchFull,(Zi8AltSoundRecord *)alternateTable,phoneticMask,phoneticTable,ordinal,
tone,includeTone,languageMask,work);
}
if (elementIndex == 0) goto nextOrdinal;
unicodeCharacter = ((ziU16)phraseTable[6] << 8) + (ziU16)phraseTable[7];
if (unicodeCharacter == previousCharacter) goto nextOrdinal;
previousCharacter = unicodeCharacter;
if (!emitWords) {
if (trackDuplicates && (ziU8)Zi8SetFindCand(params->scratch,ordinal,work) != 0) goto nextOrdinal;
for (index = 0; index < candidateCount; index++) {
if (unicodeCharacter == output[index]) break;
if (elementIndex != 0) {
unicodeCharacter = ((ziU16)phraseTable[6] << 8) + (ziU16)phraseTable[7];
if (unicodeCharacter != previousCharacter) {
previousCharacter = unicodeCharacter;
if (!emitWords) {
if (trackDuplicates && (ziU8)Zi8SetFindCand(params->scratch,ordinal,work) != 0) goto nextOrdinal;
for (index = 0; index < candidateCount; index++) {
if (unicodeCharacter == output[index]) break;
}
if (index < candidateCount) goto nextOrdinal;
} else {
if (Zi8IsDupWordW(&unicodeCharacter,1,work) != 0) goto nextOrdinal;
}
if (remaining == 0) {
totalCandidates++;
if (options->countOnly == 0) {
candidateCount++;
output[outputIndex++] = unicodeCharacter;
if (emitWords) output[outputIndex++] = 0x20;
} else {
if (totalCandidates >= options->maxCount) break;
}
if (candidateCount >= params->maxCandidates || outputIndex > outputLimit) break;
} else {
remaining--;
}
}
if (index < candidateCount) goto nextOrdinal;
} else {
if (Zi8IsDupWordW(&unicodeCharacter,1,work) != 0) goto nextOrdinal;
}
if (remaining == 0) {
totalCandidates++;
if (options->countOnly == 0) {
candidateCount++;
output[outputIndex++] = unicodeCharacter;
if (emitWords) output[outputIndex++] = 0x20;
} else {
if (totalCandidates >= options->maxCount) break;
}
if (candidateCount >= params->maxCandidates || outputIndex > outputLimit) break;
} else {
remaining--;
}
}
nextOrdinal:
@@ -1784,23 +1781,22 @@ ziBool Zi8ZHCheckSpelling(ziWChar *input,ziWChar *spelling,ziU8 inputLength,ziPt
switch (spelling[index]) {
case 0xf331:
toneMask = 1;
goto validateTone;
break;
case 0xf332:
toneMask = 2;
goto validateTone;
break;
case 0xf333:
toneMask = 4;
goto validateTone;
break;
case 0xf334:
toneMask = 8;
goto validateTone;
break;
case 0xf335:
toneMask = 0x10;
goto validateTone;
break;
default:
goto nextInputCharacter;
continue;
}
validateTone:
if (toneTable != 0) {
while( true ) {
syllableLength = (index - syllableStart) + 1;
@@ -1842,8 +1838,6 @@ validateTone:
}
input[index] = spelling[index];
syllableStart = index + 1;
nextInputCharacter:
;
}
for (index = 0; input[index] != 0; index = index + 1) {
if ((input[index] >= 0x61) && (input[index] <= 0x7a)) {

View File

@@ -231,7 +231,7 @@ ziBool Zi8IsVowel(ziU8 language, ziWChar character) {
if (language == 47) return ZI8_FALSE;
switch (character) {
case 0xFF: case 0x152: case 0x153: case 0x178:
goto vowel;
break;
default:
return ZI8_FALSE;
}
@@ -287,6 +287,7 @@ static ziBool ZiIsLetterHyphen(ziWChar character ZI_NEED_WORK) {
void Zi8ChangeWordCase(ziWChar* word, ziU8 language, ZiAlphaWork* work) {
enum { LOWER_CASE, UPPER_CASE } upper = LOWER_CASE;
/* MWCC needs the explicit work cast in the case-mode test below. */
if (work->caseMode == 3) {
Zi8ChangeCharCase(1, word++, language, work);
} else if (((ZiAlphaWork*)work)->caseMode == 1) {
@@ -460,10 +461,14 @@ int Zi8AlphaGetCandidates(ziGetParam* parameters, ziPtr optionData, ziPtr workDa
if (((Zi8GetTableCount(parameters->language,0x1f,workData) & 0x80) != 0) && (parameters->subLanguage == 0x80)) {
contextEnabled = ZI8_TRUE;
}
if (!(((((ZiAlphaOptions*)optionData)->lookupMode == '\0') && (parameters->subLanguage != 7)) &&
((parameters->subLanguage != language &&
((((parameters->subLanguage != 0 && (parameters->subLanguage != 1)) && (parameters->subLanguage != 2)) &&
((parameters->subLanguage != 0x80 && ((Zi8LangSupported(parameters->subLanguage,workData)) != '\0'))))))))) {
if (((ZiAlphaOptions*)optionData)->lookupMode != '\0' ||
parameters->subLanguage == 7 ||
parameters->subLanguage == language ||
parameters->subLanguage == 0 ||
parameters->subLanguage == 1 ||
parameters->subLanguage == 2 ||
parameters->subLanguage == 0x80 ||
(Zi8LangSupported(parameters->subLanguage,workData)) == '\0') {
languagePassCount = 0;
if (((ZiAlphaWork*)workData)->language != parameters->language) {
((ZiAlphaWork*)workData)->language = 0;
@@ -566,10 +571,12 @@ int Zi8AlphaGetCandidates(ziGetParam* parameters, ziPtr optionData, ziPtr workDa
switch ((int)((ZiAlphaWork*)workData)->dictionaryKinds[index]) {
case 1:
case 9:
goto foundHighlightedDictionary;
break;
default:
continue;
}
break;
}
foundHighlightedDictionary:
if (firstCandidate == 0 && ((ZiAlphaWork*)workData)->highlightedWord[elementIndex - 1] != 0) {
if (((ZiAlphaWork*)workData)->requiredLength < parameters->elementCount)
((ZiAlphaWork*)workData)->reuseHighlightedWord = 0;
@@ -698,7 +705,6 @@ preparePrefix:
prefixVowelRestriction = ZI8_FALSE;
}
}
goto prepareDictionaryOrder;
prepareDictionaryOrder:
((ZiAlphaWork*)workData)->dictionaryOrder[0] = 0;
if ((Zi8GetTableCount(language,0x1f,workData) & 0x20) != 0) {
@@ -770,11 +776,11 @@ prepareDictionaries:
if (dictionaryIndex != ((ZiAlphaWork*)workData)->dictionaryCount) {
dictionaryKind = ((ZiAlphaWork*)workData)->dictionaryKinds[dictionaryIndex];
if (dictionaryKind == 12) {
if (languagePassCount != 2) goto finishDictionaryPass;
if (languagePassCount != 2) continue;
goto selectDictionary;
}
} else {
if (((ZiAlphaOptions*)optionData)->lookupMode != 0) goto finishDictionaryPass;
if (((ZiAlphaOptions*)optionData)->lookupMode != 0) continue;
dictionaryKind = 10;
}
selectDictionary:
@@ -785,7 +791,7 @@ selectDictionary:
case 3:
case 4:
case 10:
goto finishDictionaryPass;
continue;
}
}
{
@@ -803,7 +809,7 @@ selectDictionary:
((parameters->currentWord == 0 ||
((parameters->wordCharCount == 0 ||
(parameters->currentWord[parameters->wordCharCount - 1] == 0x20))))))))
goto finishDictionaryPass;
continue;
if ((candidateCount == 0) &&
((((!punctuationCandidate && (parameters->firstCandidate == firstCandidate)) &&
((parameters->currentWord == 0 ||
@@ -829,10 +835,10 @@ selectDictionary:
punctuationCandidate = ZI8_FALSE;
break;
case 4:
if (((ZiAlphaOptions*)optionData)->minWordLength > elementCount) goto finishDictionaryPass;
if (((ZiAlphaOptions*)optionData)->minWordLength > elementCount) continue;
break;
case 3:
if (((ZiAlphaOptions*)optionData)->minWordLength > elementCount || elementCount == 1) goto finishDictionaryPass;
if (((ZiAlphaOptions*)optionData)->minWordLength > elementCount || elementCount == 1) continue;
break;
case 9:
if (elementCount == 1 && *elements >= 0xEFF1 && *elements <= 0xF010) {
@@ -841,7 +847,7 @@ selectDictionary:
}
default:
if (elementCount == 1 && prefixCount == 0 && *elements >= 0xEFF1 &&
*elements <= 0xF010 && !contextEnabled) goto finishDictionaryPass;
*elements <= 0xF010 && !contextEnabled) continue;
dictionaryExact = 0;
if (languagePassCount == 2) {
for (index = dictionaryIndex + 1; index < ((ZiAlphaWork*)workData)->dictionaryCount; index++) {
@@ -941,12 +947,12 @@ selectDictionary:
wordLength = 0;
}
}
if (wordLength != 0) goto filterVowelCandidate;
dictionaryStatus[dictionaryKind] = 1;
if (elements[apostropheIndex] >= 0xEFF1) goto retryDictionary;
goto finishDictionaryPass;
}
filterVowelCandidate:
if (wordLength == 0) {
dictionaryStatus[dictionaryKind] = 1;
if (elements[apostropheIndex] >= 0xEFF1) continue;
goto finishDictionaryPass;
}
}
if ((wordLength != 0) && (prefixVowelRestriction)) {
if ((*wordCursor >= 0x30) && (*wordCursor <= 0x39)) {
wordLength = 0;
@@ -974,7 +980,7 @@ filterVowelCandidate:
if (wordLength == 0) {
wordLength = 0;
dictionaryStatus[dictionaryKind] = 1;
goto retryDictionary;
continue;
}
}
if (wordLength != 0) {
@@ -1015,6 +1021,7 @@ filterVowelCandidate:
}
break;
case 10:
/* MWCC needs the stored punctuation character as the branch value. */
if ((*wordCursor = *punctuationCursor) != 0) {
punctuationCursor++;
wordLength = 1;
@@ -1078,7 +1085,7 @@ filterVowelCandidate:
punctuationCursor = &punctuationBuffer[0];
dictionaryKind = 0xb;
retryPunctuation = ZI8_TRUE;
goto retryDictionary;
continue;
}
}
if ((((((dictionaryExact == 0) || (!currentVowelRestriction)) || (prefixCount != 0)) ||
@@ -1096,11 +1103,10 @@ filterVowelCandidate:
case 7:
case 8:
case 12:
goto prepareRememberedPunctuation;
break;
default:
goto finishDictionaryPass;
}
prepareRememberedPunctuation:
if (Zi8getKeyLayout(language,0xeff1,&punctuationBuffer[0],1,workData) == 0) {
punctuationBuffer[0] = 0;
}
@@ -1109,18 +1115,17 @@ prepareRememberedPunctuation:
}
else if (((ZiAlphaOptions*)optionData)->minWordLength <= wordLength) {
if (prefixVowelRestriction) {
if (*wordCursor >= 0x30 && *wordCursor <= 0x39) goto retryDictionary;
if (*wordCursor >= 0x30 && *wordCursor <= 0x39) continue;
if (language == 0x2f) {
if (Zi8ITspecialExclusion(wordCursor,prefixCount,wordLength) != 0) goto retryDictionary;
if (Zi8ITspecialExclusion(wordCursor,prefixCount,wordLength) != 0) continue;
} else if (language == 0x58) {
if (Zi8_814659E8(wordCursor,prefixCount,wordLength) != 0) goto retryDictionary;
if (Zi8_814659E8(wordCursor,prefixCount,wordLength) != 0) continue;
} else if (Zi8IsVowel(language,*wordCursor) == 0) {
wordLength = 0;
goto retryDictionary;
continue;
}
}
{
prepareCandidate:
if (((elementCount == 1) && (dictionaryKind != 10)) &&
((*wordCursor >= 0xeff1 && *wordCursor <= 0xf010))) {
punctuationCandidate = ZI8_TRUE;
@@ -1163,7 +1168,6 @@ prepareCandidate:
case 5:
case 1:
case 9:
checkKeyLayout:
keyLayoutCursor = keyLayout;
candidateCharacterCount = wordLength + prefixCount;
for (index = 0; (int)index < (int)(unsigned int)keyLayoutCount; index = index + 1) {
@@ -1555,20 +1559,27 @@ checkPrefixPunctuation:
goto preparePrefix;
}
}
if (!completionAllowed && ((ZiAlphaWork*)workData)->suffixMode == 0 && ((ZiAlphaWork*)workData)->prefixCount != 0 &&
elementCount > 2 && ((ZiAlphaWork*)workData)->prefixCount == elementCount - 1 &&
Zi8IsAlphaPunct(parameters->elements[((ZiAlphaWork*)workData)->prefixCount - 1]) != 0) goto checkPrefixFields;
if (!completionAllowed && ((ZiAlphaWork*)workData)->suffixMode == 0 && parameters->elementCount > 1 &&
Zi8IsAlphaPunct(parameters->elements[parameters->elementCount - 1]) == 0) goto finishCandidates;
checkPrefixFields:
if (completionAllowed ||
((ZiAlphaWork*)workData)->suffixMode != 0 ||
((ZiAlphaWork*)workData)->prefixCount == 0 ||
elementCount <= 2 ||
((ZiAlphaWork*)workData)->prefixCount != elementCount - 1 ||
Zi8IsAlphaPunct(parameters->elements[((ZiAlphaWork*)workData)->prefixCount - 1]) == 0) {
if (!completionAllowed && ((ZiAlphaWork*)workData)->suffixMode == 0 && parameters->elementCount > 1 &&
Zi8IsAlphaPunct(parameters->elements[parameters->elementCount - 1]) == 0) goto finishCandidates;
}
prefixMode = ((ZiAlphaWork*)workData)->suffixMode;
prefixLength = ((ZiAlphaWork*)workData)->prefixCount;
if (prefixMode != 0 || prefixLength == 0 || elementCount <= 2 ||
prefixLength != elementCount - 1 || parameters->elements[parameters->elementCount - 1] == 0xEFF1) goto finishCandidates;
((ZiAlphaWork*)workData)->suffixMode = 1;
((ZiAlphaWork*)workData)->prefixElementCount = parameters->elementCount;
prefixPrepared = ZI8_TRUE;
goto preparePrefix;
if (prefixMode == 0 &&
prefixLength != 0 &&
elementCount > 2 &&
prefixLength == elementCount - 1 &&
parameters->elements[parameters->elementCount - 1] != 0xEFF1) {
((ZiAlphaWork*)workData)->suffixMode = 1;
((ZiAlphaWork*)workData)->prefixElementCount = parameters->elementCount;
prefixPrepared = ZI8_TRUE;
goto preparePrefix;
}
finishCandidates:
((ZiAlphaWork*)workData)->usePrefixAsElements = 0;

View File

@@ -1,105 +1,95 @@
#include <zi8clib/zitypes.h>
ziU16 Zi8MatchAltSound(ziU8* elements, ziU16 count, ziU8* table, ziU16 ch,
ziU16 Zi8MatchAltSound(ziU8* elements, ziU16 count, ziU8* table, ziU16 ordinal,
ziU32 mask, ziU16 target, ziU8 flags ZI_NEED_WORK) {
ziU8 hi;
ziU8 lo;
ziS32 i;
ziS32 j;
ziS32 mid;
ziU16 off;
ziU16 w;
ziU8 ordinalHigh;
ziU8 ordinalLow;
ziS32 recordIndex;
ziS32 searchIndex;
ziS32 midpoint;
ziU16 phoneticOffset;
ziU16 phoneticCode;
hi = (ziU8)(ch >> 8);
lo = (ziU8)ch;
ordinalHigh = (ziU8)(ordinal >> 8);
ordinalLow = (ziU8)ordinal;
flags = (ziU8)(flags >> 3);
if (count == 0) {
return 0;
}
j = 0;
i = count - 1;
if ((elements + i * 4)[1] == hi && (elements + i * 4)[0] == lo) {
j = i;
goto up;
searchIndex = 0;
recordIndex = count - 1;
if ((elements + recordIndex * 4)[1] == ordinalHigh && (elements + recordIndex * 4)[0] == ordinalLow) {
searchIndex = recordIndex;
} else {
if ((elements + searchIndex * 4)[1] != ordinalHigh || (elements + searchIndex * 4)[0] != ordinalLow) {
goto search;
}
}
if ((elements + j * 4)[1] == hi && (elements + j * 4)[0] == lo) {
goto up;
}
goto search;
up:
i = j;
recordIndex = searchIndex;
do {
if (((elements + i * 4)[3] & 0xE) == 0 ||
((elements + i * 4)[3] & flags) != 0) {
off = (ziU16)(((ziU16)(elements + i * 4)[2] |
(((ziU16)(elements + i * 4)[3] & 1) << 8)) << 1);
w = (ziU16)((((ziU16)(elements + i * 4)[3] & 0xF0) >> 4) |
(table[off] | ((ziU16)table[off + 1] << 8)));
if (target == (w & (ziU16)mask)) {
return w;
if (((elements + recordIndex * 4)[3] & 0xE) == 0 ||
((elements + recordIndex * 4)[3] & flags) != 0) {
phoneticOffset = (ziU16)(((ziU16)(elements + recordIndex * 4)[2] |
(((ziU16)(elements + recordIndex * 4)[3] & 1) << 8)) << 1);
phoneticCode = (ziU16)((((ziU16)(elements + recordIndex * 4)[3] & 0xF0) >> 4) |
(table[phoneticOffset] | ((ziU16)table[phoneticOffset + 1] << 8)));
if (target == (phoneticCode & (ziU16)mask)) {
return phoneticCode;
}
}
i++;
if (i >= count) {
recordIndex++;
if (recordIndex >= count) {
break;
}
} while ((elements + i * 4)[1] == hi && (elements + i * 4)[0] == lo);
i = j;
goto dec;
down_body:
if (((elements + i * 4)[3] & 0xE) == 0 ||
((elements + i * 4)[3] & flags) != 0) {
off = (ziU16)(((ziU16)(elements + i * 4)[2] |
(((ziU16)(elements + i * 4)[3] & 1) << 8)) << 1);
w = (ziU16)((((ziU16)(elements + i * 4)[3] & 0xF0) >> 4) |
(table[off] | ((ziU16)table[off + 1] << 8)));
if (target == (w & (ziU16)mask)) {
return w;
} while ((elements + recordIndex * 4)[1] == ordinalHigh && (elements + recordIndex * 4)[0] == ordinalLow);
recordIndex = searchIndex;
while (--recordIndex >= 0 && (elements + recordIndex * 4)[1] == ordinalHigh && (elements + recordIndex * 4)[0] == ordinalLow) {
if (((elements + recordIndex * 4)[3] & 0xE) == 0 ||
((elements + recordIndex * 4)[3] & flags) != 0) {
phoneticOffset = (ziU16)(((ziU16)(elements + recordIndex * 4)[2] |
(((ziU16)(elements + recordIndex * 4)[3] & 1) << 8)) << 1);
phoneticCode = (ziU16)((((ziU16)(elements + recordIndex * 4)[3] & 0xF0) >> 4) |
(table[phoneticOffset] | ((ziU16)table[phoneticOffset + 1] << 8)));
if (target == (phoneticCode & (ziU16)mask)) {
return phoneticCode;
}
}
}
dec:
i--;
if (i < 0) {
goto fail;
}
if ((elements + i * 4)[1] == hi && (elements + i * 4)[0] == lo) {
goto down_body;
}
fail:
return 0;
search:
if ((elements + j * 4)[1] == hi && (elements + j * 4)[0] == lo) {
if ((elements + searchIndex * 4)[1] == ordinalHigh && (elements + searchIndex * 4)[0] == ordinalLow) {
goto up;
}
if ((((ziU16)(elements + j * 4)[1] << 8) | (ziU16)(elements + j * 4)[0]) > ch) {
if ((((ziU16)(elements + searchIndex * 4)[1] << 8) | (ziU16)(elements + searchIndex * 4)[0]) > ordinal) {
return 0;
}
mid = (j + i) / 2;
if (mid == j) {
midpoint = (searchIndex + recordIndex) / 2;
if (midpoint == searchIndex) {
return 0;
}
if ((((ziU16)(elements + mid * 4)[1] << 8) | (ziU16)(elements + mid * 4)[0]) >= ch) {
i = mid;
goto hi_check;
if ((((ziU16)(elements + midpoint * 4)[1] << 8) | (ziU16)(elements + midpoint * 4)[0]) >= ordinal) {
recordIndex = midpoint;
} else {
searchIndex = midpoint;
goto search;
}
j = mid;
goto search;
hi_check:
if ((elements + i * 4)[1] == hi && (elements + i * 4)[0] == lo) {
j = i;
if ((elements + recordIndex * 4)[1] == ordinalHigh && (elements + recordIndex * 4)[0] == ordinalLow) {
searchIndex = recordIndex;
goto up;
}
if ((((ziU16)(elements + i * 4)[1] << 8) | (ziU16)(elements + i * 4)[0]) < ch) {
if ((((ziU16)(elements + recordIndex * 4)[1] << 8) | (ziU16)(elements + recordIndex * 4)[0]) < ordinal) {
return 0;
}
mid = (j + i) / 2;
if (mid == j) {
midpoint = (searchIndex + recordIndex) / 2;
if (midpoint == searchIndex) {
return 0;
}
if ((((ziU16)(elements + mid * 4)[1] << 8) | (ziU16)(elements + mid * 4)[0]) >= ch) {
i = mid;
if ((((ziU16)(elements + midpoint * 4)[1] << 8) | (ziU16)(elements + midpoint * 4)[0]) >= ordinal) {
recordIndex = midpoint;
goto hi_check;
}
j = mid;
searchIndex = midpoint;
goto search;
}

File diff suppressed because it is too large Load Diff

View File

@@ -643,7 +643,7 @@ ziU32 Zi8GetSInfo(ziU8* strokes, ziU8* extraStrokes, ziWChar* outputBuffer, ziU8
{
int strokeIndex;
int outputCount;
volatile int extraCount;
int extraCount;
outputCount = 0;
Zi8LogError(100, work);
@@ -652,17 +652,14 @@ ziU32 Zi8GetSInfo(ziU8* strokes, ziU8* extraStrokes, ziWChar* outputBuffer, ziU8
return 0;
}
for (strokeIndex = 0; strokeIndex < 4; strokeIndex++) {
if (strokeIndex == 0) {
goto lowStroke;
}
outputBuffer[(ziU8)outputCount] = zi8StrokeCode((strokes[strokeIndex] & 0xf0) >> 4, work);
if (outputBuffer[(ziU8)outputCount++] != 0) {
goto lowStroke;
}
if (strokeIndex != 0) {
outputBuffer[(ziU8)outputCount] = zi8StrokeCode((strokes[strokeIndex] & 0xf0) >> 4, work);
if (outputBuffer[(ziU8)outputCount++] == 0) {
badStroke:
outputBuffer[(ziU8)--outputCount] = 0;
return outputCount;
lowStroke:
outputBuffer[(ziU8)--outputCount] = 0;
return outputCount;
}
}
outputBuffer[(ziU8)outputCount] = zi8StrokeCode(strokes[strokeIndex] & 0xf, work);
if (outputBuffer[(ziU8)outputCount++] == 0) {
goto badStroke;
@@ -939,7 +936,6 @@ ziU32 ZiCharInfo2(ziWChar ch, ziWChar* charInfoBuffer, ziU8 maxInfoBufSize, ziU3
}
Zi8LogError(100,work);
return count;
}
index++;
tablePtr = tablePtr + 4;

View File

@@ -64,6 +64,7 @@ ziU32 Zi8MatchROMdata0(ziWChar* elements, ziU8 count, ziU8 language,
key = Zi8GetTableSize(language, keyTable, ZI_WORK);
if (key != 0 && ZI_WORK->userKeys[language] == 0) {
index = 0;
/* MWCC needs the key-count branch in the loop test block. */
goto check_keys;
next_key:
{
@@ -99,7 +100,7 @@ check_keys:
searching = 1;
current = &records[context->cnt - 1];
while (searching && context->cnt != 0 && current->node != (ziU8*)context->endNode) {
if (capacity < context->cnt) goto finish_graph;
if (capacity < context->cnt) break;
current->attr = ZiDAWGgetCHARattribute(context, current->node, ZI_WORK);
if (context->cnt <= count) {
if (context->keyCodes == 0) {
@@ -123,30 +124,32 @@ check_keys:
}
if (context->cnt < count) goto descend;
}
if (context->cnt < search[1]) goto descend;
if (search[0] != 0 && context->cnt > search[1]) goto next_sibling;
if (acceptPrefix != 0 || ZiDAWGgetEOWattribute(current->node)) {
for (index = 0; index < context->cnt; index++) output[index] = (ziU16)records[index].attr;
result = context->cnt;
searching = 0;
if (acceptPrefix != 0) goto next_sibling;
if (context->cnt >= search[1]) {
if (search[0] != 0 && context->cnt > search[1]) goto next_sibling;
if (acceptPrefix != 0 || ZiDAWGgetEOWattribute(current->node)) {
for (index = 0; index < context->cnt; index++) output[index] = (ziU16)records[index].attr;
result = context->cnt;
searching = 0;
if (acceptPrefix != 0) goto next_sibling;
}
if (search[0] != 0 && context->cnt >= search[1]) goto next_sibling;
}
if (search[0] != 0 && context->cnt >= search[1]) goto next_sibling;
descend:
records[context->cnt].node = ZiDAWGGetChild(records[context->cnt - 1].node);
if (records[context->cnt].node == (ziU8*)0) goto next_sibling;
context->cnt++;
if (ZI_WORK->maxCnt < context->cnt) ZI_WORK->maxCnt = context->cnt;
goto update_current;
if (records[context->cnt].node != (ziU8*)0) {
context->cnt++;
if (ZI_WORK->maxCnt < context->cnt) ZI_WORK->maxCnt = context->cnt;
} else {
next_sibling:
while (context->cnt != 0) {
records[context->cnt - 1].node = ZiDAWGGetSibling(records[context->cnt - 1].node);
if (records[context->cnt - 1].node != (ziU8*)0) break;
context->cnt--;
while (context->cnt != 0) {
records[context->cnt - 1].node = ZiDAWGGetSibling(records[context->cnt - 1].node);
if (records[context->cnt - 1].node != (ziU8*)0) break;
context->cnt--;
}
}
update_current:
current = &records[context->cnt - 1];
}
finish_graph:
return result;
}

View File

@@ -4,7 +4,7 @@ extern ziU16 Zi8GetTableCount(ziU8 lang, ziU8 tableIdx ZI_NEED_WORK);
extern ziU8 Zi8getKeyLayout(ziU8 lang, ziU16 key, ziWChar* layout, ziU8 mode ZI_NEED_WORK);
extern ziChar Zi8ConvertWC2UC(ziWChar ch, ziU8 language ZI_NEED_WORK);
extern ziU32 Zi8AlphaGetCandidates(ziGetParam* param, ziPtr sw ZI_NEED_WORK);
extern ziU8 Zi8SyllablesROMdata(ziWChar* keys, ziU8 count, ziU8 lang, ziWChar* out,
extern ziU8 Zi8SyllablesROMdata(ziWChar* keys, ziU8 keyCount, ziU8 lang, ziWChar* output,
ziU16 a, ziU8 b, ziU8* cntOut, ziU8 c ZI_NEED_WORK);
typedef struct _ziSwParam {
@@ -20,197 +20,191 @@ typedef struct _ziSwParam {
} ziSwParam;
ziU32 Zi8GetSyllablesCandidates(ziGetParam* param, ziSwParam* sw ZI_NEED_WORK) {
ziWChar buf[0x40];
ziWChar buf2[0x32];
ziS32 rem;
ziS32 cur;
ziS32 firstCand;
ziS32 count;
ziWChar* pNext;
ziU16 err;
ziU8 flag14;
ziU8 flag13;
ziU8 flag12;
ziU8 flag11;
ziU8 sylCnt;
ziWChar* out;
ziU8* u28;
ziS32 i;
ziWChar syllableBuffer[0x40];
ziWChar keyLayout[0x32];
ziS32 remainingCapacity;
ziS32 syllableLength;
ziS32 remainingSkip;
ziS32 candidateCount;
ziWChar* nextCharacter;
ziU16 error;
ziU8 allowHyphen;
ziU8 needKeyFallback;
ziU8 nextMatch;
ziU8 reverseOrder;
ziU8 matchedLength;
ziWChar* output;
ziU8* encodedOutput;
ziS32 index;
firstCand = param->firstCandidate;
count = 0;
u28 = 0;
pNext = 0;
flag14 = 1;
flag13 = 1;
flag12 = 0;
flag11 = 0;
sylCnt = 0;
err = 0x64;
remainingSkip = param->firstCandidate;
candidateCount = 0;
encodedOutput = 0;
nextCharacter = 0;
allowHyphen = 1;
needKeyFallback = 1;
nextMatch = 0;
reverseOrder = 0;
matchedLength = 0;
error = 0x64;
if (param->currentWord != 0 && param->wordCharCount != 0 &&
param->currentWord[param->wordCharCount - 1] != 0x20) {
flag11 = 1;
reverseOrder = 1;
}
if (param->elementCount == 0 || (param->elementCount == 1 && flag11 == 0)) {
count = Zi8AlphaGetCandidates(param, sw, ZI_WORK);
if (param->elementCount == 0 || (param->elementCount == 1 && reverseOrder == 0)) {
candidateCount = Zi8AlphaGetCandidates(param, sw, ZI_WORK);
goto end;
}
if (sw->countOnly != 0 || (param->getOptions & 0xFD) != 0x81) {
out = buf;
rem = 0x40;
output = syllableBuffer;
remainingCapacity = 0x40;
} else {
out = param->candidates;
rem = sw->capacity - 1;
output = param->candidates;
remainingCapacity = sw->capacity - 1;
}
if ((param->getOptions & 0xFD) == 0x80) {
u28 = (ziU8*)param->candidates;
rem = sw->capacity - 1;
encodedOutput = (ziU8*)param->candidates;
remainingCapacity = sw->capacity - 1;
}
if (rem <= param->elementCount) {
err = 0x168;
if (remainingCapacity <= param->elementCount) {
error = 0x168;
goto end;
}
if ((Zi8GetTableCount(param->language, 0x1F, ZI_WORK) & 8) != 0) {
flag14 = 0;
allowHyphen = 0;
}
if (param->elements[0] == 0xEFF1 && param->elementCount > 1 && flag14 != 0) {
buf[0] = 0x2D;
if (param->elements[0] == 0xEFF1 && param->elementCount > 1 && allowHyphen != 0) {
syllableBuffer[0] = 0x2D;
} else {
Zi8getKeyLayout(param->language, param->elements[0], buf, 1, ZI_WORK);
Zi8getKeyLayout(param->language, param->elements[0], syllableBuffer, 1, ZI_WORK);
}
out[0] = buf[0];
Zi8SyllablesROMdata(param->elements, param->elementCount, param->language, out,
(ziU16)rem, 0, &sylCnt, flag11, ZI_WORK);
if (sylCnt != 0) {
cur = sylCnt;
output[0] = syllableBuffer[0];
Zi8SyllablesROMdata(param->elements, param->elementCount, param->language, output,
(ziU16)remainingCapacity, 0, &matchedLength, reverseOrder, ZI_WORK);
if (matchedLength != 0) {
syllableLength = matchedLength;
} else {
cur = 1;
syllableLength = 1;
}
if (cur == param->elementCount) goto L5dc;
if (firstCand != 0) {
firstCand--;
goto L5dc;
}
if (sw->countOnly != 0) {
if (++count >= sw->maxCount) goto end;
goto L5dc;
}
for (i = cur; i < param->elementCount; i += sylCnt) {
if (param->elements[i] == 0xEFF1 && param->elementCount - i > 1 && flag14 != 0) {
buf2[0] = 0x2D;
if (syllableLength != param->elementCount) {
if (remainingSkip != 0) {
remainingSkip--;
} else if (sw->countOnly != 0) {
if (++candidateCount >= sw->maxCount) goto end;
} else {
Zi8getKeyLayout(param->language, param->elements[i], buf2, 1, ZI_WORK);
}
out[i] = buf2[0];
Zi8SyllablesROMdata(param->elements + i, param->elementCount - i, param->language,
out + i, (ziU16)rem, 0, &sylCnt, 1, ZI_WORK);
if (sylCnt == 0) {
sylCnt = 1;
}
}
if (u28 != 0) {
for (i = 0; i < param->elementCount; i++) {
u28[i] = Zi8ConvertWC2UC(out[i], param->language, ZI_WORK);
}
u28[i++] = 0;
u28[i] = 0;
u28 += i;
} else {
out[i++] = 0;
out[i] = 0;
out += i;
}
rem -= i;
if (++count >= param->maxCandidates) goto end;
if (rem > param->elementCount) goto L5dc;
goto end;
L5dc:
while (cur >= 1) {
flag12 = 0;
goto rom;
found:
flag12 = 1;
if (cur == 1) {
flag13 = 0;
}
L464:
if (out[0] >= 0xEFF1 && out[0] <= 0xF010) {
goto dec;
}
L464b:
if (firstCand != 0) {
firstCand--;
goto L560;
}
if (sw->countOnly != 0) {
if (++count >= sw->maxCount) goto end;
goto L560;
}
if (u28 != 0) {
for (i = 0; i < cur; i++) {
u28[i] = Zi8ConvertWC2UC(out[i], param->language, ZI_WORK);
for (index = syllableLength; index < param->elementCount; index += matchedLength) {
if (param->elements[index] == 0xEFF1 && param->elementCount - index > 1 && allowHyphen != 0) {
keyLayout[0] = 0x2D;
} else {
Zi8getKeyLayout(param->language, param->elements[index], keyLayout, 1, ZI_WORK);
}
output[index] = keyLayout[0];
Zi8SyllablesROMdata(param->elements + index, param->elementCount - index, param->language,
output + index, (ziU16)remainingCapacity, 0, &matchedLength, 1, ZI_WORK);
if (matchedLength == 0) {
matchedLength = 1;
}
}
u28[i++] = 0;
u28[i] = 0;
u28 += i;
} else {
i = cur;
out[i++] = 0;
out[i] = 0;
out += i;
if (encodedOutput != 0) {
for (index = 0; index < param->elementCount; index++) {
encodedOutput[index] = Zi8ConvertWC2UC(output[index], param->language, ZI_WORK);
}
encodedOutput[index++] = 0;
encodedOutput[index] = 0;
encodedOutput += index;
} else {
output[index++] = 0;
output[index] = 0;
output += index;
}
remainingCapacity -= index;
if (++candidateCount >= param->maxCandidates) goto end;
/* MWCC needs the forward capacity branch before the common exit. */
if (remainingCapacity > param->elementCount) goto search_syllables;
goto end;
}
rem -= i;
if (++count >= param->maxCandidates) goto end;
if (rem <= cur) goto end;
L560:
if (pNext != 0) {
if (*pNext == 0) goto end;
out[0] = *pNext++;
goto L464b;
}
rom:
if (Zi8SyllablesROMdata(param->elements, (ziU8)cur, param->language, out,
(ziU16)rem, flag12, 0, flag11, ZI_WORK) != 0) {
goto found;
}
dec:
cur--;
}
if (flag13 == 0) goto end;
if (param->elements[0] == 0xEFF1 && param->elementCount > 1 && flag14 != 0) {
buf2[0] = 0x2D;
buf2[1] = 0;
Zi8getKeyLayout(param->language, param->elements[0], &buf2[1], 1, ZI_WORK);
for (i = 1; buf2[i] != 0; i++) {
if (buf2[i] == 0x2D) break;
search_syllables:
for (; syllableLength >= 1; syllableLength--) {
nextMatch = 0;
goto match_syllable;
syllable_found:
nextMatch = 1;
if (syllableLength == 1) {
needKeyFallback = 0;
}
while (buf2[i] != 0) {
buf2[i] = buf2[i + 1];
i++;
if (output[0] >= 0xEFF1 && output[0] <= 0xF010) {
continue;
}
emit_syllable:
if (remainingSkip != 0) {
remainingSkip--;
} else if (sw->countOnly != 0) {
if (++candidateCount >= sw->maxCount) goto end;
} else {
if (encodedOutput != 0) {
for (index = 0; index < syllableLength; index++) {
encodedOutput[index] = Zi8ConvertWC2UC(output[index], param->language, ZI_WORK);
}
encodedOutput[index++] = 0;
encodedOutput[index] = 0;
encodedOutput += index;
} else {
index = syllableLength;
output[index++] = 0;
output[index] = 0;
output += index;
}
remainingCapacity -= index;
if (++candidateCount >= param->maxCandidates) goto end;
if (remainingCapacity <= syllableLength) goto end;
}
next_syllable:
if (nextCharacter != 0) {
if (*nextCharacter == 0) goto end;
output[0] = *nextCharacter++;
goto emit_syllable;
}
match_syllable:
if (Zi8SyllablesROMdata(param->elements, (ziU8)syllableLength, param->language, output,
(ziU16)remainingCapacity, nextMatch, 0, reverseOrder, ZI_WORK) != 0) {
goto syllable_found;
}
} else {
Zi8getKeyLayout(param->language, param->elements[0], buf2, 1, ZI_WORK);
}
cur = 1;
pNext = buf2;
goto L560;
if (needKeyFallback != 0) {
if (param->elements[0] == 0xEFF1 && param->elementCount > 1 && allowHyphen != 0) {
keyLayout[0] = 0x2D;
keyLayout[1] = 0;
Zi8getKeyLayout(param->language, param->elements[0], &keyLayout[1], 1, ZI_WORK);
for (index = 1; keyLayout[index] != 0; index++) {
if (keyLayout[index] == 0x2D) break;
}
while (keyLayout[index] != 0) {
keyLayout[index] = keyLayout[index + 1];
index++;
}
} else {
Zi8getKeyLayout(param->language, param->elements[0], keyLayout, 1, ZI_WORK);
}
syllableLength = 1;
nextCharacter = keyLayout;
goto next_syllable;
}
end:
if (sw->countOnly != 0) {
param->letters = 0;
} else {
param->letters = (ziU8)count;
param->letters = (ziU8)candidateCount;
}
Zi8LogError(err, ZI_WORK);
return count;
Zi8LogError(error, ZI_WORK);
return candidateCount;
}

View File

@@ -66,18 +66,17 @@ retry:
getParam.getMode = 0;
if (_Zi8GetCandidates(&getParam, __zi8_work_data) != 0) {
charSet |= getParam.subLanguage;
goto next;
} else {
getParam.getMode = 1;
if (_Zi8GetCandidates(&getParam, __zi8_work_data) != 0) {
charSet |= getParam.subLanguage;
} else {
getParam.getMode = 2;
if (_Zi8GetCandidates(&getParam, __zi8_work_data) != 0) {
charSet |= getParam.subLanguage;
}
}
}
getParam.getMode = 1;
if (_Zi8GetCandidates(&getParam, __zi8_work_data) != 0) {
charSet |= getParam.subLanguage;
goto next;
}
getParam.getMode = 2;
if (_Zi8GetCandidates(&getParam, __zi8_work_data) != 0) {
charSet |= getParam.subLanguage;
}
next:
if (getParam.subLanguage == 1) {
getParam.subLanguage = 4;
goto retry;

View File

@@ -318,11 +318,11 @@ ziBool Zi8MatchPhonetic(ziU8* pCodeTable, ziU8* dictionary, ziPtr soundTable, zi
altMode = 1;
}
while (remaining-- != 0) {
if ((node[0] & flag) != 0) goto decode_node;
if ((node[0] & flag) == 0) {
next_node:
node += 0xC;
continue;
decode_node:
node += 0xC;
continue;
}
code = Zi8GetPCode(pCodeTable, node);
if ((*values != (code & *masks)) && (altMode == 0) && ((node[0] & 0x80) != 0)) {
if (*count != 0) {
@@ -370,6 +370,7 @@ match_code:
*count = remaining;
return 1;
}
/* MWCC needs the group-end branch before the backward group jump. */
next_group:
{
nextCode = *sound++;
@@ -392,15 +393,14 @@ next_group:
do {
dictionaryIndex = sound[0] | ((ziU16)sound[1] << 8);
sound += 2;
if (hasString) {
goto phonetic_skip;
}
code = Zi8GetPCode(pCodeTable, dictionary + (dictionaryIndex & 0x7FFF) * sizeof(DictionaryNode));
if (((code & masks[partIndex]) != values[partIndex]) && (altMode == 0) && (dictionary[(dictionaryIndex & 0x7FFF) * sizeof(DictionaryNode)] & 0x80) != 0) {
code = Zi8MatchAltSound(soundTable, soundCode, pCodeTable, dictionaryIndex & 0x7FFF, masks[partIndex], values[partIndex], flag, ZI_WORK);
}
if ((code & masks[partIndex]) == values[partIndex]) {
goto phonetic_matched;
if (!hasString) {
code = Zi8GetPCode(pCodeTable, dictionary + (dictionaryIndex & 0x7FFF) * sizeof(DictionaryNode));
if (((code & masks[partIndex]) != values[partIndex]) && (altMode == 0) && (dictionary[(dictionaryIndex & 0x7FFF) * sizeof(DictionaryNode)] & 0x80) != 0) {
code = Zi8MatchAltSound(soundTable, soundCode, pCodeTable, dictionaryIndex & 0x7FFF, masks[partIndex], values[partIndex], flag, ZI_WORK);
}
if ((code & masks[partIndex]) == values[partIndex]) {
goto phonetic_matched;
}
}
phonetic_skip:
if ((dictionaryIndex & 0x8000) == 0) {
@@ -479,17 +479,14 @@ ziU8 Zi8GetPyPhonetic(ziWChar* text, ziU8 count, ziU16* initial, ziU16* final, z
initial[outputIndex] = 0;
final[outputIndex] = 0;
value = *current;
if (value < 0x61) {
goto check_pinyin_extension;
if (value >= 0x61) {
if (value <= 0x7A) {
goto pinyin_ascii;
}
}
if (value <= 0x7A) {
goto pinyin_ascii;
if (value >= 0xF361) {
if (value <= 0xF37A) goto pinyin_extension;
}
check_pinyin_extension:
if (value < 0xF361) {
goto invalid_pinyin;
}
if (value <= 0xF37A) goto pinyin_extension;
invalid_pinyin:
*bestInitial = *bestFinal = initial[0] = final[0] = 0xFFFF;
return 1;
@@ -520,23 +517,23 @@ pinyin_initial:
final[outputIndex] &= 0xfdff;
}
value = *current;
if (value != 0x68 && value != 0xF368) goto scan_final;
if (outputIndex == 0) {
*resultCount += 1;
if (value == 0x68 || value == 0xF368) {
if (outputIndex == 0) {
*resultCount += 1;
}
final[outputIndex] += 0x200;
*bestInitial = initial[0];
*bestFinal = final[0];
count--;
if (count == 0) {
break;
}
current += 1;
}
final[outputIndex] += 0x200;
*bestInitial = initial[0];
*bestFinal = final[0];
count--;
if (count == 0) {
break;
}
current += 1;
}
} else if ((*current == 0xF369) || (*current == 0x69)) {
goto invalid_pinyin;
}
scan_final:
partial = 0;
for (index = 0; index < 4; index++) {
pinyin[index] = 0;
@@ -548,41 +545,41 @@ scan_final:
if (index != 0) {
partial = 1;
}
goto finish_final;
break;
}
if ((value >= 0xF331) && (value < 0xF336)) {
if (index != 0) {
partial = 1;
}
goto finish_final;
break;
}
if ((value < 0x61) || (value > 0x7A)) {
if (value < 0xF361) {
goto finish_final;
break;
}
value -= 0xF361;
if (value > 0x19) {
if (outputIndex == 0) {
*resultCount += 1;
}
goto finish_final;
break;
}
} else {
value -= 0x61;
}
pinyin[index] = (ziU8)value + 1;
if (!Zi8GetPyFinal(pinyin, &pyInitial, &pyFinal)) goto try_final_extension;
if (outputIndex == 0) {
*resultCount += 1;
if (Zi8GetPyFinal(pinyin, &pyInitial, &pyFinal)) {
if (outputIndex == 0) {
*resultCount += 1;
}
current++;
index++;
count--;
if (count == 0) {
break;
}
continue;
}
current++;
index++;
count--;
if (count == 0) {
goto finish_final;
}
continue;
try_final_extension:
if (index < 3) {
pinyin[index + 1] = 0xFF;
@@ -608,13 +605,15 @@ try_final_extension:
}
}
finish_final:
if ((index > 3) && (count != 0) && (((value = *current) == 0x27) || (value == 0xF360) || (value == 0x20))) {
if (outputIndex == 0) {
*resultCount += 1;
if (index > 3 && count != 0) {
value = *current;
if (value == 0x27 || value == 0xF360 || value == 0x20) {
if (outputIndex == 0) {
*resultCount += 1;
}
current++;
count--;
}
current++;
count--;
}
if (index > 3) {
partial = 1;
@@ -681,23 +680,29 @@ finish_final:
if (outputIndex == 0) {
*resultCount = *resultCount + 1;
}
} else if ((value >= 0xF331) && ((value -= 0xF331) <= 4)) {
value++;
initial[outputIndex] |= 7;
final[outputIndex] |= value;
*bestInitial = initial[0];
*bestFinal = final[0];
count--;
current++;
if (outputIndex == 0) {
*resultCount = *resultCount + 1;
}
if ((count != 0) && (((value = *current) == 0x27) || (value == 0xF360) || (value == 0x20))) {
} else if (value >= 0xF331) {
value -= 0xF331;
if (value <= 4) {
value++;
initial[outputIndex] |= 7;
final[outputIndex] |= value;
*bestInitial = initial[0];
*bestFinal = final[0];
count--;
current++;
if (outputIndex == 0) {
*resultCount = *resultCount + 1;
}
if (count != 0) {
value = *current;
if (value == 0x27 || value == 0xF360 || value == 0x20) {
count--;
current++;
if (outputIndex == 0) {
*resultCount = *resultCount + 1;
}
}
}
}
}
}
@@ -707,33 +712,26 @@ finish_final:
*resultCount -= 1;
}
return result;
}
ziBool Zi8GetPyFinal(ziU8* pinyin, ziU8* initial, ziU8* final) {
ziU8 index = 0;
ziU8 row;
row = 0;
goto check_row;
scan_row:
while (index < 4) {
if (pinyin[index] != Zi8PinyinFinals[row][index]) {
break;
while (row < 0x36) {
while (index < 4) {
if (pinyin[index] != Zi8PinyinFinals[row][index]) {
break;
}
index++;
}
index++;
}
if (index < 4) {
goto next_row;
}
*initial = Zi8PinyinFinals[row][4];
*final = Zi8PinyinFinals[row][5];
return 1;
next_row:
row++;
index = 0;
check_row:
if (row < 0x36) {
goto scan_row;
if (index >= 4) {
*initial = Zi8PinyinFinals[row][4];
*final = Zi8PinyinFinals[row][5];
return 1;
}
row++;
index = 0;
}
return 0;
}
@@ -787,52 +785,43 @@ ziU8 Zi8GetBpmfPhonetic(ziWChar* text, ziU8 count, ziU16* initial, ziU16* final,
value = *text - 0xF305;
switch ((ziS32)value) {
case 0x22:
goto bpmf_value_22;
case 0x23:
goto bpmf_value_23;
case 0x24:
goto bpmf_value_24;
default:
goto set_bpmf_initial;
}
bpmf_value_22:
*final |= 0x80;
*initial |= 0x180;
resultCount++;
if (--count == 0) {
*bestInitial = *initial | 0x78;
*bestFinal = *final | 0x38;
return resultCount;
}
text++;
goto after_bpmf_initial;
bpmf_value_23:
*final |= 0x100;
*initial |= 0x180;
resultCount++;
if (--count == 0) {
*bestInitial = *initial | 0x78;
*bestFinal = *final | 0x38;
return resultCount;
}
text++;
goto after_bpmf_initial;
bpmf_value_24:
*final |= 0x180;
*initial |= 0x180;
resultCount++;
if (--count == 0) {
*bestInitial = *initial | 0x78;
*bestFinal = *final | 0x38;
return resultCount;
}
text++;
goto after_bpmf_initial;
set_bpmf_initial:
if ((*text < 0xF331) || (*text > 0xF335)) {
*final |= 0x80;
*initial |= 0x180;
resultCount++;
if (--count == 0) {
*bestInitial = *initial | 0x78;
*bestFinal = *final | 0x38;
return resultCount;
}
text++;
break;
case 0x23:
*final |= 0x100;
*initial |= 0x180;
resultCount++;
if (--count == 0) {
*bestInitial = *initial | 0x78;
*bestFinal = *final | 0x38;
return resultCount;
}
text++;
break;
case 0x24:
*final |= 0x180;
*initial |= 0x180;
resultCount++;
if (--count == 0) {
*bestInitial = *initial | 0x78;
*bestFinal = *final | 0x38;
return resultCount;
}
text++;
break;
default:
if ((*text < 0xF331) || (*text > 0xF335)) {
*initial |= 0x180;
}
}
after_bpmf_initial:
value = *text - 0xF305;
if ((value > 0x14) && (value < 0x22)) {

View File

@@ -66,15 +66,14 @@ ziU16 Zi8Uni2Ptr(ziU16 ch, ziE12* buf ZI_NEED_WORK) {
if (ZI_WORK->unicodeMap != ZI8_NULL && ZI_WORK->unicodeMapSubLang == ZI_WORK->subLanguage) {
if (ch >= ZI_WORK->unicodeRange1Min && ch <= ZI_WORK->unicodeRange1Max) {
i = (ziU16)(ch - ZI_WORK->unicodeRange1Min);
goto map;
} else {
if (ch >= ZI_WORK->unicodeRange2Min && ch <= ZI_WORK->unicodeRange2Max) {
i = (ziU16)(ZI_WORK->unicodeRange1Max + (ch - ZI_WORK->unicodeRange2Min) -
ZI_WORK->unicodeRange1Min + 1);
} else {
return 0xFFFF;
}
}
if (ch >= ZI_WORK->unicodeRange2Min && ch <= ZI_WORK->unicodeRange2Max) {
i = (ziU16)(ZI_WORK->unicodeRange1Max + (ch - ZI_WORK->unicodeRange2Min) -
ZI_WORK->unicodeRange1Min + 1);
goto map;
}
return 0xFFFF;
map:
i = ZI_WORK->unicodeMap[i];
if (i != 0xFFFF) {
e = (ziU8*)table + i * 0xC;

View File

@@ -76,16 +76,14 @@ ziU8 Zi8ZHaddSpace(ziWChar* src, ziU8 count, ziWChar* dst,
i = 2;
}
if (i-- > m) {
goto fail;
if (i-- <= m) {
for (k = 0; k < i; k++) {
pdst[k] = psrc[k];
}
pdst[k] = 0;
Zi8LogError(0x64, ZI_WORK);
return 1;
}
for (k = 0; k < i; k++) {
pdst[k] = psrc[k];
}
pdst[k] = 0;
Zi8LogError(0x64, ZI_WORK);
return 1;
fail:
if (count >= maxLen) {
count = (ziU8)(maxLen - 1);

View File

@@ -103,7 +103,7 @@ ziU8 Zi8MatchUWDdata(ziWChar* pattern, ziU8 length, ziWChar* currentWord, ziU16
ziU32 size;
int headerSize;
int entryLanguage;
volatile int entryLength;
int entryLength;
int previousOffset;
int visited = 0;
int fallback = 0;

View File

@@ -301,133 +301,131 @@ ziU32 Zi8GetKOcandidates(ziGetParam* param, ZiKoreanCandidateOptions* options ZI
param->candidates[0] = 0;
}
Zi8LogError(100, ZI_WORK);
if (param->wordCharCount == 0) goto scan_key_table;
{
if (((keyIndex = Zi8_8148302C(param->currentWord[0], keyTable, ZI_WORK)) != 0xFFFF) &&
((keyTable[(keyIndex << 3) + keyIndex + offsetof(ZiKoreanKeyEntry, keyBytes[4])] & 8) != 0)) {
wordOffset = keyTable[(keyIndex << 3) + keyIndex + offsetof(ZiKoreanKeyEntry, childLow)] |
((keyTable[(keyIndex << 3) + keyIndex + offsetof(ZiKoreanKeyEntry, keyBytes[4])] & 3) << 16 |
keyTable[(keyIndex << 3) + keyIndex + offsetof(ZiKoreanKeyEntry, childHigh)] << 8);
remainingLetters = param->wordCharCount - 1;
wordIndex = 1;
wordNode = wordTable + wordOffset;
if (param->wordCharCount != 0) {
{
if (((keyIndex = Zi8_8148302C(param->currentWord[0], keyTable, ZI_WORK)) != 0xFFFF) &&
((keyTable[(keyIndex << 3) + keyIndex + offsetof(ZiKoreanKeyEntry, keyBytes[4])] & 8) != 0)) {
wordOffset = keyTable[(keyIndex << 3) + keyIndex + offsetof(ZiKoreanKeyEntry, childLow)] |
((keyTable[(keyIndex << 3) + keyIndex + offsetof(ZiKoreanKeyEntry, keyBytes[4])] & 3) << 16 |
keyTable[(keyIndex << 3) + keyIndex + offsetof(ZiKoreanKeyEntry, childHigh)] << 8);
remainingLetters = param->wordCharCount - 1;
wordIndex = 1;
wordNode = wordTable + wordOffset;
match_word:
while (remainingLetters != 0) {
keyIndex = Zi8_8148302C(param->currentWord[wordIndex], keyTable, ZI_WORK);
if (keyIndex == (((ziU16)*wordNode & 0x1F) << 8 | (ziU16)wordNode[1])) {
--remainingLetters;
++wordIndex;
if ((*wordNode & 0x40) != 0) {
remainingLetters = param->wordCharCount - 1;
wordIndex = 1;
break;
}
wordNode += 2;
} else {
wordIndex = 1;
remainingLetters = param->wordCharCount - 1;
break;
}
}
if (remainingLetters == 0) {
keyIndex = ((ziU16)*wordNode & 0x1F) << 8 | (ziU16)wordNode[1];
character = (ziU16)((ziU16)keyTable[(keyIndex << 3) + keyIndex + offsetof(ZiKoreanKeyEntry, characterHigh)] << 8 |
keyTable[(keyIndex << 3) + keyIndex + offsetof(ZiKoreanKeyEntry, characterLow)]);
if (param->wordCharCount == 1) {
if (keyIndex == previousIndex) {
for (; (*wordNode & 0x40) == 0; wordNode = wordNode + 2) {
while (remainingLetters != 0) {
keyIndex = Zi8_8148302C(param->currentWord[wordIndex], keyTable, ZI_WORK);
if (keyIndex == (((ziU16)*wordNode & 0x1F) << 8 | (ziU16)wordNode[1])) {
--remainingLetters;
++wordIndex;
if ((*wordNode & 0x40) != 0) {
remainingLetters = param->wordCharCount - 1;
wordIndex = 1;
break;
}
wordNode += 2;
remainingLetters = param->wordCharCount - 1;
} else {
wordIndex = 1;
goto next_word;
remainingLetters = param->wordCharCount - 1;
break;
}
previousIndex = keyIndex;
if (param->elementCount == 0) {
if (remainingCandidates != 0) {
--remainingCandidates;
} else {
if (options->countOnly != 0) {
if (++prefixCount < (ziS32)options->maxCount) {
goto skip_word;
}
return options->maxCount;
}
if (remainingLetters == 0) {
keyIndex = ((ziU16)*wordNode & 0x1F) << 8 | (ziU16)wordNode[1];
character = (ziU16)((ziU16)keyTable[(keyIndex << 3) + keyIndex + offsetof(ZiKoreanKeyEntry, characterHigh)] << 8 |
keyTable[(keyIndex << 3) + keyIndex + offsetof(ZiKoreanKeyEntry, characterLow)]);
if (param->wordCharCount == 1) {
if (keyIndex == previousIndex) {
for (; (*wordNode & 0x40) == 0; wordNode = wordNode + 2) {
}
wordNode += 2;
remainingLetters = param->wordCharCount - 1;
wordIndex = 1;
goto next_word;
}
previousIndex = keyIndex;
if (param->elementCount == 0) {
if (remainingCandidates != 0) {
--remainingCandidates;
} else {
if (options->countOnly != 0) {
if (++prefixCount < (ziS32)options->maxCount) {
goto skip_word;
}
return options->maxCount;
}
param->candidates[candidateCount++] = character;
++param->count;
if (++param->letters >= param->maxCandidates) {
return param->letters;
}
}
} else {
param->candidates[candidateCount++] = character;
++param->count;
if (++param->letters >= param->maxCandidates) {
return param->letters;
Zi8_814834AC(param, &remainingCandidates, &candidateCount, &inserted, ZI_WORK);
param->count = candidateCount;
param->letters = candidateCount;
if (candidateCount < param->maxCandidates) goto skip_word;
if (options->countOnly != 0) {
if ((prefixCount += candidateCount) >= (ziS32)options->maxCount) return options->maxCount;
param->count = 0;
param->letters = 0;
candidateCount = 0;
} else {
return candidateCount;
}
}
}
} else {
param->candidates[candidateCount++] = character;
++param->count;
if (++param->letters >= param->maxCandidates) {
Zi8_814834AC(param, &remainingCandidates, &candidateCount, &inserted, ZI_WORK);
param->count = candidateCount;
param->letters = candidateCount;
if (candidateCount < param->maxCandidates) goto skip_word;
if (options->countOnly != 0) {
if ((prefixCount += candidateCount) >= (ziS32)options->maxCount) return options->maxCount;
param->count = 0;
param->letters = 0;
candidateCount = 0;
} else {
return candidateCount;
for (candidateIndex = 0; candidateIndex < candidateCount; candidateIndex++) {
if (character == param->candidates[candidateIndex]) break;
}
if ((candidateIndex == candidateCount) &&
(Zi8_814833F0(param, character, ZI_WORK) == 0)) {
param->candidates[candidateCount++] = character;
++param->count;
if (++param->letters >= param->maxCandidates) {
Zi8_814834AC(param, &remainingCandidates, &candidateCount, &inserted, ZI_WORK);
param->count = candidateCount;
param->letters = candidateCount;
if (candidateCount >= param->maxCandidates) {
if (options->countOnly != 0) {
if ((prefixCount += candidateCount) >= (ziS32)options->maxCount) return options->maxCount;
param->count = 0;
param->letters = 0;
candidateCount = 0;
} else {
return candidateCount;
}
}
}
}
}
} else {
for (candidateIndex = 0; candidateIndex < candidateCount; candidateIndex++) {
if (character == param->candidates[candidateIndex]) break;
}
if ((candidateIndex == candidateCount) &&
(Zi8_814833F0(param, character, ZI_WORK) == 0)) {
param->candidates[candidateCount++] = character;
++param->count;
if (++param->letters < param->maxCandidates) {
goto skip_word;
}
Zi8_814834AC(param, &remainingCandidates, &candidateCount, &inserted, ZI_WORK);
param->count = candidateCount;
param->letters = candidateCount;
if (candidateCount < param->maxCandidates) goto skip_word;
if (options->countOnly != 0) {
if ((prefixCount += candidateCount) >= (ziS32)options->maxCount) return options->maxCount;
param->count = 0;
param->letters = 0;
candidateCount = 0;
} else {
return candidateCount;
}
}
}
skip_word:
for (; (*wordNode & 0x40) == 0; wordNode = wordNode + 2) {
}
wordNode += 2;
remainingLetters = param->wordCharCount - 1;
wordIndex = 1;
next_word:
if ((*wordNode & 0x80) == 0) {
goto match_word;
}
}
skip_word:
for (; (*wordNode & 0x40) == 0; wordNode = wordNode + 2) {
}
resultCount = prefixCount;
if (candidateCount != 0) {
Zi8_814834AC(param, &remainingCandidates, &candidateCount, &inserted, ZI_WORK);
if (options->countOnly != 0) {
if ((prefixCount += candidateCount) >= (ziS32)options->maxCount) return options->maxCount;
resultCount = prefixCount;
}
wordNode += 2;
remainingLetters = param->wordCharCount - 1;
wordIndex = 1;
next_word:
if ((*wordNode & 0x80) != 0) {
goto search_table;
}
goto match_word;
param->count = candidateCount;
param->letters = candidateCount;
}
}
search_table:
resultCount = prefixCount;
if (candidateCount != 0) {
Zi8_814834AC(param, &remainingCandidates, &candidateCount, &inserted, ZI_WORK);
if (options->countOnly != 0) {
if ((prefixCount += candidateCount) >= (ziS32)options->maxCount) return options->maxCount;
resultCount = prefixCount;
}
param->count = candidateCount;
param->letters = candidateCount;
}
scan_key_table:
if (param->elementCount > 9) {
param->letters = 0;
return 0;

View File

@@ -68,17 +68,12 @@ ziBool Zi8getKeyLayout(ziU8 language, ziWChar key, ziWChar* chars, ziU8 mode, zi
chars[keyIndex] = 0;
return 1;
} else {
if (mode == 1) {
goto table_1e;
if (mode != 1) {
if ((tableCount = Zi8GetTableCount(language, 0x1d, __zi8_work_data)) != 0) {
dataAddress = (ziU8*)Zi8GetTableAddress(language, 0x1d, __zi8_work_data);
goto tables_ready;
}
}
if ((tableCount = Zi8GetTableCount(language, 0x1d, __zi8_work_data)) == 0) {
goto table_1e;
}
{
dataAddress = (ziU8*)Zi8GetTableAddress(language, 0x1d, __zi8_work_data);
goto tables_ready;
}
table_1e:
if ((tableCount = Zi8GetTableCount(language, 0x1e, __zi8_work_data)) != 0) {
dataAddress = (ziU8*)Zi8GetTableAddress(language, 0x1e, __zi8_work_data);
}

View File

@@ -53,26 +53,28 @@ posEntry:
if ((ziS32)position < length) {
if (complete) word[length] = 1; else word[length] = 0;
if (++index >= ZI_WORK->oemLen) goto oemFailed;
} else {
if (fallback) {
index = 0;
*word = *pattern;
return 1;
}
ZI_WORK->oemIdx = ++index;
while (word[position] != 0) position++;
return position;
}
matchRetry:
if (index < ZI_WORK->oemLen) {
if (ZI_WORK->oemMatch(index, word, capacity, ZI_WORK->oemData)) {
goto posEntry;
}
}
oemFailed:
if (length == 1 && complete && !continuation) {
complete = 0;
fallback = 1;
index = 0;
goto matchRetry;
}
if (fallback) {
index = 0;
*word = *pattern;
return 1;
}
ZI_WORK->oemIdx = ++index;
while (word[position] != 0) position++;
return position;
matchRetry:
if (index >= ZI_WORK->oemLen) goto oemFailed;
if (!ZI_WORK->oemMatch(index, word, capacity, ZI_WORK->oemData)) goto oemFailed;
goto posEntry;
oemFailed:
if (length != 1 || !complete || continuation) goto tail0;
complete = 0;
fallback = 1;
index = 0;
goto matchRetry;
tail0:
return 0;
}

View File

@@ -43,22 +43,10 @@
#define BTA_DISABLE_DELAY 1000
#ifndef BTA_DISABLE_DELAY
# define BTA_DISABLE_DELAY 200
#endif
#define BTA_DM_REMOTE_DEVICE_NAME_LENGTH 32
#ifndef BTA_DM_REMOTE_DEVICE_NAME_LENGTH
# define BTA_DM_REMOTE_DEVICE_NAME_LENGTH 248
#endif
#define BTA_DM_SDP_DB_SIZE 250
#ifndef BTA_DM_SDP_DB_SIZE
# define BTA_DM_SDP_DB_SIZE 8000
#endif
/* GKI pools */
#ifndef HCI_CMD_POOL_ID
@@ -67,10 +55,6 @@
#define SDP_POOL_ID GKI_POOL_ID_2
#ifndef SDP_POOL_ID
# define SDP_POOL_ID GKI_POOL_ID_3
#endif
#ifndef RFCOMM_CMD_POOL_ID
# define RFCOMM_CMD_POOL_ID GKI_POOL_ID_2
#endif
@@ -110,23 +94,14 @@ void bte_hcisu_send(BT_HDR *p_msg, UINT16 event);
#define BT_1SEC_TIMEOUT 1
#ifndef BT_1SEC_TIMEOUT
# define BT_1SEC_TIMEOUT 2
#endif
/* BTM */
#define BTM_INQ_DB_SIZE 12
#ifndef BTM_INQ_DB_SIZE
# define BTM_INQ_DB_SIZE 40
#endif
#ifndef BTM_DEFAULT_SCAN_TYPE
# define BTM_DEFAULT_SCAN_TYPE BTM_SCAN_TYPE_INTERLACED
#endif
// CLEANUP: header pass, probably
#ifndef BTM_DEFAULT_CONN_WINDOW
# define BTM_DEFAULT_CONN_WINDOW 18
#endif
@@ -139,7 +114,6 @@ void bte_hcisu_send(BT_HDR *p_msg, UINT16 event);
# define BTM_DEFAULT_DISC_MODE BTM_GENERAL_DISCOVERABLE
#endif
// CLEANUP: header pass, probably
#ifndef BTM_DEFAULT_DISC_WINDOW
# define BTM_DEFAULT_DISC_WINDOW 18
#endif
@@ -154,44 +128,20 @@ void bte_hcisu_send(BT_HDR *p_msg, UINT16 event);
*/
#define BTA_DM_COD {0x40, 0x02, 0x04}
#ifndef BTA_DM_COD
# define BTA_DM_COD {0x5a, 0x02, 0x0c}
#endif
#define BTM_MAX_SCO_LINKS 3
#ifndef BTM_MAX_SCO_LINKS
# define BTM_MAX_SCO_LINKS 2
#endif
#ifndef BTM_DEFAULT_SCO_MODE
# define BTM_DEFAULT_SCO_MODE 2
#endif
#define BTM_SEC_MAX_DEVICE_RECORDS 16
#ifndef BTM_SEC_MAX_DEVICE_RECORDS
# define BTM_SEC_MAX_DEVICE_RECORDS 100
#endif
#define BTM_SEC_MAX_SERVICE_RECORDS 24
#ifndef BTM_SEC_MAX_SERVICE_RECORDS
# define BTM_SEC_MAX_SERVICE_RECORDS 32
#endif
#define BTM_MAX_REM_BD_NAME_LEN 64
#ifndef BTM_MAX_REM_BD_NAME_LEN
# define BTM_MAX_REM_BD_NAME_LEN 248
#endif
#define BTM_MAX_LOC_BD_NAME_LEN 31
#ifndef BTM_MAX_LOC_BD_NAME_LEN
# define BTM_MAX_LOC_BD_NAME_LEN 248
#endif
#ifndef BTM_SEC_SERVICE_NAME_LEN
# define BTM_SEC_SERVICE_NAME_LEN BT_MAX_SERVICE_NAME_LEN
#endif
@@ -210,37 +160,14 @@ void bte_hcisu_send(BT_HDR *p_msg, UINT16 event);
/* L2CAP */
// TODO: could this be resolved by configuring MAX_ACL_CONNECTIONS?
#if 0
#define MAX_ACL_CONNECTIONS 4
#ifndef MAX_ACL_CONNECTIONS
# define MAX_L2CAP_LINKS 7
#else
# define MAX_L2CAP_LINKS MAX_ACL_CONNECTIONS
#endif
#else
# define MAX_L2CAP_LINKS 4
#endif
#define MAX_L2CAP_LINKS 4
#define MAX_L2CAP_CHANNELS 10
#ifndef MAX_L2CAP_CHANNELS
# define MAX_L2CAP_CHANNELS 16
#endif
#define MAX_L2CAP_CLIENTS 8
#ifndef MAX_L2CAP_CLIENTS
# define MAX_L2CAP_CLIENTS 15
#endif
#define L2CAP_LINK_INACTIVITY_TOUT 2
#ifndef L2CAP_LINK_INACTIVITY_TOUT
# define L2CAP_LINK_INACTIVITY_TOUT 4
#endif
#ifndef L2CAP_LINK_STARTUP_TOUT
# define L2CAP_LINK_STARTUP_TOUT 60
#endif
@@ -269,27 +196,11 @@ void bte_hcisu_send(BT_HDR *p_msg, UINT16 event);
#define SDP_MAX_PAD_LEN 350
#ifndef SDP_MAX_PAD_LEN
# define SDP_MAX_PAD_LEN 600
#endif
#define SDP_MAX_ATTR_LEN 80
#ifndef SDP_MAX_ATTR_LEN
# if defined(HID_DEV_INCLUDED) && HID_DEV_INCLUDED == TRUE
// probably went here
# define SDP_MAX_ATTR_LEN 80
# else
# define SDP_MAX_ATTR_LEN 100
# endif
#endif
#define SDP_MAX_ATTR_FILTERS 12
#ifndef SDP_MAX_ATTR_FILTERS
# define SDP_MAX_ATTR_FILTERS 15
#endif
#ifndef SDP_MAX_UUID_FILTERS
# define SDP_MAX_UUID_FILTERS 3
#endif
@@ -300,10 +211,6 @@ void bte_hcisu_send(BT_HDR *p_msg, UINT16 event);
#define SDP_MAX_LIST_BYTE_COUNT 1000
#ifndef SDP_MAX_LIST_BYTE_COUNT
# define SDP_MAX_LIST_BYTE_COUNT 0x1000
#endif
#ifndef SDP_MAX_PROTOCOL_PARAMS
# define SDP_MAX_PROTOCOL_PARAMS 2
#endif
@@ -332,81 +239,30 @@ void bte_hcisu_send(BT_HDR *p_msg, UINT16 event);
#define MAX_RFC_PORTS 5
#ifndef MAX_RFC_PORTS
# define MAX_RFC_PORTS 30
#endif
// Well I guess not since this is different than MAX_L2CAP_LINKS
#if 0
#define MAX_ACL_CONNECTIONS 4
#ifndef MAX_ACL_CONNECTIONS
# define MAX_BD_CONNECTIONS 7
#else
# define MAX_BD_CONNECTIONS MAX_ACL_CONNECTIONS
#endif
#else
# define MAX_BD_CONNECTIONS 1
#endif
#define MAX_BD_CONNECTIONS 1
#define PORT_RX_LOW_WM 5000
#ifndef PORT_RX_LOW_WM
# define PORT_RX_LOW_WM (BTA_RFC_MTU_SIZE * PORT_RX_BUF_LOW_WM)
#endif
#define PORT_RX_HIGH_WM 8000
#ifndef PORT_RX_HIGH_WM
# define PORT_RX_HIGH_WM (BTA_RFC_MTU_SIZE * PORT_RX_BUF_HIGH_WM)
#endif
#define PORT_RX_CRITICAL_WM 12000
#ifndef PORT_RX_CRITICAL_WM
# define PORT_RX_CRITICAL_WM (BTA_RFC_MTU_SIZE * PORT_RX_BUF_CRITICAL_WM)
#endif
#define PORT_RX_BUF_LOW_WM 8
#ifndef PORT_RX_BUF_LOW_WM
# define PORT_RX_BUF_LOW_WM 4
#endif
#define PORT_RX_BUF_HIGH_WM 16
#ifndef PORT_RX_BUF_HIGH_WM
# define PORT_RX_BUF_HIGH_WM 10
#endif
#ifndef PORT_RX_BUF_CRITICAL_WM
# define PORT_RX_BUF_CRITICAL_WM 15
#endif
#define PORT_TX_HIGH_WM 8000
#ifndef PORT_TX_HIGH_WM
# define PORT_TX_HIGH_WM (BTA_RFC_MTU_SIZE * PORT_TX_BUF_HIGH_WM)
#endif
#define PORT_TX_CRITICAL_WM 10000
#ifndef PORT_TX_CRITICAL_WM
# define PORT_TX_CRITICAL_WM (BTA_RFC_MTU_SIZE * PORT_TX_BUF_CRITICAL_WM)
#endif
#define PORT_TX_BUF_HIGH_WM 16
#ifndef PORT_TX_BUF_HIGH_WM
# define PORT_TX_BUF_HIGH_WM 10
#endif
#define PORT_TX_BUF_CRITICAL_WM 22
#ifndef PORT_TX_BUF_CRITICAL_WM
# define PORT_TX_BUF_CRITICAL_WM 15
#endif
#ifndef PORT_FC_DEFAULT
# define PORT_FC_DEFAULT PORT_FC_CREDIT
#endif
@@ -451,10 +307,6 @@ void bte_hcisu_send(BT_HDR *p_msg, UINT16 event);
#define HID_HOST_MAX_DEVICES 16
#ifndef HID_HOST_MAX_DEVICES
# define HID_HOST_MAX_DEVICES 7
#endif
#ifndef HID_HOST_MTU
# define HID_HOST_MTU 640
#endif
@@ -465,10 +317,6 @@ void bte_hcisu_send(BT_HDR *p_msg, UINT16 event);
#define HID_HOST_MAX_CONN_RETRY 0
#ifndef HID_HOST_MAX_CONN_RETRY
# define HID_HOST_MAX_CONN_RETRY 3
#endif
#ifndef HID_HOST_REPAGE_WIN
# define HID_HOST_REPAGE_WIN 2
#endif

View File

@@ -55,12 +55,6 @@ enum
};
typedef UINT32 tBTA_SERVICE_MASK;
#if 0
enum
{
/* ... */
};
#endif
// Added constants for tBTA_SEC
typedef UINT8 tBTA_SEC;
@@ -74,36 +68,12 @@ enum
typedef UINT8 tBTA_DM_DISC;
#if 0
enum
{
/* ... */
};
#endif
typedef UINT8 tBTA_DM_CONN;
#if 0
enum
{
/* ... */
};
#endif
typedef UINT8 tBTA_DM_INQ_MODE;
#if 0
enum
{
/* ... */
};
#endif
typedef UINT8 tBTA_DM_INQ_FILT;
#if 0
enum
{
/* ... */
};
#endif
typedef UINT8 tBTA_AUTH_RESP;
enum

View File

@@ -62,8 +62,8 @@ typedef struct
typedef struct
{
UINT16 at_0x00; // 0x00
UINT16 at_0x02; // 0x02
UINT16 vendorId; // 0x00
UINT16 productId; // 0x02
} tHCI_CFG; // size 0x04
typedef void tHCI_INIT(UINT8, UINT8, UINT16);

View File

@@ -19,11 +19,11 @@ typedef void tUUSB_CBACK(UINT8, INT8);
typedef struct
{
char pad0_[4];
UINT16 at_0x04;
UINT16 at_0x06;
UINT16 at_0x08;
UINT16 vendorId; // 0x04
UINT16 productId; // 0x06
UINT16 taskId; // 0x08
char pad1_[1];
char at_0x0b;
char reserved; // 0x0b
char pad2_[1]; // for stack
} tUUSB;

View File

@@ -26,7 +26,7 @@ typedef struct IOSResourceOpen {
u8* path; // 0x00
u32 flags; // 0x04
u32 ownerId; // 0x08
u16 groudId; // 0x0C
u16 groupId; // 0x0C
} IOSResourceOpen;
typedef struct IOSResourceRead {

View File

@@ -8,7 +8,7 @@ extern "C" {
#endif
void CNTCACHEInit(int unk0, int unk1);
void CNTCACHEClear();
s32 CNTCACHEClear(void);
#ifdef __cplusplus
}

View File

@@ -167,24 +167,27 @@ s32 ARCConvertPathToEntrynum(ARCHandle* handle, const char* path) {
for (i = dirLookAt + 1; i < FSTEntries[dirLookAt].dir.next; i = IS_ENTRY_DIR(FSTEntries, i) ? FSTEntries[i].dir.next : i + 1) {
char* name;
loop_back:
// Skip directories
if (IS_ENTRY_DIR(FSTEntries, i) == FALSE && isDir == TRUE) {
continue;
}
do {
// Skip directories
if (IS_ENTRY_DIR(FSTEntries, i) == FALSE && isDir == TRUE) {
break;
}
name = handle->FSTStringStart + FILE_STRING_OFF(FSTEntries, i);
name = handle->FSTStringStart + FILE_STRING_OFF(FSTEntries, i);
// Skip empty entries
if (*name == '.' && *(name + 1) == 0) {
i++;
goto loop_back;
}
// Skip empty entries
if (*name == '.' && *(name + 1) == 0) {
i++;
continue;
}
// Advance to next file in hierarchy
if (isSame(ptrPath, name) == TRUE) {
goto next_in_hier;
}
// Advance to next file in hierarchy
if (isSame(ptrPath, name) == TRUE) {
// MWCC needs this join to preserve the original search branches.
goto next_in_hier;
}
break;
} while (TRUE);
}
return -1;
@@ -198,6 +201,7 @@ s32 ARCConvertPathToEntrynum(ARCHandle* handle, const char* path) {
}
}
/* MWCC must retain this unreferenced SDK entry point in the linked image. */
#pragma push
#pragma force_active on
BOOL ARCEntrynumIsDir(ARCHandle* handle, s32 entryNum) {
@@ -315,23 +319,26 @@ BOOL ARCReadDir(ARCDir* dir, ARCDirEntry* dirent) {
handle = dir->handle;
FSTEntries = (FSTEntry*)handle->FSTStart;
loc = dir->location;
retry:
if (loc <= dir->entryNum || dir->next <= loc) {
return FALSE;
for (;;) {
if (loc <= dir->entryNum || dir->next <= loc) {
return FALSE;
}
dirent->handle = handle;
dirent->entryNum = loc;
dirent->isDir = IS_ENTRY_DIR(FSTEntries, loc);
dirent->name = handle->FSTStringStart + FILE_STRING_OFF(FSTEntries, loc);
if (dirent->name[0] == '.' && dirent->name[1] == 0) {
loc++;
continue;
}
dir->location = IS_ENTRY_DIR(FSTEntries, loc) ? FSTEntries[loc].dir.next : (loc + 1);
break;
}
dirent->handle = handle;
dirent->entryNum = loc;
dirent->isDir = IS_ENTRY_DIR(FSTEntries, loc);
dirent->name = handle->FSTStringStart + FILE_STRING_OFF(FSTEntries, loc);
if (dirent->name[0] == '.' && dirent->name[1] == 0) {
loc++;
goto retry;
}
dir->location = IS_ENTRY_DIR(FSTEntries, loc) ? FSTEntries[loc].dir.next : (loc + 1);
return TRUE;
}

View File

@@ -71,19 +71,11 @@ enum
typedef void tBTA_DM_ACTION(tBTA_DM_MSG *p_data);
typedef UINT8 tBTA_DM_STATE_TABLE_ENTRY[BTA_DM_NUM_COLS];
#if 0
typedef tBTA_DM_STATE_TABLE_ENTRY tBTA_DM_STATE_TABLE[];
#else
typedef tBTA_DM_STATE_TABLE_ENTRY tBTA_DM_STATE_TABLE;
#endif
typedef void tBTA_DM_SEARCH_ACTION(tBTA_DM_MSG *p_data);
typedef UINT8 tBTA_DM_SEARCH_STATE_TABLE_ENTRY[BTA_DM_SEARCH_NUM_COLS];
#if 0
typedef tBTA_DM_SEARCH_STATE_TABLE_ENTRY tBTA_DM_SEARCH_STATE_TABLE[];
#else
typedef tBTA_DM_SEARCH_STATE_TABLE_ENTRY tBTA_DM_SEARCH_STATE_TABLE;
#endif
tBTA_DM_ACTION * const bta_dm_action[] =
{
@@ -108,18 +100,11 @@ tBTA_DM_STATE_TABLE_ENTRY const bta_dm_st_table[] =
{BTA_DM_API_DISABLE_EVT - BTA_SYS_EVT_START(BTA_ID_DM), BTA_DM_IGNORE},
{BTA_DM_API_SET_NAME_EVT - BTA_SYS_EVT_START(BTA_ID_DM), BTA_DM_IGNORE},
{BTA_DM_API_SET_VISIBILITY_EVT - BTA_SYS_EVT_START(BTA_ID_DM), BTA_DM_IGNORE},
#if 0
// not over here?
{BTA_DM_API_BOND_EVT - BTA_SYS_EVT_START(BTA_ID_DM), BTA_DM_IGNORE},
#endif
{BTA_DM_API_PIN_REPLY_EVT - BTA_SYS_EVT_START(BTA_ID_DM), BTA_DM_IGNORE},
{BTA_DM_API_AUTH_REPLY_EVT - BTA_SYS_EVT_START(BTA_ID_DM), BTA_DM_IGNORE},
{BTA_DM_API_SIG_STRENGTH_EVT - BTA_SYS_EVT_START(BTA_ID_DM), BTA_DM_IGNORE},
{BTA_DM_ACL_CHANGE_EVT - BTA_SYS_EVT_START(BTA_ID_DM), BTA_DM_IGNORE},
#if 1
// over here?
{BTA_DM_API_BOND_EVT - BTA_SYS_EVT_START(BTA_ID_DM), BTA_DM_IGNORE},
#endif
{BTA_DM_PM_BTM_STATUS_EVT - BTA_SYS_EVT_START(BTA_ID_DM), BTA_DM_IGNORE},
{BTA_DM_PM_TIMER_EVT - BTA_SYS_EVT_START(BTA_ID_DM), BTA_DM_IGNORE},
{BTA_DM_API_KEEP_ACL_LINKS - BTA_SYS_EVT_START(BTA_ID_DM), BTA_DM_IGNORE},

View File

@@ -66,11 +66,7 @@ enum
typedef void tBTA_HH_ACTION(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data);
typedef UINT8 tBTA_HH_STATE_TABLE_ENTRY[BTA_HH_NUM_COLS];
#if 0
typedef tBTA_HH_STATE_TABLE_ENTRY tBTA_HH_STATE_TABLE[];
#else
typedef tBTA_HH_STATE_TABLE_ENTRY tBTA_HH_STATE_TABLE;
#endif
static char const *bta_hh_evt_code(tBTA_HH_INT_EVT evt_code);
static char const *bta_hh_state_code(tBTA_HH_STATE state_code);

View File

@@ -87,7 +87,8 @@ void btm_acl_created(BD_ADDR bda, DEV_CLASS dc, BD_NAME bdn, UINT16 hci_handle,
UINT8 xx;
UINT8 yy;
if ((p = btm_bda_to_acl(bda)) != (tACL_CONN *)NULL)
p = btm_bda_to_acl(bda);
if (p != (tACL_CONN *)NULL)
{
p->hci_handle = hci_handle;
p->link_role = link_role;
@@ -151,7 +152,8 @@ void btm_acl_removed(BD_ADDR bda)
{
tACL_CONN *p;
if ((p = btm_bda_to_acl(bda)) != (tACL_CONN *)NULL)
p = btm_bda_to_acl(bda);
if (p != (tACL_CONN *)NULL)
{
p->in_use = FALSE;
@@ -179,7 +181,8 @@ tBTM_STATUS BTM_GetRole(BD_ADDR remote_bd_addr, tBTM_ROLE *p_role)
{
tACL_CONN *p;
if ((p = btm_bda_to_acl(remote_bd_addr)) == NULL)
p = btm_bda_to_acl(remote_bd_addr);
if (p == NULL)
{
*p_role = BTM_ROLE_UNDEFINED;
return BTM_UNKNOWN_ADDR;
@@ -202,7 +205,8 @@ tBTM_STATUS BTM_SwitchRole(BD_ADDR remote_bd_addr, tBTM_ROLE new_role,
if (!HCI_SWITCH_SUPPORTED(btm_cb.devcb.local_features))
return BTM_MODE_UNSUPPORTED;
if ((p = btm_bda_to_acl(remote_bd_addr)) == NULL)
p = btm_bda_to_acl(remote_bd_addr);
if (p == NULL)
return BTM_UNKNOWN_ADDR;
if (p->link_role == new_role)
@@ -223,7 +227,8 @@ tBTM_STATUS BTM_SwitchRole(BD_ADDR remote_bd_addr, tBTM_ROLE new_role,
memset(&btm_cb.devcb.switch_role_ref_data, 0,
sizeof btm_cb.devcb.switch_role_ref_data);
if ((status = BTM_ReadPowerMode(p->remote_addr, &pwr_mode)) != BTM_SUCCESS)
status = BTM_ReadPowerMode(p->remote_addr, &pwr_mode);
if (status != BTM_SUCCESS)
return status;
if (pwr_mode == BTM_PM_MD_PARK || pwr_mode == BTM_PM_MD_SNIFF)
@@ -356,7 +361,8 @@ tBTM_STATUS BTM_SetLinkPolicy(BD_ADDR remote_bda, tHCI_LINK_POLICY *settings)
}
}
if ((p = btm_bda_to_acl(remote_bda)) != NULL)
p = btm_bda_to_acl(remote_bda);
if (p != NULL)
{
return btsnd_hcic_write_policy_set(p->hci_handle, *settings)
? BTM_CMD_STARTED
@@ -382,7 +388,8 @@ tBTM_STATUS BTM_ReadLinkPolicy(BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb)
if (btm_cb.devcb.p_rlinkp_cmpl_cb)
return BTM_BUSY;
if ((p = btm_bda_to_acl(remote_bda)) != (tACL_CONN *)NULL)
p = btm_bda_to_acl(remote_bda);
if (p != (tACL_CONN *)NULL)
{
btu_start_timer(&btm_cb.devcb.rlinkp_timer, BTU_TTYPE_BTM_ACL,
BTM_DEV_REPLY_TIMEOUT);
@@ -534,7 +541,8 @@ tBTM_STATUS BTM_SetLinkSuperTout(BD_ADDR remote_bda, UINT16 timeout)
{
tACL_CONN *p;
if ((p = btm_bda_to_acl(remote_bda)) != (tACL_CONN *)NULL)
p = btm_bda_to_acl(remote_bda);
if (p != (tACL_CONN *)NULL)
{
p->link_super_tout = timeout;
@@ -559,7 +567,8 @@ tBTM_STATUS BTM_SetPacketTypes(BD_ADDR remote_bda,
{
tACL_CONN *p;
if ((p = btm_bda_to_acl(remote_bda)) != NULL)
p = btm_bda_to_acl(remote_bda);
if (p != NULL)
return btm_set_packet_types(p, pkt_types);
return BTM_UNKNOWN_ADDR;
@@ -569,7 +578,8 @@ UINT16 BTM_ReadPacketTypes(BD_ADDR remote_bda)
{
tACL_CONN *p;
if ((p = btm_bda_to_acl(remote_bda)) != (tACL_CONN *)NULL)
p = btm_bda_to_acl(remote_bda);
if (p != (tACL_CONN *)NULL)
return p->pkt_types_mask;
return 0;
@@ -583,7 +593,8 @@ UINT16 BTM_ReadClockOffset(BD_ADDR remote_bda)
remote_bda[0], remote_bda[1], remote_bda[2], remote_bda[3],
remote_bda[4], remote_bda[5]);
if ((p = btm_bda_to_acl(remote_bda)) != NULL)
p = btm_bda_to_acl(remote_bda);
if (p != NULL)
return p->clock_offset;
return 0;
@@ -632,7 +643,8 @@ tHCI_HANDLE BTM_GetHCIConnHandle(BD_ADDR remote_bda)
{
tACL_CONN *p;
if ((p = btm_bda_to_acl(remote_bda)) != (tACL_CONN *)NULL)
p = btm_bda_to_acl(remote_bda);
if (p != (tACL_CONN *)NULL)
return p->hci_handle;
return HCI_HANDLE_INVALID;
@@ -642,7 +654,8 @@ void btm_process_clk_off_comp_evt(tHCI_HANDLE hci_handle, UINT16 clock_offset)
{
UINT8 xx;
if ((xx = btm_handle_to_acl_index(hci_handle)) < MAX_L2CAP_LINKS)
xx = btm_handle_to_acl_index(hci_handle);
if (xx < MAX_L2CAP_LINKS)
btm_cb.acl_db[xx].clock_offset = clock_offset;
}
@@ -856,7 +869,8 @@ tBTM_STATUS BTM_SetQoS(BD_ADDR bd, FLOW_SPEC *p_flow, tBTM_CMPL_CB *p_cb)
if (btm_cb.devcb.p_qossu_cmpl_cb)
return BTM_BUSY;
if ((p = btm_bda_to_acl(bd)) != NULL)
p = btm_bda_to_acl(bd);
if (p != NULL)
{
btu_start_timer(&btm_cb.devcb.qossu_timer, BTU_TTYPE_BTM_ACL,
BTM_DEV_REPLY_TIMEOUT);
@@ -923,7 +937,8 @@ tBTM_STATUS BTM_ReadRSSI(BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb)
if (btm_cb.devcb.p_rssi_cmpl_cb)
return BTM_BUSY;
if ((p = btm_bda_to_acl(remote_bda)) != (tACL_CONN *)NULL)
p = btm_bda_to_acl(remote_bda);
if (p != (tACL_CONN *)NULL)
{
btu_start_timer(&btm_cb.devcb.rssi_timer, BTU_TTYPE_BTM_ACL,
BTM_DEV_REPLY_TIMEOUT);
@@ -956,7 +971,8 @@ tBTM_STATUS BTM_ReadLinkQuality(BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb)
if (btm_cb.devcb.p_lnk_qual_cmpl_cb)
return BTM_BUSY;
if ((p = btm_bda_to_acl(remote_bda)) != (tACL_CONN *)NULL)
p = btm_bda_to_acl(remote_bda);
if (p != (tACL_CONN *)NULL)
{
btu_start_timer(&btm_cb.devcb.lnk_quality_timer, BTU_TTYPE_BTM_ACL,
BTM_DEV_REPLY_TIMEOUT);

View File

@@ -52,10 +52,6 @@
#define BTM_SCO_HOST_BUF_SIZE 30
#ifndef BTM_SCO_HOST_BUF_SIZE
# define BTM_SCO_HOST_BUF_SIZE 255
#endif
static void btm_db_reset(void);
static void btm_dev_reset(void);
@@ -99,6 +95,7 @@ static void btm_db_reset(void)
btm_inq_db_reset();
btm_discovery_db_reset();
// MWCC requires the repeated callback tests for the original instructions.
if (btm_cb.devcb.p_rln_cmpl_cb)
{
p_cb = btm_cb.devcb.p_rln_cmpl_cb;
@@ -247,7 +244,8 @@ void btm_get_hci_buf_size(void)
btu_start_timer(&btm_cb.devcb.reset_timer, BTU_TTYPE_BTM_DEV_CTL,
BTM_DEV_REPLY_TIMEOUT);
if ((p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_READ_CMD)) != NULL)
p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_READ_CMD);
if (p_buf != NULL)
btsnd_hcic_read_buffer_size(p_buf);
}
}
@@ -662,7 +660,8 @@ tBTM_STATUS BTM_ReadLocalDeviceName(tBTM_CMPL_CB *p_cb)
return BTM_BUSY;
// NOTE: HCIC_PARAM_SIZE_READ_NAME is not defined
if ((p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_READ_NAME)) != NULL)
p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_READ_NAME);
if (p_buf != NULL)
{
btu_start_timer(&btm_cb.devcb.rln_timer, BTU_TTYPE_BTM_DEV_CTL,
BTM_INFO_TIMEOUT);
@@ -736,7 +735,8 @@ tBTM_STATUS BTM_SetDeviceClass(DEV_CLASS dev_class)
return BTM_DEV_RESET;
}
if ((p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM3)) != NULL)
p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM3);
if (p_buf != NULL)
{
btsnd_hcic_write_dev_class(p_buf, dev_class);
return BTM_SUCCESS;
@@ -857,7 +857,8 @@ tBTM_STATUS BTM_WritePageTimeout(UINT16 timeout)
btm_cb.devcb.page_timeout = timeout * 625 / 1000;
if ((p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM2)) != NULL)
p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM2);
if (p_buf != NULL)
{
btsnd_hcic_write_page_tout(p_buf, timeout);
return BTM_SUCCESS;
@@ -875,7 +876,8 @@ tBTM_STATUS BTM_WriteVoiceSettings(UINT16 settings)
BTM_TRACE(EVENT, "BTM: BTM_WriteVoiceSettings: Settings: 0x%04x.",
settings);
if ((p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM2)) != NULL)
p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM2);
if (p_buf != NULL)
{
btsnd_hcic_write_voice_settings(p_buf, settings & 0x03ff);
return BTM_SUCCESS;
@@ -893,7 +895,8 @@ tBTM_STATUS BTM_EnableTestMode(void)
BTM_TRACE(EVENT, "BTM: BTM_EnableTestMode");
if ((p_buf = HCI_GET_CMD_BUF(2 + sizeof cond)) != NULL)
p_buf = HCI_GET_CMD_BUF(2 + sizeof cond);
if (p_buf != NULL)
{
cond = HCI_DO_AUTO_ACCEPT_CONNECT;
btsnd_hcic_set_event_filter(p_buf, HCI_FILTER_CONNECTION_SETUP,
@@ -920,7 +923,8 @@ tBTM_STATUS BTM_EnableTestMode(void)
return BTM_NO_RESOURCES;
}
if ((p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_READ_CMD)) != NULL)
p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_READ_CMD);
if (p_buf != NULL)
{
btsnd_hcic_enable_test_mode(p_buf);
return BTM_SUCCESS;
@@ -955,7 +959,8 @@ tBTM_STATUS BTM_ReadStoredLinkKey(BD_ADDR bd_addr, tBTM_CMPL_CB *p_cb)
BTM_TRACE(EVENT, "BTM: BTM_ReadStoredLinkKey: Read_All: %s",
read_all_flag ? "TRUE" : "FALSE");
if ((p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_READ_STORED_KEY)) != NULL)
p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_READ_STORED_KEY);
if (p_buf != NULL)
{
btm_cb.devcb.p_stored_link_key_cmpl_cb = p_cb;

View File

@@ -101,7 +101,8 @@ tBTM_STATUS BTM_SetDiscoverability(tBTM_DISC_MODE inq_mode, UINT16 window,
if (inq_mode != BTM_NON_DISCOVERABLE)
{
if ((p_buf = HCI_GET_CMD_BUF(1 + LAP_LEN * 2)) != NULL)
p_buf = HCI_GET_CMD_BUF(1 + LAP_LEN * 2);
if (p_buf != NULL)
{
if (inq_mode & BTM_LIMITED_DISCOVERABLE)
{
@@ -139,7 +140,8 @@ tBTM_STATUS BTM_SetDiscoverability(tBTM_DISC_MODE inq_mode, UINT16 window,
}
}
if ((p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM1)) != NULL)
p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM1);
if (p_buf != NULL)
{
if (btm_cb.btm_inq_vars.connectable_mode != BTM_NON_CONNECTABLE)
scan_mode |= HCI_PAGE_SCAN_ENABLED;
@@ -193,7 +195,8 @@ tBTM_STATUS BTM_SetInquiryScanType(tBTM_INQ_SCAN_TYPE scan_type)
{
if (BTM_IsDeviceUp())
{
if ((p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM1)) != NULL)
p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM1);
if (p_buf != NULL)
{
btsnd_hcic_write_inqscan_type(p_buf, scan_type);
btm_cb.btm_inq_vars.inq_scan_type = scan_type;
@@ -229,7 +232,8 @@ tBTM_STATUS BTM_SetPageScanType(UINT16 scan_type)
{
if (BTM_IsDeviceUp())
{
if ((p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM1)) != NULL)
p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM1);
if (p_buf != NULL)
{
btsnd_hcic_write_pagescan_type(p_buf, scan_type);
btm_cb.btm_inq_vars.page_scan_type = scan_type;
@@ -261,7 +265,8 @@ tBTM_STATUS BTM_SetInquiryMode(tBTM_INQ_RESULT_TYPE mode)
if (!BTM_IsDeviceUp())
return BTM_WRONG_MODE;
if ((p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM1)) != NULL)
p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM1);
if (p_buf != NULL)
btsnd_hcic_write_inquiry_mode(p_buf, mode);
else
return BTM_NO_RESOURCES;
@@ -428,7 +433,8 @@ tBTM_STATUS BTM_SetConnectability(tBTM_CONN_MODE page_mode, UINT16 window,
}
}
if ((p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM1)) != NULL)
p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM1);
if (p_buf != NULL)
{
if (p_inq->discoverable_mode != BTM_NON_DISCOVERABLE)
scan_mode |= HCI_INQUIRY_SCAN_ENABLED;
@@ -564,7 +570,8 @@ tBTM_STATUS BTM_ReadRemoteDeviceName(BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb)
remote_bda[0], remote_bda[1], remote_bda[2], remote_bda[3],
remote_bda[4], remote_bda[5]);
if ((p_i = btm_inq_db_find(remote_bda)) != NULL)
p_i = btm_inq_db_find(remote_bda);
if (p_i != NULL)
p_cur = &p_i->inq_info;
return btm_initiate_rem_name(remote_bda, p_cur, BTM_RMT_NAME_EXT,
@@ -1092,7 +1099,8 @@ static void btm_initiate_inquiry(tBTM_INQUIRY_VAR_ST *p_inq)
{
btm_clr_inq_result_flt();
if ((p_inq->p_bd_db = GKI_getbuf(GKI_MAX_BUF_SIZE)) != NULL)
p_inq->p_bd_db = GKI_getbuf(GKI_MAX_BUF_SIZE);
if (p_inq->p_bd_db != NULL)
{
p_inq->max_bd_entries = GKI_MAX_BUF_SIZE / sizeof *p_inq->p_bd_db;
memset(p_inq->p_bd_db, 0, GKI_MAX_BUF_SIZE);

View File

@@ -80,7 +80,8 @@ static void btm_esco_conn_rsp(UINT16 sco_inx, UINT8 hci_status, BD_ADDR bda,
BT_HDR *p_buf;
UINT16 temp_pkt_types;
if ((p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_REJECT_ESCO)) == NULL)
p_buf = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_REJECT_ESCO);
if (p_buf == NULL)
{
BTM_TRACE(ERROR, "btm_esco_conn_rsp -> No Resources");
return;
@@ -246,8 +247,10 @@ tBTM_STATUS BTM_CreateSco(BD_ADDR remote_bda, BOOLEAN is_orig, UINT16 pkt_types,
if (is_orig)
{
// MWCC requires this combined check for the original instructions.
if (!remote_bda
|| ((acl_handle = BTM_GetHCIConnHandle(remote_bda)) == 0xffff))
|| ((acl_handle = BTM_GetHCIConnHandle(remote_bda))
== BTM_INVALID_HCI_HANDLE))
{
return BTM_UNKNOWN_ADDR;
}
@@ -382,7 +385,8 @@ void btm_sco_chk_pend_unpark(tHCI_STATUS hci_status, tHCI_HANDLE hci_handle,
/* explicitly post-increment */
for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++)
{
if (p->state == SCO_ST_PEND_UNPARK && mode == 0
// MWCC requires the handle lookup inside this short-circuit condition.
if (p->state == SCO_ST_PEND_UNPARK && mode == HCI_MODE_ACTIVE
&& hci_status == HCI_SUCCESS
&& ((acl_handle = BTM_GetHCIConnHandle(p->esco.data.bd_addr))
== hci_handle))
@@ -494,7 +498,7 @@ void btm_sco_connected(tHCI_STATUS hci_status, BD_ADDR bda,
{
if (p->state == SCO_ST_CONNECTING)
{
if (hci_status != 35)
if (hci_status != HCI_ERR_LMP_ERR_TRANS_COLLISION)
{
p->state = SCO_ST_UNUSED;
@@ -598,6 +602,7 @@ void btm_sco_removed(UINT16 hci_handle, UINT8 reason)
if (btm_num_sco_links_active() <= 1)
btm_chg_all_acl_pkt_types(FALSE);
// MWCC requires the second database address computation after the calls.
p = btm_cb.sco_cb.sco_db;
/* explicitly post-increment */

View File

@@ -89,21 +89,18 @@ void btu_task_init(void)
void btu_task_msg_handler(void)
{
TIMER_LIST_ENT *r30;
BT_HDR *r29;
unsigned char r28;
unsigned short r27;
unsigned char r26;
TIMER_LIST_ENT *p_tle;
BT_HDR *p_msg;
UINT8 i;
UINT16 event;
BOOLEAN handled;
OSTime sp10;
signed (*sp0c)(TIMER_LIST_ENT *);
unsigned short sp0a;
unsigned char sp09;
char sp08;
tBTU_TIMER_CALLBACK *p_timeout_cback;
UINT16 mask;
BOOLEAN messages_done;
sp09 = 0;
sp08 = 1;
sp10 = OSGetTime();
messages_done = FALSE;
OSGetTime();
++_btu_g_count;
@@ -112,7 +109,6 @@ void btu_task_msg_handler(void)
if (execute_btu)
{
execute_btu = 0;
sp08 = btu_count;
btu_count = 1;
}
else
@@ -125,109 +121,110 @@ void btu_task_msg_handler(void)
GKI_enable();
r27 = 0x05;
event = TASK_MBOX_0_EVT_MASK | TASK_MBOX_2_EVT_MASK;
if ((unsigned)_btu_g_count > (unsigned)_btu_last_timer_tick + 500)
{
r27 |= 0x30;
event |= TIMER_0_EVT_MASK | TIMER_1_EVT_MASK;
_btu_last_timer_tick = _btu_g_count;
}
while (sp09 == 0)
while (!messages_done)
{
sp09 = 1;
messages_done = TRUE;
if (r27 & (1 << 0))
if (event & TASK_MBOX_0_EVT_MASK)
{
while ((r29 = GKI_read_mbox(0)))
while ((p_msg = GKI_read_mbox(BTU_HCI_RCV_MBOX)))
{
sp09 = 0;
messages_done = FALSE;
BTU_TASK_TRACE("BTU Task got msg in MBOX0\n");
switch (r29->event & 0xff00)
switch (p_msg->event & 0xff00)
{
case 0x1100:
l2c_rcv_acl_data(r29);
l2c_rcv_acl_data(p_msg);
break;
case 0x1900:
l2c_link_segments_xmitted(r29);
l2c_link_segments_xmitted(p_msg);
break;
case 0x1200:
btm_route_sco_data(r29);
btm_route_sco_data(p_msg);
break;
case 0x1000:
btu_hcif_process_event(r29);
GKI_freebuf(r29);
btu_hcif_process_event(p_msg);
GKI_freebuf(p_msg);
break;
case 0x1600:
btu_hcif_send_cmd(r29);
btu_hcif_send_cmd(p_msg);
break;
default:
r28 = 0;
sp0a = r29->event & 0xff00;
r26 = 0;
i = 0;
mask = p_msg->event & 0xff00;
handled = FALSE;
for (; r26 == 0 && r28 < BTU_MAX_REG_EVENT; ++r28)
for (; !handled && i < BTU_MAX_REG_EVENT; ++i)
{
if (!btu_cb.event_reg[r28].event_cb)
if (!btu_cb.event_reg[i].event_cb)
continue;
if (sp0a != btu_cb.event_reg[r28].event_range)
if (mask != btu_cb.event_reg[i].event_range)
continue;
if (btu_cb.event_reg[r28].event_cb)
// MWCC requires this repeated callback check.
if (btu_cb.event_reg[i].event_cb)
{
(*btu_cb.event_reg[r28].event_cb)(r29);
r26 = 1;
(*btu_cb.event_reg[i].event_cb)(p_msg);
handled = TRUE;
}
}
if (r26 == 0)
GKI_freebuf(r29);
if (!handled)
GKI_freebuf(p_msg);
}
}
}
if (r27 & (1 << 4))
if (event & TIMER_0_EVT_MASK)
{
GKI_update_timer_list(&btu_cb.timer_queue, 1);
r27 &= ~(1 << 4);
event &= ~TIMER_0_EVT_MASK;
while (btu_cb.timer_queue.p_first
&& btu_cb.timer_queue.p_first->ticks == 0)
{
sp09 = 0;
messages_done = FALSE;
r30 = btu_cb.timer_queue.p_first;
GKI_remove_from_timer_list(&btu_cb.timer_queue, r30);
p_tle = btu_cb.timer_queue.p_first;
GKI_remove_from_timer_list(&btu_cb.timer_queue, p_tle);
switch (r30->event)
switch (p_tle->event)
{
case 1:
btm_dev_timeout(r30);
case BTU_TTYPE_BTM_DEV_CTL:
btm_dev_timeout(p_tle);
break;
case 9:
btm_acl_timeout(r30);
case BTU_TTYPE_BTM_ACL:
btm_acl_timeout(p_tle);
break;
case 2:
case 3:
case 4:
l2c_process_timeout(r30);
case BTU_TTYPE_L2CAP_LINK:
case BTU_TTYPE_L2CAP_CHNL:
case BTU_TTYPE_L2CAP_HOLD:
l2c_process_timeout(p_tle);
break;
case 5:
sdp_conn_timeout((tCONN_CB *)r30->param);
case BTU_TTYPE_SDP:
sdp_conn_timeout((tCONN_CB *)p_tle->param);
break;
case 10:
case BTU_TTYPE_BTM_RMT_NAME:
btm_inq_rmt_name_failed();
break;
@@ -235,63 +232,63 @@ void btu_task_msg_handler(void)
btm_discovery_timeout();
break;
case 11:
case 12:
rfcomm_process_timeout(r30);
case BTU_TTYPE_RFCOMM_MFC:
case BTU_TTYPE_RFCOMM_PORT:
rfcomm_process_timeout(p_tle);
break;
case 60:
case BTU_TTYPE_BTU_CMD_CMPL:
btu_hcif_cmd_timeout();
break;
case 66:
hidh_proc_repage_timeout(r30);
case BTU_TTYPE_HID_HOST_REPAGE_TO:
hidh_proc_repage_timeout(p_tle);
break;
case 22:
sp0c = (signed (*)(TIMER_LIST_ENT *p_tle))r30->param;
p_timeout_cback = (tBTU_TIMER_CALLBACK *)p_tle->param;
(*sp0c)(r30);
(*p_timeout_cback)(p_tle);
break;
default:
r28 = 0;
r26 = 0;
i = 0;
handled = FALSE;
for (; r26 == 0 && r28 < BTU_MAX_REG_TIMER; ++r28)
for (; !handled && i < BTU_MAX_REG_TIMER; ++i)
{
if (!btu_cb.timer_reg[r28].timer_cb)
if (!btu_cb.timer_reg[i].timer_cb)
continue;
if (btu_cb.timer_reg[r28].p_tle != r30)
if (btu_cb.timer_reg[i].p_tle != p_tle)
continue;
(*btu_cb.timer_reg[r28].timer_cb)(r30);
r26 = 1;
(*btu_cb.timer_reg[i].timer_cb)(p_tle);
handled = TRUE;
}
}
}
}
if (r27 & (1 << 2))
if (event & TASK_MBOX_2_EVT_MASK)
{
while ((r29 = GKI_read_mbox(2)))
while ((p_msg = GKI_read_mbox(TASK_MBOX_2)))
{
BTU_TASK_TRACE("BTU Task got msg in MBOX2\n");
sp09 = 0;
messages_done = FALSE;
bta_sys_event(r29);
bta_sys_event(p_msg);
}
}
if (r27 & (1 << 5))
if (event & TIMER_1_EVT_MASK)
{
r27 &= ~(1 << 5);
event &= ~TIMER_1_EVT_MASK;
bta_sys_timer_update();
}
if (r27 & (1 << 15))
if (event & (1 << 15))
break;
}

View File

@@ -306,11 +306,6 @@ BOOLEAN gap_is_service_busy(UINT16 request)
return FALSE;
}
# if 0
// Range: 0x730 -> 0x794
unsigned short gap_convert_btm_status(unsigned char btm_status /* r3 */) {}
#endif
UINT16 gap_convert_btm_status(tBTM_STATUS btm_status)
{
switch (btm_status)

View File

@@ -133,16 +133,16 @@ UINT16 hcisu_h2_receive_msg(UINT16 pipe, tHCISU_H2_CB *p_cb)
UINT16 msg_len;
UINT16 len;
UINT8 msg_received;
UINT16 r27;
UINT16 usb_pipe;
if (p_cb->open_state != 2)
return 0;
r27 = pipe + 1;
usb_pipe = pipe + 1;
while (TRUE)
{
if (UUSB_Read(r27, &byte, 1) == 0)
if (UUSB_Read(usb_pipe, &byte, 1) == 0)
break;
++bytes_read;
@@ -151,17 +151,17 @@ UINT16 hcisu_h2_receive_msg(UINT16 pipe, tHCISU_H2_CB *p_cb)
switch (p_cb->rx_state[pipe])
{
case 0:
if (r27 == 1)
if (usb_pipe == 1)
{
p_cb->p_rx_msg[pipe] = GKI_getpoolbuf(GKI_POOL_ID_2);
p_cb->pkt_type[pipe] = 4;
}
else if (r27 == 2)
else if (usb_pipe == 2)
{
p_cb->p_rx_msg[pipe] = GKI_getpoolbuf(GKI_POOL_ID_3);
p_cb->pkt_type[pipe] = 2;
}
else if (r27 == 3)
else if (usb_pipe == 3)
{
p_cb->p_rx_msg[pipe] = GKI_getpoolbuf(GKI_POOL_ID_1);
p_cb->pkt_type[pipe] = 3;
@@ -207,10 +207,10 @@ UINT16 hcisu_h2_receive_msg(UINT16 pipe, tHCISU_H2_CB *p_cb)
{
msg_len = (msg_len << 8) + p_cb->len_hi[pipe];
if ((p_cb->p_rx_msg[pipe] =
(HC_BT_HDR *)l2cap_link_chk_pkt_start(
(BT_HDR *)p_cb->p_rx_msg[pipe]))
== 0)
p_cb->p_rx_msg[pipe] =
(HC_BT_HDR *)l2cap_link_chk_pkt_start(
(BT_HDR *)p_cb->p_rx_msg[pipe]);
if (p_cb->p_rx_msg[pipe] == 0)
{
p_cb->bytes_left[pipe] = msg_len;
@@ -421,10 +421,10 @@ BOOLEAN hcisu_h2_open(tHCI_CFG *_p_cfg)
tHCI_CFG *p_cfg = _p_cfg;
tUUSB uusb;
uusb.at_0x0b = 0;
uusb.at_0x04 = p_cfg->at_0x00;
uusb.at_0x06 = p_cfg->at_0x02;
uusb.at_0x08 = hcisu_h2_cb.task_id;
uusb.reserved = 0;
uusb.vendorId = p_cfg->vendorId;
uusb.productId = p_cfg->productId;
uusb.taskId = hcisu_h2_cb.task_id;
hcisu_h2_cb.open_state = 2;

View File

@@ -623,28 +623,6 @@ static void hidh_l2cif_data_ind(UINT16 l2cap_cid, BT_HDR *p_msg)
}
}
# if 0
UINT8 hidh_conn_snd_data(UINT8 dhandle /* r1+0x8 */, UINT8 trans_type /* r25 */,
UINT8 param /* r22 */, UINT16 data /* r24 */,
UINT8 report_id /* r23 */, BT_HDR *buf /* r31 */)
{
struct hid_conn *p_hcon; // r30
BT_HDR *p_buf; // r29
UINT8 *p_out; // r27
UINT16 bytes_copied; // r28
UINT8 seg_req; // r1+0xC
UINT16 data_size; // r26
UINT16 cid; // r1+0xE
UINT8 pool_id; // r1+0xB
UINT8 use_data; // r1+0xA
UINT8 blank_datc; // r1+0x9
// References
// -> struct host_ctb hh_cb;
}
#endif
tHID_STATUS hidh_conn_snd_data(UINT8 dhandle, UINT8 trans_type, UINT8 param,
UINT16 data, UINT8 report_id, BT_HDR *buf)
{

View File

@@ -61,9 +61,11 @@ BOOLEAN L2CA_Register(UINT16 psm, tL2CAP_APPL_INFO *p_cb_info)
return FALSE;
}
if ((p_rcb = l2cu_find_rcb_by_psm(psm)) == NULL)
p_rcb = l2cu_find_rcb_by_psm(psm);
if (p_rcb == NULL)
{
if ((p_rcb = l2cu_allocate_rcb(psm)) == NULL)
p_rcb = l2cu_allocate_rcb(psm);
if (p_rcb == NULL)
{
L2CAP_TRACE(WARNING, "L2CAP - no RCB available, PSM: 0x%04x", psm);
return FALSE;
@@ -81,7 +83,8 @@ void L2CA_Deregister(UINT16 psm)
L2CAP_TRACE(API, "L2CAP - L2CA_Deregister() called for PSM: 0x%04x", psm);
if ((p_rcb = l2cu_find_rcb_by_psm(psm)) != NULL)
p_rcb = l2cu_find_rcb_by_psm(psm);
if (p_rcb != NULL)
{
l2cu_release_rcb(p_rcb);
}
@@ -110,14 +113,16 @@ UINT16 L2CA_ConnectReq(UINT16 psm, BD_ADDR p_bd_addr)
return 0;
}
if ((p_rcb = l2cu_find_rcb_by_psm(psm)) == NULL)
p_rcb = l2cu_find_rcb_by_psm(psm);
if (p_rcb == NULL)
{
L2CAP_TRACE(WARNING, "L2CAP - no RCB for L2CA_conn_req, PSM: 0x%04x",
psm);
return 0;
}
if ((p_lcb = l2cu_find_lcb_by_bd_addr(p_bd_addr)) == NULL)
p_lcb = l2cu_find_lcb_by_bd_addr(p_bd_addr);
if (p_lcb == NULL)
{
if (((p_lcb = l2cu_allocate_lcb(p_bd_addr)) == NULL))
{
@@ -136,7 +141,8 @@ UINT16 L2CA_ConnectReq(UINT16 psm, BD_ADDR p_bd_addr)
return 0;
}
if ((p_ccb = l2cu_allocate_ccb(p_lcb)) == NULL)
p_ccb = l2cu_allocate_ccb(p_lcb);
if (p_ccb == NULL)
{
L2CAP_TRACE(WARNING, "L2CAP - no CCB for L2CA_conn_req");
return 0;
@@ -166,13 +172,15 @@ BOOLEAN L2CA_ConnectRsp(BD_ADDR p_bd_addr, UINT8 id, UINT16 lcid, UINT16 result,
p_bd_addr[0], p_bd_addr[1], p_bd_addr[2], p_bd_addr[3],
p_bd_addr[4], p_bd_addr[5]);
if ((p_lcb = l2cu_find_lcb_by_bd_addr(p_bd_addr)) == NULL)
p_lcb = l2cu_find_lcb_by_bd_addr(p_bd_addr);
if (p_lcb == NULL)
{
L2CAP_TRACE(WARNING, "L2CAP - no LCB for L2CA_conn_rsp");
return FALSE;
}
if ((p_ccb = l2cu_find_ccb_by_cid(p_lcb, lcid)) == NULL)
p_ccb = l2cu_find_ccb_by_cid(p_lcb, lcid);
if (p_ccb == NULL)
{
L2CAP_TRACE(WARNING, "L2CAP - no CCB for L2CA_conn_rsp");
return FALSE;
@@ -212,7 +220,8 @@ BOOLEAN L2CA_ConfigReq(UINT16 cid, tL2CAP_CFG_INFO *p_cfg)
L2CAP_TRACE(API, "L2CA_ConfigReq() CID: 0x%04x", cid);
if ((p_ccb = l2cu_find_ccb_by_cid(NULL, cid)) == NULL)
p_ccb = l2cu_find_ccb_by_cid(NULL, cid);
if (p_ccb == NULL)
{
L2CAP_TRACE(WARNING, "L2CAP - no CCB for L2CA_cfg_req, CID: %d", cid);
return FALSE;
@@ -232,7 +241,8 @@ BOOLEAN L2CA_ConfigRsp(UINT16 cid, tL2CAP_CFG_INFO *p_cfg)
L2CAP_TRACE(API, "L2CA_ConfigRsp() CID: 0x%04x Result: %d", cid,
p_cfg->result);
if ((p_ccb = l2cu_find_ccb_by_cid(NULL, cid)) == NULL)
p_ccb = l2cu_find_ccb_by_cid(NULL, cid);
if (p_ccb == NULL)
{
L2CAP_TRACE(WARNING, "L2CAP - no CCB for L2CA_cfg_rsp, CID: %d", cid);
return FALSE;
@@ -252,7 +262,8 @@ BOOLEAN L2CA_DisconnectReq(UINT16 cid)
L2CAP_TRACE(API, "L2CA_DisconnectReq() CID: 0x%04x", cid);
if ((p_ccb = l2cu_find_ccb_by_cid(NULL, cid)) == NULL)
p_ccb = l2cu_find_ccb_by_cid(NULL, cid);
if (p_ccb == NULL)
{
L2CAP_TRACE(WARNING, "L2CAP - no CCB for L2CA_disc_req, CID: %d", cid);
return FALSE;
@@ -269,7 +280,8 @@ BOOLEAN L2CA_DisconnectRsp(UINT16 cid)
L2CAP_TRACE(API, "L2CA_DisconnectRsp() CID: 0x%04x", cid);
if ((p_ccb = l2cu_find_ccb_by_cid(NULL, cid)) == NULL)
p_ccb = l2cu_find_ccb_by_cid(NULL, cid);
if (p_ccb == NULL)
{
L2CAP_TRACE(WARNING, "L2CAP - no CCB for L2CA_disc_rsp, CID: %d", cid);
return FALSE;
@@ -287,7 +299,8 @@ UINT8 L2CA_DataWrite(UINT16 cid, BT_HDR *p_data)
L2CAP_TRACE(API, "L2CA_DataWrite() CID: 0x%04x Len: %d", cid,
p_data->len);
if ((p_ccb = l2cu_find_ccb_by_cid(NULL, cid)) == NULL)
p_ccb = l2cu_find_ccb_by_cid(NULL, cid);
if (p_ccb == NULL)
{
L2CAP_TRACE(WARNING, "L2CAP - no CCB for L2CA_DataWrite, CID: %d", cid);
GKI_freebuf(p_data);
@@ -324,9 +337,11 @@ BOOLEAN L2CA_Ping(BD_ADDR p_bd_addr, tL2CA_ECHO_RSP_CB *p_callback)
if (!BTM_IsDeviceUp())
return FALSE;
if ((p_lcb = l2cu_find_lcb_by_bd_addr(p_bd_addr)) == NULL)
p_lcb = l2cu_find_lcb_by_bd_addr(p_bd_addr);
if (p_lcb == NULL)
{
if ((p_lcb = l2cu_allocate_lcb(p_bd_addr)) == NULL)
p_lcb = l2cu_allocate_lcb(p_bd_addr);
if (p_lcb == NULL)
{
L2CAP_TRACE(WARNING, "L2CAP - no LCB for L2CA_ping");
return FALSE;
@@ -374,7 +389,8 @@ BOOLEAN L2CA_SetIdleTimeout(UINT16 cid, UINT16 timeout, BOOLEAN is_global)
}
else
{
if ((p_ccb = l2cu_find_ccb_by_cid(NULL, cid)) == NULL)
p_ccb = l2cu_find_ccb_by_cid(NULL, cid);
if (p_ccb == NULL)
{
L2CAP_TRACE(WARNING,
"L2CAP - no CCB for L2CA_SetIdleTimeout, CID: %d", cid);
@@ -453,7 +469,8 @@ BOOLEAN L2CA_SetAclPriority(BD_ADDR bd_addr, UINT8 priority)
bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4],
bd_addr[5]);
if ((p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr)) == NULL)
p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr);
if (p_lcb == NULL)
{
L2CAP_TRACE(WARNING, "L2CAP - no LCB for L2CA_SetAclPriority");
return FALSE;
@@ -489,28 +506,19 @@ void L2CA_SetCompression(UINT16 local_cid, UINT8 pe_type, UINT8 mem_level,
"pe_type %d, mem_level %d, wbits %d, enable %d",
local_cid, direction, pe_type, mem_level, wbits, enable);
if ((p_ccb = l2cu_find_ccb_by_cid(NULL, local_cid)) == NULL)
p_ccb = l2cu_find_ccb_by_cid(NULL, local_cid);
if (p_ccb == NULL)
return;
p_lcb = p_ccb->p_lcb;
if (p_lcb && p_lcb->in_use && p_lcb->link_state == LST_CONNECTED)
{
#if 0
/* ... */
#endif
}
else
{
// MWCC requires these link checks while compression is disabled.
if (!p_lcb || !p_lcb->in_use || p_lcb->link_state != LST_CONNECTED)
return;
}
}
void L2CA_RegisterCompression(tL2CA_COMPRESS_CB *p_callback, int unused)
{
#if 0
/* ... */
#endif
}
UINT8 L2CA_Flush(UINT16 cid)
@@ -522,7 +530,8 @@ UINT8 L2CA_Flush(UINT16 cid)
int xx;
int num_bufs;
if ((p_ccb = l2cu_find_ccb_by_cid(NULL, cid)) == NULL)
p_ccb = l2cu_find_ccb_by_cid(NULL, cid);
if (p_ccb == NULL)
{
L2CAP_TRACE(WARNING, "L2CAP - no CCB for L2CA_Flush, CID: %d", cid);
return FALSE;

View File

@@ -132,7 +132,8 @@ BOOLEAN l2c_link_hci_conn_comp(UINT8 status, UINT16 handle, BD_ADDR p_bda)
{
p_lcb->link_state = LST_CONNECTED;
if ((p_dev_info = btm_find_dev(p_bda)) != NULL)
p_dev_info = btm_find_dev(p_bda);
if (p_dev_info != NULL)
{
btm_acl_created(ci.bd_addr, p_dev_info->dev_class,
p_dev_info->sec_bd_name, handle, p_lcb->link_role);
@@ -242,7 +243,8 @@ BOOLEAN l2c_link_hci_disc_comp(UINT16 handle, UINT8 reason)
l2cu_release_lcb(p_lcb);
}
if ((p_lcb = l2cu_find_lcb_by_state(LST_CONNECT_HOLDING)) != NULL)
p_lcb = l2cu_find_lcb_by_state(LST_CONNECT_HOLDING);
if (p_lcb != NULL)
l2cu_create_conn(p_lcb);
return status;
@@ -757,7 +759,8 @@ void l2c_link_segments_xmitted(BT_HDR *p_msg)
STREAM_TO_UINT16(p, &handle);
handle = HCID_GET_HANDLE(handle);
if ((p_lcb = l2cu_find_lcb_by_handle(handle)) == NULL)
p_lcb = l2cu_find_lcb_by_handle(handle);
if (p_lcb == NULL)
{
L2CAP_TRACE(WARNING,
"L2CAP - rcvd segment complete, unknown handle: %d",

View File

@@ -561,9 +561,6 @@ static void process_l2cap_cmd(tL2C_LCB *p_lcb, UINT8 *p, UINT16 pkt_len)
void l2c_process_compress_setup_timeout(TIMER_LIST_ENT *p_tle)
{
#if 0
/* ... */
#endif
}
void l2c_process_timeout(TIMER_LIST_ENT *p_tle)

View File

@@ -162,7 +162,8 @@ BT_HDR *l2cu_build_header(UINT16 hci_handle, UINT16 len, UINT8 cmd, UINT8 id)
BT_HDR *p_buf;
UINT8 *p;
if ((p_buf = GKI_getpoolbuf(L2CAP_CMD_POOL_ID)) == NULL)
p_buf = GKI_getpoolbuf(L2CAP_CMD_POOL_ID);
if (p_buf == NULL)
return NULL;
p_buf->offset = L2CAP_SEND_CMD_OFFSET;
@@ -1097,7 +1098,8 @@ BOOLEAN l2cu_create_conn_after_switch(tL2C_LCB *p_lcb)
p_lcb->link_state = LST_CONNECTING;
if ((p_inq_info = BTM_InqDbRead(p_lcb->remote_bd_addr)) != NULL)
p_inq_info = BTM_InqDbRead(p_lcb->remote_bd_addr);
if (p_inq_info != NULL)
{
page_scan_rep_mode = p_inq_info->results.page_scan_rep_mode;
page_scan_mode = p_inq_info->results.page_scan_mode;
@@ -1201,7 +1203,6 @@ BOOLEAN l2cu_check_feature_req(tL2C_LCB *p_lcb, UINT8 id, UINT8 *p_data,
UINT8 buff[100];
UINT8 *p_out = buff;
UINT8 *p_end = p_data + data_len - 2;
UINT8 pe_type;
UINT8 pe_len;
if (data_len < 4 || p_data[0] != 'R' || p_data[1] != 'Q'
@@ -1218,15 +1219,10 @@ BOOLEAN l2cu_check_feature_req(tL2C_LCB *p_lcb, UINT8 id, UINT8 *p_data,
while (p_data < p_end)
{
pe_type = *p_data++;
p_data++;
pe_len = *p_data++;
switch (pe_type)
{
default:
p_data += pe_len;
break;
}
p_data += pe_len;
}
if (p_data != p_end)
@@ -1259,16 +1255,12 @@ void l2cu_check_feature_rsp(tL2C_LCB *p_lcb, UINT8 id, UINT8 *p_data,
while (p_data < p_end)
{
UINT8 pe_id = *p_data++;
UINT8 pe_len = *p_data++;
UINT8 pe_len;
// This is kind of crazy LOL
switch (pe_id)
{
default:
p_data += pe_len;
break;
}
p_data++;
pe_len = *p_data++;
p_data += pe_len;
}
if (p_data != p_end)
@@ -1277,9 +1269,6 @@ void l2cu_check_feature_rsp(tL2C_LCB *p_lcb, UINT8 id, UINT8 *p_data,
void l2cu_stop_compression(/* void? */)
{
#if 0
/* ... */
#endif
}
BOOLEAN l2cu_lcb_has_feature_enable(/* tL2C_LCB *p_lcb? */)

View File

@@ -81,7 +81,8 @@ int RFCOMM_CreateConnection(UINT16 uuid, UINT8 scn, BOOLEAN is_server,
}
}
if ((p_port = port_allocate_port(dlci, bd_addr)) == NULL)
p_port = port_allocate_port(dlci, bd_addr);
if (p_port == NULL)
{
RFCOMM_TRACE(WARNING, "RFCOMM_CreateConnection - no resources");
return PORT_NO_RESOURCES;
@@ -125,7 +126,8 @@ int RFCOMM_CreateConnection(UINT16 uuid, UINT8 scn, BOOLEAN is_server,
{
rfcomm_mtu = L2CAP_MTU_SIZE - RFCOMM_DATA_OVERHEAD;
if (mtu) // ?
// MWCC requires this repeated MTU test for the original instructions.
if (mtu)
p_port->mtu = mtu < rfcomm_mtu ? mtu : rfcomm_mtu;
else
p_port->mtu = rfcomm_mtu;
@@ -921,7 +923,8 @@ int PORT_Test(UINT16 handle, UINT8 *p_data, UINT16 len)
if (len > (p_port->mtu == 0 ? RFCOMM_DEFAULT_MTU : p_port->mtu))
return PORT_UNKNOWN_ERROR;
if ((p_buf = GKI_getpoolbuf(RFCOMM_CMD_POOL_ID)) != NULL)
p_buf = GKI_getpoolbuf(RFCOMM_CMD_POOL_ID);
if (p_buf != NULL)
{
p_buf->offset = L2CAP_MIN_OFFSET + RFCOMM_MIN_OFFSET + 2;
p_buf->len = len;

View File

@@ -45,7 +45,8 @@ int port_open_continue(tPORT *p_port)
RFCOMM_TRACE(EVENT, "port_open_continue");
if ((p_mcb = rfc_alloc_multiplexer_channel(p_port->bd_addr, TRUE)) == NULL)
p_mcb = rfc_alloc_multiplexer_channel(p_port->bd_addr, TRUE);
if (p_mcb == NULL)
{
RFCOMM_TRACE(WARNING, "port_open_continue no mx channel");
port_release_port(p_port);
@@ -653,7 +654,8 @@ void PORT_FlowInd(tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN enable_data)
}
else
{
if ((p_port = port_find_mcb_dlci_port(p_mcb, dlci)) == NULL)
p_port = port_find_mcb_dlci_port(p_mcb, dlci);
if (p_port == NULL)
return;
p_port->tx.peer_fc = !enable_data;
@@ -695,7 +697,8 @@ UINT32 port_rfc_send_tx_data(tPORT *p_port)
while (!p_port->tx.peer_fc && p_port->rfc.p_mcb
&& p_port->rfc.p_mcb->peer_ready)
{
if ((p_buf = GKI_dequeue(&p_port->tx.queue)) != NULL)
p_buf = GKI_dequeue(&p_port->tx.queue);
if (p_buf != NULL)
{
RFCOMM_TRACE(EVENT, "Sending RFCOMM_DataReq");

View File

@@ -100,7 +100,8 @@ static void rfc_mx_sm_state_idle(tRFC_MCB *p_mcb, UINT16 event, void *p_data)
case RFC_MX_EVENT_START_REQ:
p_mcb->peer_l2cap_mtu = L2CAP_DEFAULT_MTU - RFCOMM_MIN_OFFSET - 1;
if ((p_mcb->lcid = L2CA_ConnectReq(BT_PSM_RFCOMM, p_mcb->bd_addr)) == 0)
p_mcb->lcid = L2CA_ConnectReq(BT_PSM_RFCOMM, p_mcb->bd_addr);
if (p_mcb->lcid == 0)
{
PORT_StartCnf(p_mcb, RFCOMM_ERROR);
return;

View File

@@ -336,8 +336,8 @@ BOOLEAN SDP_FindAddProtoListsElemInRec(tSDP_DISC_REC *p_rec, UINT16 layer_uuid,
if (SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type)
== DATA_ELE_SEQ_DESC_TYPE)
{
if ((ret = sdp_fill_proto_elem(p_sattr, layer_uuid, p_elem))
== TRUE)
ret = sdp_fill_proto_elem(p_sattr, layer_uuid, p_elem);
if (ret == TRUE)
{
break;
}
@@ -577,9 +577,11 @@ UINT16 SDP_SetLocalDiRecord(tSDP_DI_RECORD *p_device_info, UINT32 *p_handle)
{
handle = sdp_cb.server_db.di_primary_handle;
}
else if ((handle = SDP_CreateRecord()) == 0)
else
{
return SDP_NO_RESOURCES;
handle = SDP_CreateRecord();
if (handle == 0)
return SDP_NO_RESOURCES;
}
*p_handle = handle;
@@ -724,63 +726,64 @@ UINT16 SDP_GetLocalDiRecord(tSDP_DI_GET_RECORD *p_device_info, UINT32 *p_handle)
if (*p_handle == 0)
*p_handle = sdp_cb.server_db.di_primary_handle;
if ((p_rec = sdp_db_find_record(*p_handle)) != NULL)
p_rec = sdp_db_find_record(*p_handle);
if (p_rec != NULL)
{
// ERRATUM: uses sizeof(tSDP_DI_RECORD), not sizeof(tSDP_DI_GET_RECORD)
memset(p_device_info, 0, sizeof(tSDP_DI_RECORD));
result = SDP_SUCCESS;
if ((p_attr = sdp_db_find_attr_in_rec(p_rec, ATTR_ID_SPECIFICATION_ID,
ATTR_ID_SPECIFICATION_ID))
!= NULL)
p_attr = sdp_db_find_attr_in_rec(
p_rec, ATTR_ID_SPECIFICATION_ID, ATTR_ID_SPECIFICATION_ID);
if (p_attr != NULL)
{
p_temp = p_attr->value_ptr;
BE_STREAM_TO_UINT16(p_temp, &p_device_info->spec_id);
}
if ((p_attr = sdp_db_find_attr_in_rec(p_rec, ATTR_ID_VENDOR_ID,
ATTR_ID_VENDOR_ID))
!= NULL)
p_attr = sdp_db_find_attr_in_rec(
p_rec, ATTR_ID_VENDOR_ID, ATTR_ID_VENDOR_ID);
if (p_attr != NULL)
{
p_temp = p_attr->value_ptr;
BE_STREAM_TO_UINT16(p_temp, &p_device_info->rec.vendor);
}
if ((p_attr = sdp_db_find_attr_in_rec(p_rec, ATTR_ID_PRODUCT_ID,
ATTR_ID_PRODUCT_ID))
!= NULL)
p_attr = sdp_db_find_attr_in_rec(
p_rec, ATTR_ID_PRODUCT_ID, ATTR_ID_PRODUCT_ID);
if (p_attr != NULL)
{
p_temp = p_attr->value_ptr;
BE_STREAM_TO_UINT16(p_temp, &p_device_info->rec.product);
}
if ((p_attr = sdp_db_find_attr_in_rec(p_rec, ATTR_ID_PRODUCT_VERSION,
ATTR_ID_PRODUCT_VERSION))
!= NULL)
p_attr = sdp_db_find_attr_in_rec(
p_rec, ATTR_ID_PRODUCT_VERSION, ATTR_ID_PRODUCT_VERSION);
if (p_attr != NULL)
{
p_temp = p_attr->value_ptr;
BE_STREAM_TO_UINT16(p_temp, &p_device_info->rec.version);
}
if ((p_attr = sdp_db_find_attr_in_rec(p_rec, ATTR_ID_VENDOR_ID_SOURCE,
ATTR_ID_VENDOR_ID_SOURCE))
!= NULL)
p_attr = sdp_db_find_attr_in_rec(
p_rec, ATTR_ID_VENDOR_ID_SOURCE, ATTR_ID_VENDOR_ID_SOURCE);
if (p_attr != NULL)
{
p_temp = p_attr->value_ptr;
BE_STREAM_TO_UINT16(p_temp, &p_device_info->rec.vendor_id_source);
}
if ((p_attr = sdp_db_find_attr_in_rec(p_rec, ATTR_ID_PRIMARY_RECORD,
ATTR_ID_PRIMARY_RECORD))
!= NULL)
p_attr = sdp_db_find_attr_in_rec(
p_rec, ATTR_ID_PRIMARY_RECORD, ATTR_ID_PRIMARY_RECORD);
if (p_attr != NULL)
{
p_device_info->rec.primary_record = *p_attr->value_ptr;
}
if ((p_attr = sdp_db_find_attr_in_rec(p_rec, ATTR_ID_CLIENT_EXE_URL,
ATTR_ID_CLIENT_EXE_URL))
!= NULL)
p_attr = sdp_db_find_attr_in_rec(
p_rec, ATTR_ID_CLIENT_EXE_URL, ATTR_ID_CLIENT_EXE_URL);
if (p_attr != NULL)
{
templen =
p_attr->len < SDP_MAX_ATTR_LEN ? p_attr->len : SDP_MAX_ATTR_LEN;
@@ -790,10 +793,9 @@ UINT16 SDP_GetLocalDiRecord(tSDP_DI_GET_RECORD *p_device_info, UINT32 *p_handle)
templen);
}
if ((p_attr =
sdp_db_find_attr_in_rec(p_rec, ATTR_ID_SERVICE_DESCRIPTION,
ATTR_ID_SERVICE_DESCRIPTION))
!= NULL)
p_attr = sdp_db_find_attr_in_rec(
p_rec, ATTR_ID_SERVICE_DESCRIPTION, ATTR_ID_SERVICE_DESCRIPTION);
if (p_attr != NULL)
{
templen =
p_attr->len < SDP_MAX_ATTR_LEN ? p_attr->len : SDP_MAX_ATTR_LEN;
@@ -803,9 +805,9 @@ UINT16 SDP_GetLocalDiRecord(tSDP_DI_GET_RECORD *p_device_info, UINT32 *p_handle)
templen);
}
if ((p_attr = sdp_db_find_attr_in_rec(p_rec, ATTR_ID_DOCUMENTATION_URL,
ATTR_ID_DOCUMENTATION_URL))
!= NULL)
p_attr = sdp_db_find_attr_in_rec(
p_rec, ATTR_ID_DOCUMENTATION_URL, ATTR_ID_DOCUMENTATION_URL);
if (p_attr != NULL)
{
templen =
p_attr->len < SDP_MAX_ATTR_LEN ? p_attr->len : SDP_MAX_ATTR_LEN;

View File

@@ -84,7 +84,7 @@ void HCI_TRACE(char const *p_msg)
/* ... */
}
void HCI_TRACE1(char const *p_msg, UINT32 arg1)
void HCI_TRACE1(char const *p_msg, UINT32 value)
{
/* ... */
}
@@ -172,21 +172,17 @@ static void uusb_CloseDeviceCB(long result, void *p_data)
static void uusb_ReadIntrDataCB(long result, void *p_data)
{
// MWCC requires this local for the original callback instructions.
int sp14 = 0;
UINT32 len;
void *p_buffer = NULL;
HC_BT_HDR *p_buf = p_data;
int sp10 = 0;
int sp0c = 0;
len = 0;
usb.reading_intr_data = FALSE;
if (usb.state != 2)
{
GKI_freebuf(p_buf);
p_buf = NULL;
uusb_ReleaseCmdBufferPool();
@@ -199,7 +195,6 @@ static void uusb_ReadIntrDataCB(long result, void *p_data)
if (result <= 0)
{
GKI_freebuf(p_buf);
p_buf = NULL;
goto end;
}
@@ -207,7 +202,6 @@ static void uusb_ReadIntrDataCB(long result, void *p_data)
if (!p_buffer)
{
GKI_freebuf(p_buf);
p_buf = NULL;
goto end;
}
@@ -222,7 +216,6 @@ static void uusb_ReadIntrDataCB(long result, void *p_data)
__uusb_ppc_stack1 + sizeof __uusb_ppc_stack1);
GKI_freebuf(p_buf);
p_buf = NULL;
end:
uusb_issue_intr_read();
@@ -230,18 +223,13 @@ end:
static void uusb_ReadBulkDataCB(long result, void *p_data)
{
int sp14 = 0;
UINT32 len;
void *p_buffer = NULL;
HC_BT_HDR *p_buf = p_data;
int sp10 = 0;
len = 0;
if (usb.state != 2)
{
GKI_freebuf(p_buf);
p_buf = NULL;
uusb_ReleaseAclBufferPool();
@@ -251,7 +239,6 @@ static void uusb_ReadBulkDataCB(long result, void *p_data)
if (result <= 0)
{
GKI_freebuf(p_buf);
p_buf = NULL;
goto end;
}
@@ -261,7 +248,6 @@ static void uusb_ReadBulkDataCB(long result, void *p_data)
if (!p_buffer)
{
GKI_freebuf(p_buf);
p_buf = NULL;
goto end;
}
@@ -276,11 +262,9 @@ static void uusb_ReadBulkDataCB(long result, void *p_data)
OSSwitchFiberEx((unsigned long)p_buffer, 0, 0, 0,
&bta_ci_hci_msg_handler,
__uusb_ppc_stack2 + sizeof __uusb_ppc_stack2);
p_buffer = 0;
}
GKI_freebuf(p_buf);
p_buf = NULL;
end:
uusb_issue_bulk_read();
@@ -290,7 +274,6 @@ static void uusb_issue_bulk_read(void)
{
HC_BT_HDR *p_buf = NULL;
void *p_buffer;
int r28 = 0;
IOSError ret;
do
@@ -312,7 +295,6 @@ static void uusb_issue_bulk_read(void)
if (ret != 0)
{
GKI_freebuf(p_buf);
p_buf = NULL;
}
}
@@ -320,7 +302,6 @@ static void uusb_issue_intr_read(void)
{
HC_BT_HDR *p_buf = NULL;
void *p_buffer = NULL;
int r28 = 0;
IOSError ret;
do
@@ -341,7 +322,6 @@ static void uusb_issue_intr_read(void)
if (ret != 0)
{
GKI_freebuf(p_buf);
p_buf = NULL;
}
usb.reading_intr_data = TRUE;
@@ -359,7 +339,6 @@ static void uusb_WriteCtrlDataCB(long result, void *p_data)
if (p_data != NULL)
{
GKI_freebuf(p_data);
p_data = NULL;
GKI_disable();
@@ -407,7 +386,6 @@ static void uusb_WriteBulkDataCB(long result, void *p_data)
if (p_data != NULL)
{
GKI_freebuf(p_data);
p_data = NULL;
GKI_disable();
@@ -582,10 +560,8 @@ int UUSB_WriteBuf(/* ... */)
UINT16 UUSB_Write(UINT8 pipe, void *p_data, UINT16 len, void *unused)
{
short sp18 = 0;
IOSError ret = 0;
void *p_buffer = NULL;
int sp_0x1c = 0;
HC_BT_HDR *p_buf = NULL;
if (usb.state != 2)
@@ -628,7 +604,6 @@ UINT16 UUSB_Write(UINT8 pipe, void *p_data, UINT16 len, void *unused)
UUSBDBG("ret was negative eight: %d (8, eight)", ret);
GKI_freebuf(p_buf);
p_buf = NULL;
}
else
{
@@ -675,11 +650,9 @@ UINT16 UUSB_Write(UINT8 pipe, void *p_data, UINT16 len, void *unused)
if (ret != -22)
UUSBDBG("ret was negative 2wenty 2wo: %d", ret);
if (ret == -8);
UUSBDBG("rat was negative eight: %d", ret);
UUSBDBG("rat was negative eight: %d", ret);
GKI_freebuf(p_buf);
p_buf = NULL;
}
else
{

View File

@@ -43,7 +43,6 @@ static BOOL IsCard(u32 id) {
}
default: {
return FALSE;
break;
}
}

View File

@@ -6,6 +6,7 @@
static void WriteCallback(s32 chan, s32 result);
static void EraseCallback(s32 chan, s32 result);
// MWCC needs write failures to bypass the shared command-status check.
static void WriteCallback(s32 chan, s32 result) {
CARDControl* card;
CARDCallback callback;
@@ -19,7 +20,7 @@ static void WriteCallback(s32 chan, s32 result) {
fileInfo = card->fileInfo;
if (fileInfo->length < 0) {
result = CARD_RESULT_CANCELED;
goto after;
goto finish_write;
}
fileInfo->length -= card->sectorSize;
if (fileInfo->length <= 0) {
@@ -29,23 +30,23 @@ static void WriteCallback(s32 chan, s32 result) {
callback = card->apiCallback;
card->apiCallback = NULL;
result = __CARDUpdateDir(chan, callback);
goto check;
goto check_command_result;
} else {
fat = __CARDGetFatBlock(card);
fileInfo->offset += card->sectorSize;
fileInfo->iBlock = fat[fileInfo->iBlock];
if ((fileInfo->iBlock < 5) || (fileInfo->iBlock >= card->cBlock)) {
result = CARD_RESULT_BROKEN;
goto after;
goto finish_write;
}
result = __CARDEraseSector(chan, card->sectorSize * fileInfo->iBlock, EraseCallback);
check:
check_command_result:
if (result < 0) {
goto after;
goto finish_write;
}
}
} else {
after:
finish_write:
callback = card->apiCallback;
card->apiCallback = NULL;
__CARDPutControlBlock(card, result);
@@ -62,16 +63,14 @@ static void EraseCallback(s32 chan, s32 result) {
if (result >= 0) {
fileInfo = card->fileInfo;
result = __CARDWrite(chan, card->sectorSize * fileInfo->iBlock, card->sectorSize, card->buffer, WriteCallback);
if (result < 0) {
goto after;
if (result >= 0) {
return;
}
} else {
after:
callback = card->apiCallback;
card->apiCallback = NULL;
__CARDPutControlBlock(card, result);
callback(chan, result);
}
callback = card->apiCallback;
card->apiCallback = NULL;
__CARDPutControlBlock(card, result);
callback(chan, result);
}
s32 CARDWriteAsync(CARDFileInfo* fileInfo, void* buf, s32 length, s32 offset, CARDCallback callback) {

View File

@@ -251,23 +251,26 @@ s32 contentConvertPathToEntrynumDVD(CNTHandleDVD* cntHandle, const char* path) {
ptrPath = path;
for (i = dirLookAt + 1; i < FstStart[dirLookAt].dir.next; i = IS_ENTRY_DIR(FstStart, i) ? FstStart[i].dir.next : (i + 1)) {
loop_back:
// Skip directories
if (IS_ENTRY_DIR(FstStart, i) == FALSE && isDir == TRUE) {
continue;
}
do {
// Skip directories
if (IS_ENTRY_DIR(FstStart, i) == FALSE && isDir == TRUE) {
break;
}
name = FstStringStart + FILE_STRING_OFF(FstStart, i);
name = FstStringStart + FILE_STRING_OFF(FstStart, i);
if (*name == '.' && *(name + 1) == 0) {
i++;
goto loop_back;
}
if (*name == '.' && *(name + 1) == 0) {
i++;
continue;
}
// Advance to next file in hierarchy
if (isSame(ptrPath, name) == TRUE) {
goto next_in_hier;
}
// Advance to next file in hierarchy
if (isSame(ptrPath, name) == TRUE) {
// MWCC needs this join to preserve the original search branches.
goto next_in_hier;
}
break;
} while (TRUE);
}
return -1;

View File

@@ -1,4 +1,5 @@
#include <revolution/os.h>
#include <revolution/verdefs.h>
#include <private/nand.h>
#include <revolution/nand.h>
#include <private/es.h>
@@ -7,37 +8,21 @@
#include <stdlib.h>
#include <string.h>
char scCntCacheStrs[0xd0] = {
0x3c, 0x3c, 0x20, 0x52, 0x56, 0x4c, 0x5f, 0x53, 0x44, 0x4b, 0x20, 0x2d, 0x20, 0x43, 0x4e, 0x54,
0x43, 0x41, 0x43, 0x48, 0x45, 0x20, 0x09, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x20, 0x62,
0x75, 0x69, 0x6c, 0x64, 0x3a, 0x20, 0x41, 0x70, 0x72, 0x20, 0x32, 0x30, 0x20, 0x32, 0x30, 0x31,
0x30, 0x20, 0x31, 0x34, 0x3a, 0x31, 0x35, 0x3a, 0x32, 0x38, 0x20, 0x28, 0x30, 0x78, 0x34, 0x31,
0x39, 0x39, 0x5f, 0x36, 0x30, 0x38, 0x33, 0x31, 0x29, 0x20, 0x3e, 0x3e, 0x00, 0x00, 0x00, 0x00,
0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x32, 0x2f, 0x63, 0x6e, 0x74, 0x63, 0x61, 0x63, 0x68,
0x65, 0x2e, 0x74, 0x78, 0x74, 0x00, 0x00, 0x00, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x54, 0x69,
0x74, 0x6c, 0x65, 0x20, 0x00, 0x00, 0x00, 0x00, 0x25, 0x30, 0x31, 0x36, 0x6c, 0x6c, 0x78, 0x20,
0x00, 0x00, 0x00, 0x00, 0x2f, 0x74, 0x6d, 0x70, 0x2f, 0x63, 0x6e, 0x74, 0x63, 0x61, 0x63, 0x68,
0x65, 0x2e, 0x74, 0x78, 0x74, 0x00, 0x00, 0x00, 0x2f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x32,
0x00, 0x00, 0x00, 0x00, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e,
0x74, 0x20, 0x00, 0x00, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x54, 0x69, 0x74, 0x6c, 0x65, 0x00,
0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x00, 0x00, 0x00
};
char scCntCacheTitleDataFmt[0x16] = {
0x2f, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x2f, 0x25, 0x30, 0x38, 0x78, 0x2f, 0x25, 0x30, 0x38, 0x78,
0x2f, 0x64, 0x61, 0x74, 0x61, 0x00,
};
const char* __CNTCACHEVersion = scCntCacheStrs;
char scCntCacheSpaceNl[3] = {0x20, 0x0a, 0x00};
#define CNTCACHE_FILE "/shared2/cntcache.txt"
#define CNTCACHE_TMP_FILE "/tmp/cntcache.txt"
#define CNTCACHE_DIR "/shared2"
#define CNTCACHE_READ_SIZE 0x400
#define CNTCACHE_LINE_SIZE 0x40
#define CNTCACHE_RESULT_IO_ERROR (-5299)
extern void _savegpr_23();
extern void _restgpr_23();
SDKDefineVersion(CNTCACHE, "Apr 20 2010", "14:15:28");
OSMutex _CNTCACHEMutex;
long long _CNTCACHEUnused816997A8;
int _CNTCACHEUnused816997A4;
BOOL _CNTCACHEInitialized;
void CNTCACHEClear();
s32 CNTCACHEClear(void);
BOOL _CNTCACHEIsTitleRemovable(ESTitleId titleId);
void _CNTCACHEDeleteTitle();
void _CNTCACHEDeleteContent();
@@ -61,203 +46,243 @@ void CNTCACHEInit(int cacheValue, int cacheHighWord) {
_CNTCACHEUnused816997A4 = cacheValue;
*((int*)&_CNTCACHEUnused816997A8) = cacheHighWord;
}
asm void CNTCACHEClear() {
clrlwi r11, r1, 0x1b
mr r12, r1
subfic r11, r11, -0x500
stwux r1, r1, r11
mflr r0
mr r11, r12
stw r0, 4(r12)
bl _savegpr_23
lis r30, scCntCacheStrs@ha
lis r3, _CNTCACHEMutex@ha
addi r30, r30, scCntCacheStrs@l
li r29, 0
addi r3, r3, _CNTCACHEMutex@l
bl OSLockMutex
addi r3, r30, 0x50
addi r4, r1, 0x24
li r27, 1
li r5, 3
bl NANDPrivateOpen
cmpwi r3, -0xc
mr r28, r3
bne L_d4
li r28, 0
b L_28c
L_d4:
cmpwi r3, 0
beq L_e0
b L_268
L_e0:
addi r3, r1, 0x24
addi r4, r1, 0x20
bl NANDGetLength
cmpwi r3, 0
mr r28, r3
beq L_fc
b L_268
L_fc:
li r26, 0
li r31, 0
b L_25c
L_108:
lwz r25, 0x20(r1)
cmplwi r25, 0x400
ble L_118
li r25, 0x400
L_118:
addi r24, r1, 0xc0
addi r0, r25, 0x1f
addi r3, r1, 0x24
mr r4, r24
rlwinm r5, r0, 0, 0, 0x1a
bl NANDRead
cmpw r3, r25
beq L_140
li r28, -0x14b3
b L_268
L_140:
mr r4, r24
li r28, 0
mtctr r25
cmplwi r25, 0
ble L_16c
L_154:
lbz r0, 0(r4)
cmpwi r0, 0xa
bne L_164
b L_170
L_164:
addi r4, r4, 1
bdnz L_154
L_16c:
li r4, 0
L_170:
cmpwi r4, 0
bne L_224
li r28, 0
b L_268
b L_224
L_184:
stb r31, 0(r4)
subf r23, r24, r4
mr r3, r24
la r4, scCntCacheSpaceNl
bl strtok
cmpwi r3, 0
mr r29, r3
beq L_1d4
addi r4, r30, 0xb4
bl strcmp
cmpwi r3, 0
bne L_1bc
bl _CNTCACHEDeleteTitle
b L_1d4
L_1bc:
mr r3, r29
addi r4, r30, 0xc0
bl strcmp
cmpwi r3, 0
bne L_1d4
bl _CNTCACHEDeleteContent
L_1d4:
lwz r0, 0x20(r1)
addi r23, r23, 1
add r24, r24, r23
subf r0, r23, r0
subf r25, r23, r25
mr r4, r24
stw r0, 0x20(r1)
add r26, r26, r23
mtctr r25
cmplwi r25, 0
ble L_218
L_200:
lbz r0, 0(r4)
cmpwi r0, 0xa
bne L_210
b L_21c
L_210:
addi r4, r4, 1
bdnz L_200
L_218:
li r4, 0
L_21c:
cmpwi r4, 0
beq L_22c
L_224:
cmpwi r25, 0
bgt L_184
L_22c:
lwz r0, 0x20(r1)
cmpwi r0, 0
beq L_25c
mr r4, r26
addi r3, r1, 0x24
li r5, 0
bl NANDSeek
cmplw r3, r26
beq L_258
li r28, -0x14b3
b L_268
L_258:
li r28, 0
L_25c:
lwz r0, 0x20(r1)
cmpwi r0, 0
bne L_108
L_268:
addi r3, r1, 0x24
bl NANDClose
addi r3, r30, 0x50
li r29, 0
bl NANDPrivateDelete
cmpwi r3, 0
addi r3, r30, 0x84
bl NANDPrivateDelete
cmpwi r3, 0
L_28c:
cmpwi r29, 0
beq L_29c
addi r3, r1, 0x24
bl NANDClose
L_29c:
cmpwi r27, 0
beq L_2b0
lis r3, _CNTCACHEMutex@ha
addi r3, r3, _CNTCACHEMutex@l
bl OSUnlockMutex
L_2b0:
mr r3, r28
lwz r10, 0(r1)
mr r11, r10
bl _restgpr_23
lwz r0, 4(r10)
mtlr r0
mr r1, r10
blr
static s32 ReadCacheFile(char* buf, u32 bufSize, u32* length) {
NANDFileInfo info;
s32 result;
*length = 0;
result = NANDPrivateOpen(CNTCACHE_FILE, &info, NAND_ACCESS_READ);
if (result == NAND_RESULT_NOEXISTS) {
return NAND_RESULT_OK;
}
if (result != NAND_RESULT_OK) {
return result;
}
result = NANDGetLength(&info, length);
if (result == NAND_RESULT_OK && *length > bufSize) {
result = NAND_RESULT_MAXBLOCKS;
}
if (result == NAND_RESULT_OK && NANDRead(&info, buf, OSRoundUp32B(*length)) != *length) {
result = CNTCACHE_RESULT_IO_ERROR;
}
NANDClose(&info);
return result;
}
static s32 WriteCacheFile(const char* buf, u32 length);
s32 CNTCACHEAddDeleteTitle(ESTitleId titleId) {
char buf[CNTCACHE_READ_SIZE + CNTCACHE_LINE_SIZE] ALIGN32;
u32 length;
s32 result;
OSLockMutex(&_CNTCACHEMutex);
result = ReadCacheFile(buf, CNTCACHE_READ_SIZE, &length);
if (result == NAND_RESULT_OK) {
strcpy(buf + length, "DeleteTitle ");
length += strlen(buf + length);
length += sprintf(buf + length, "%016llx ", titleId);
buf[length++] = '\n';
result = WriteCacheFile(buf, length);
}
OSUnlockMutex(&_CNTCACHEMutex);
return result;
}
static s32 WriteCacheFile(const char* buf, u32 length) {
NANDFileInfo info;
s32 result;
NANDPrivateDelete(CNTCACHE_TMP_FILE);
result = NANDPrivateCreate(CNTCACHE_TMP_FILE, NAND_PERM_USER | NAND_PERM_GROUP, 0);
if (result != NAND_RESULT_OK) {
return result;
}
result = NANDPrivateOpen(CNTCACHE_TMP_FILE, &info, NAND_ACCESS_WRITE);
if (result != NAND_RESULT_OK) {
return result;
}
if (NANDWrite(&info, buf, length) != length) {
result = CNTCACHE_RESULT_IO_ERROR;
}
NANDClose(&info);
if (result != NAND_RESULT_OK) {
return result;
}
return NANDPrivateMove(CNTCACHE_TMP_FILE, CNTCACHE_DIR);
}
s32 CNTCACHEAddDeleteContent(ESTitleId titleId, const char* indices) {
char buf[CNTCACHE_READ_SIZE + CNTCACHE_LINE_SIZE] ALIGN32;
u32 length;
s32 result;
if (strlen(indices) > CNTCACHE_LINE_SIZE / 2) {
return NAND_RESULT_INVALID;
}
OSLockMutex(&_CNTCACHEMutex);
result = ReadCacheFile(buf, CNTCACHE_READ_SIZE, &length);
if (result == NAND_RESULT_OK) {
strcpy(buf + length, "DeleteContent ");
length += strlen(buf + length);
length += sprintf(buf + length, "%016llx ", titleId);
strcpy(buf + length, indices);
length += strlen(buf + length);
buf[length++] = '\n';
result = WriteCacheFile(buf, length);
}
OSUnlockMutex(&_CNTCACHEMutex);
return result;
}
static char* FindLineEnd(char* str, u32 length) {
u32 i;
for (i = 0; i < length; i++) {
if (*str == '\n') {
return str;
}
str++;
}
return NULL;
}
static inline BOOL DeleteCacheFile(const char* path) {
if (NANDPrivateDelete(path) != NAND_RESULT_OK) {
return FALSE;
}
return TRUE;
}
s32 CNTCACHEClear(void) {
NANDFileInfo info;
char* command;
s32 result;
BOOL locked = FALSE;
BOOL opened = FALSE;
u32 fileLength;
u32 offset;
s32 readLength;
char* line;
char* lineEnd;
u32 lineLength;
u8 buf[CNTCACHE_READ_SIZE] ALIGN32;
OSLockMutex(&_CNTCACHEMutex);
locked = TRUE;
result = NANDPrivateOpen(CNTCACHE_FILE, &info, NAND_ACCESS_RW);
if (result == NAND_RESULT_NOEXISTS) {
result = NAND_RESULT_OK;
goto end;
}
switch (result) {
case NAND_RESULT_OK:
opened = TRUE;
break;
default:
goto close;
}
result = NANDGetLength(&info, &fileLength);
switch (result) {
case NAND_RESULT_OK:
break;
default:
goto close;
}
offset = 0;
while (fileLength != 0) {
readLength = fileLength > sizeof(buf) ? sizeof(buf) : fileLength;
line = (char*)buf;
result = NANDRead(&info, buf, OSRoundUp32B(readLength));
if (result != readLength) {
result = CNTCACHE_RESULT_IO_ERROR;
goto close;
}
result = NAND_RESULT_OK;
lineEnd = FindLineEnd(line, readLength);
if (!lineEnd) {
result = NAND_RESULT_OK;
goto close;
}
while (readLength > 0) {
*lineEnd = '\0';
lineLength = lineEnd - line;
command = strtok(line, " \n");
if (command) {
if (strcmp(command, "DeleteTitle") == 0) {
_CNTCACHEDeleteTitle();
} else if (strcmp(command, "DeleteContent") == 0) {
_CNTCACHEDeleteContent();
}
}
lineLength++;
line += lineLength;
fileLength -= lineLength;
readLength -= lineLength;
offset += lineLength;
lineEnd = FindLineEnd(line, readLength);
if (!lineEnd) {
break;
}
}
if (fileLength != 0) {
result = NANDSeek(&info, offset, NAND_SEEK_BEG);
if (result != offset) {
result = CNTCACHE_RESULT_IO_ERROR;
goto close;
}
result = NAND_RESULT_OK;
}
}
close:
NANDClose(&info);
opened = FALSE;
DeleteCacheFile(CNTCACHE_FILE);
DeleteCacheFile(CNTCACHE_TMP_FILE);
end:
if (opened) {
NANDClose(&info);
}
if (locked) {
OSUnlockMutex(&_CNTCACHEMutex);
}
return result;
}
void _CNTCACHEDeleteTitle() {
char* token = strtok(NULL, scCntCacheSpaceNl);
char* token;
while (token != NULL) {
for (token = strtok(NULL, " \n"); token != NULL; token = strtok(NULL, " \n")) {
ESTitleId titleId;
int removable;
errno = 0;
titleId = strtoull(token, NULL, 16);
if (errno == 0 && (u32)ES_TITLE_TYPE(titleId) != 1) {
removable = _CNTCACHEIsTitleRemovable(titleId);
if (removable == 1) {
ES_DeleteTitle(titleId);
} else if (removable == 0) {
ES_DeleteTitleContent(titleId);
}
if (errno != 0 || (u32)ES_TITLE_TYPE(titleId) == 1) {
continue;
}
removable = _CNTCACHEIsTitleRemovable(titleId);
if (removable == 1) {
ES_DeleteTitle(titleId);
} else if (removable == 0) {
ES_DeleteTitleContent(titleId);
}
token = strtok(NULL, scCntCacheSpaceNl);
}
}
@@ -267,7 +292,7 @@ static s32 GetSaveDataUsage(ESTitleId titleId) {
u32 usedBlocks = 1;
u32 usedINodes = 1;
snprintf(nandPath, (int)sizeof(nandPath), scCntCacheTitleDataFmt, NANDTitleIdHi(titleId), NANDTitleIdLo(titleId));
snprintf(nandPath, (int)sizeof(nandPath), "/title/%08x/%08x/data", NANDTitleIdHi(titleId), NANDTitleIdLo(titleId));
ret = NANDSecretGetUsage(nandPath, &usedBlocks, &usedINodes);
if (ret == NAND_RESULT_NOEXISTS) {
@@ -322,7 +347,7 @@ void _CNTCACHEDeleteContent() {
ESError result;
char* token;
token = strtok(NULL, scCntCacheSpaceNl);
token = strtok(NULL, " \n");
errno = 0;
titleId = strtoull(token, NULL, 16);
if (errno == 0 && NANDTitleIdHi(titleId) == 0x00010005) {
@@ -333,7 +358,7 @@ void _CNTCACHEDeleteContent() {
}
if (result == ES_ERR_OK && ES_GetTmdView(titleId, tmd, &size) == ES_ERR_OK) {
if ((tmd->head.titleType & 8) && (tmd->head.titleType & 0x10)) {
token = strtok(NULL, scCntCacheSpaceNl);
token = strtok(NULL, " \n");
while (token) {
u32 index;
u32 i;
@@ -353,7 +378,7 @@ void _CNTCACHEDeleteContent() {
}
}
}
token = strtok(NULL, scCntCacheSpaceNl);
token = strtok(NULL, " \n");
}
}
memset(buf, 0, OSRoundUp32B(size));

View File

@@ -43,7 +43,7 @@ CXStreamingResult CXReadUncompRL(CXUncompContextRL* context, const void* src, u3
const u8* pSrc = src;
if (context->hdrLen) {
int a;
int headerBytes;
if (context->hdrLen == 8) {
if ((*pSrc & CX_COMPRESSION_TYPE_MASK) != CX_COMPRESSION_TYPE_RUN_LENGTH) {
return CX_STREAMING_ERR_BAD_FILE_TYPE;
@@ -54,10 +54,10 @@ CXStreamingResult CXReadUncompRL(CXUncompContextRL* context, const void* src, u3
}
}
a = CXiReadHeader(&context->hdrLen, &context->outDataLen, pSrc, size, context->size);
headerBytes = CXiReadHeader(&context->hdrLen, &context->outDataLen, pSrc, size, context->size);
pSrc += a;
size -= a;
pSrc += headerBytes;
size -= headerBytes;
if (!size) {
return !context->hdrLen ? context->outDataLen : CX_STREAMING_ERR_BAD_FILE_TYPE;
@@ -78,11 +78,11 @@ CXStreamingResult CXReadUncompRL(CXUncompContextRL* context, const void* src, u3
}
}
} else if (context->length) {
u8 b = *pSrc++;
u8 repeatedByte = *pSrc++;
size--;
while (context->length) {
*context->outData++ = b;
*context->outData++ = repeatedByte;
context->length--;
context->outDataLen--;
@@ -161,7 +161,7 @@ CXStreamingResult CXReadUncompLZ(CXUncompContextLZ* context, const void* src, u3
const u8* pSrc = src;
if (context->hdrLen) {
int a;
int headerBytes;
if (context->hdrLen == 8) {
if ((*pSrc & CX_COMPRESSION_TYPE_MASK) != CX_COMPRESSION_TYPE_LZ) {
return CX_STREAMING_ERR_BAD_FILE_TYPE;
@@ -174,10 +174,10 @@ CXStreamingResult CXReadUncompLZ(CXUncompContextLZ* context, const void* src, u3
}
}
a = CXiReadHeader(&context->hdrLen, &context->outDataLen, pSrc, size, context->size);
headerBytes = CXiReadHeader(&context->hdrLen, &context->outDataLen, pSrc, size, context->size);
pSrc += a;
size -= a;
pSrc += headerBytes;
size -= headerBytes;
if (!size) {
return !context->hdrLen ? context->outDataLen : CX_STREAMING_ERR_BAD_FILE_TYPE;
@@ -186,7 +186,7 @@ CXStreamingResult CXReadUncompLZ(CXUncompContextLZ* context, const void* src, u3
while (context->outDataLen > 0) {
while (context->flagsLeft) {
s32 a;
s32 backReferenceDistance;
if (!size) {
return context->outDataLen;
@@ -197,76 +197,73 @@ CXStreamingResult CXReadUncompLZ(CXUncompContextLZ* context, const void* src, u3
context->outDataLen--;
size--;
} else {
while (context->lengthBytesLeft) {
context->lengthBytesLeft--;
goto there;
}
if (!context->lzType) {
context->length = *pSrc++;
context->length += 0x30;
context->lengthBytesLeft = 0;
} else {
switch (context->lengthBytesLeft) {
case 2: {
context->length = *pSrc++;
while (context->lengthBytesLeft) {
context->lengthBytesLeft--;
if (context->length >> 4 == 1) {
context->length = (context->length & 0x0F) << 16;
context->length += 0x1110;
} else if (context->length >> 4 == 0) {
context->length = (context->length & 0x0F) << 8;
context->length += 0x110;
context->lengthBytesLeft = 1;
} else {
context->length += 0x10;
context->lengthBytesLeft = 0;
}
if (!context->lzType) {
context->length = *pSrc++;
context->length += 0x30;
context->lengthBytesLeft = 0;
} else {
switch (context->lengthBytesLeft) {
case 2: {
context->length = *pSrc++;
if (context->length >> 4 == 1) {
context->length = (context->length & 0x0F) << 16;
context->length += 0x1110;
} else if (context->length >> 4 == 0) {
context->length = (context->length & 0x0F) << 8;
context->length += 0x110;
context->lengthBytesLeft = 1;
} else {
context->length += 0x10;
context->lengthBytesLeft = 0;
break;
}
case 1: {
context->length += *pSrc++ << 8;
break;
}
case 0: {
context->length += *pSrc++;
break;
}
}
}
break;
}
case 1: {
context->length += *pSrc++ << 8;
break;
}
case 0: {
context->length += *pSrc++;
break;
}
size--;
if (!size) {
return context->outDataLen;
}
}
backReferenceDistance = (context->length & 0x0F) << 8;
context->length >>= 4;
backReferenceDistance = (backReferenceDistance | *pSrc++) + 1;
size--;
if (!size) {
return context->outDataLen;
context->lengthBytesLeft = 3;
if (context->length > context->outDataLen) {
if (!context->size) {
return CX_STREAMING_ERR_BAD_FILE_SIZE;
}
context->length = context->outDataLen;
}
while (context->length > 0) {
*context->outData = context->outData[-backReferenceDistance];
context->outData++;
context->outDataLen--;
context->length--;
}
}
a = (context->length & 0x0F) << 8;
context->length >>= 4;
a = (a | *pSrc++) + 1;
size--;
context->lengthBytesLeft = 3;
if (context->length > context->outDataLen) {
if (!context->size) {
return CX_STREAMING_ERR_BAD_FILE_SIZE;
}
context->length = context->outDataLen;
}
while (context->length > 0) {
*context->outData = context->outData[-a];
context->outData++;
context->outDataLen--;
context->length--;
}
there:
if (!context->outDataLen) {
goto out;
}
@@ -295,7 +292,7 @@ CXStreamingResult CXReadUncompHuffman(CXUncompContextHuffman* context, const voi
const u8* pSrc = src;
if (context->hdrLen) {
int a;
int headerBytes;
if (context->hdrLen == 8) {
context->depth = *pSrc & 0x0F;
@@ -308,10 +305,10 @@ CXStreamingResult CXReadUncompHuffman(CXUncompContextHuffman* context, const voi
}
}
a = CXiReadHeader(&context->hdrLen, &context->outDataLen, pSrc, size, context->size);
headerBytes = CXiReadHeader(&context->hdrLen, &context->outDataLen, pSrc, size, context->size);
pSrc += a;
size -= a;
pSrc += headerBytes;
size -= headerBytes;
if (!size) {
return !context->hdrLen ? context->outDataLen : CX_STREAMING_ERR_BAD_FILE_TYPE;

View File

@@ -5,6 +5,8 @@
#include <private/es.h>
#include <stddef.h>
static IOSFd __esFd = -1;
#define DECLARE_ES_WORK u8 __esWork[256] ALIGN32
@@ -13,7 +15,6 @@ static IOSFd __esFd = -1;
#define IS_ALIGNED(x) (((u32)(x) & 31) == 0)
#define IS_ALIGNED64(x) (((u32)(x) & 63) == 0)
// Di means something. DVD Interface????
enum {
ES_IOCTLV_IMPORT_TICKET = 1,
ES_IOCTLV_IMPORT_TITLE_0 = 2,
@@ -77,14 +78,12 @@ enum {
ESError ES_InitLib() {
ESError ret = ES_ERR_OK;
// Already initialized? Get out.
if (__esFd >= 0) {
goto out;
}
__esFd = IOS_Open("/dev/es", 0);
// Failed? Return error code
if (__esFd < ES_ERR_OK) {
ret = __esFd;
}
@@ -98,6 +97,7 @@ ESError ES_ImportTicket(ESTicket* ticket, void* certs, u32 certSize, void* crls,
IOSIoVector* vec = (IOSIoVector*)AT_ES_WORK(0xD0);
/* MWCC needs the initial success value to preserve validation branch layout. */
ESError ret = ES_ERR_OK;
if (ticket == NULL || certs == NULL || certSize == 0) {
@@ -126,11 +126,10 @@ ESError ES_ImportTicket(ESTicket* ticket, void* certs, u32 certSize, void* crls,
if (transferMode == 0) {
ret = IOS_Ioctlv(__esFd, ES_IOCTLV_IMPORT_TICKET, 3, 0, vec);
goto out;
} else {
ret = ES_ERR_INVALID_UNKNOWN;
}
ret = ES_ERR_INVALID_UNKNOWN;
out:
return ret;
}
@@ -141,6 +140,7 @@ ESError ES_ImportBoot(ESTicket* ticket, void* certs, u32 certSize, void* tmd, u3
IOSIoVector* vec = (IOSIoVector*)AT_ES_WORK(0xD0);
/* MWCC needs the initial success value to preserve validation branch layout. */
ESError ret = ES_ERR_OK;
if (ticket == NULL || certs == NULL || certSize == 0 || tmd == NULL || tmdSize == 0 || tmdCerts == NULL || tmdCertSize == 0 || app == NULL ||
@@ -191,7 +191,7 @@ ESError ES_GetTmdSize(ESTitleMeta* tmd, u32* tmdSize) {
goto out;
}
*tmdSize = tmd->head.numContents * 0x24 + 0x1E4 /* todo: figure these out. */;
*tmdSize = tmd->head.numContents * sizeof(ESContentMeta) + offsetof(ESTitleMeta, contents);
out:
return ret;
@@ -205,7 +205,7 @@ ESError ES_GetTmdSizeFromView(ESTmdView* tmd, u32* tmdSize) {
goto out;
}
*tmdSize = tmd->head.numContents * 0x24 + 0x1E4 /* todo: figure these out. */;
*tmdSize = tmd->head.numContents * sizeof(ESContentMeta) + offsetof(ESTitleMeta, contents);
out:
return ret;

View File

@@ -223,7 +223,6 @@ static s32 fa_nanddrv_VerifyBPB(u8* buf, u32* clusters) {
if (total < 65525) { result = PDM_FAT_16; }
return result;
}
#pragma dont_inline on
static s32 fa_nanddrv_BuildUpFSInfoSector(u8* buf) {
pf_memset(buf, 0, 512);
if ((u32)&buf[0] & 3) { buf[0] = 0x52; buf[1] = 0x52; buf[2] = 0x61; buf[3] = 0x41; }
@@ -238,7 +237,6 @@ static s32 fa_nanddrv_BuildUpFSInfoSector(u8* buf) {
else { *(u32*)&buf[508] = 0x000055AA; }
return 0;
}
#pragma dont_inline reset
static s32 fa_nanddrv_BuildUpBootSector(NAND_DISK_INFO* info, u8* buf, PDM_FAT_TYPE* type, u32 clusters) {
u32 total;
u32 fat_sectors;

View File

@@ -40,7 +40,6 @@ extern pf_s32 PFDRV_lread(PF_VOLUME* p_vol, pf_u8* buffer, pf_u32 sector, pf_u32
extern pf_s32 PFDRV_lwrite(PF_VOLUME* p_vol, const pf_u8* buffer, pf_u32 sector, pf_u32 num_sector, pf_u32* p_num_success);
pf_s32 PFCACHE_FlushAllCaches(PF_VOLUME* p_vol);
#pragma dont_inline on
pf_s32 PFCACHE_InitPageList(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_head, PF_CACHE_PAGE* pages, PF_CACHE_BUFFER* buffers, pf_u32 num,
pf_u32 size, pf_bool is_fat) {
pf_u32 i;
@@ -122,9 +121,6 @@ pf_s32 PFCACHE_InitPageList(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_head, PF_CACHE_
return 0;
}
#pragma dont_inline reset
#pragma dont_inline on
PF_CACHE_PAGE* PFCACHE_SearchForPage(PF_VOLUME* p_vol, PF_CACHE_PAGE* p_head, pf_u32 sector) {
PF_CACHE_PAGE* p_page;
if (sector == 0xFFFFFFFF) {
@@ -149,9 +145,6 @@ PF_CACHE_PAGE* PFCACHE_SearchForPage(PF_VOLUME* p_vol, PF_CACHE_PAGE* p_head, pf
return PF_NULL;
}
#pragma dont_inline reset
#pragma dont_inline on
pf_bool PFCACHE_SearchForFreePage(PF_CACHE_PAGE* p_head, PF_CACHE_PAGE** pp_page) {
PF_CACHE_PAGE* p_page;
for (p_page = p_head->p_prev; p_page != p_head; p_page = p_page->p_prev) {
@@ -176,9 +169,6 @@ pf_bool PFCACHE_SearchForFreePage(PF_CACHE_PAGE* p_head, PF_CACHE_PAGE** pp_page
return PF_FALSE;
}
#pragma dont_inline reset
#pragma dont_inline on
pf_s32 PFCACHE_FlushPageIfNeeded(PF_VOLUME* p_vol, PF_CACHE_PAGE* p_page) {
pf_s32 err;
pf_u32 num_success;
@@ -207,9 +197,6 @@ pf_s32 PFCACHE_FlushPageIfNeeded(PF_VOLUME* p_vol, PF_CACHE_PAGE* p_page) {
return 0;
}
#pragma dont_inline reset
#pragma dont_inline on
pf_s32 PFCACHE_DoAllocatePage(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_head, pf_u32 sector, PF_CACHE_PAGE** pp_page, pf_bool* p_is_hit) {
pf_s32 err;
*pp_page = PFCACHE_SearchForPage(p_vol, *pp_head, sector);
@@ -268,9 +255,6 @@ pf_s32 PFCACHE_DoAllocatePage(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_head, pf_u32
return 0;
}
#pragma dont_inline reset
#pragma dont_inline on
pf_s32 PFCACHE_DoReadPage(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_head, pf_u32 sector, PF_CACHE_PAGE** pp_page, pf_bool set_sig) {
pf_u32 num_success;
pf_bool is_hit;
@@ -335,9 +319,6 @@ pf_s32 PFCACHE_DoReadPage(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_head, pf_u32 sect
return 0;
}
#pragma dont_inline reset
#pragma dont_inline on
pf_s32 PFCACHE_DoReadPageAndFlushIfNeeded(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_head, pf_u32 sector, PF_CACHE_PAGE** pp_page,
pf_bool set_sig) {
pf_u32 num_success;
@@ -409,9 +390,24 @@ pf_s32 PFCACHE_DoReadPageAndFlushIfNeeded(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_h
return 0;
}
#pragma dont_inline reset
static inline PF_CACHE_PAGE* PFCACHE_NextValidPage(PF_CACHE_PAGE* page, PF_CACHE_PAGE** head) {
if (page == PF_NULL) {
page = *head;
} else {
page = page->p_next;
if (page == *head) {
return PF_NULL;
}
}
for (; (page->stat & 1) != 0; page = page->p_next) {
if (page->sector != 0xFFFFFFFF) {
page->p_buf = page->buffer;
return page;
}
}
return PF_NULL;
}
#pragma dont_inline on
pf_s32 PFCACHE_DoReadNumSector(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_head, pf_u8* p_buf, pf_u32 sector, pf_u32 num_sector,
pf_u32* p_num_success) {
PF_CACHE_PAGE* p_page;
@@ -427,23 +423,7 @@ pf_s32 PFCACHE_DoReadNumSector(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_head, pf_u8*
num_rest_sector = *p_num_success;
num_success_sector = *p_num_success;
do {
if (p_page == PF_NULL) {
p_page = *pp_head;
} else {
p_page = p_page->p_next;
if (p_page == *pp_head) {
p_page = PF_NULL;
goto found_page;
}
}
for (; (p_page->stat & 1) != 0; p_page = p_page->p_next) {
if (p_page->sector != 0xFFFFFFFF) {
p_page->p_buf = p_page->buffer;
goto found_page;
}
}
p_page = PF_NULL;
found_page:
p_page = PFCACHE_NextValidPage(p_page, pp_head);
if (p_page != PF_NULL && p_page->sector != 0xFFFFFFFF) {
if (p_page->sector <= sector && p_page->sector + p_page->size >= sector + num_success_sector) {
pf_memcpy(p_buf, &p_page->buffer[(sector - p_page->sector) << p_vol->bpb.log2_bytes_per_sector],
@@ -472,9 +452,6 @@ pf_s32 PFCACHE_DoReadNumSector(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_head, pf_u8*
return 0;
}
#pragma dont_inline reset
#pragma dont_inline on
pf_s32 PFCACHE_DoWritePage(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_head, PF_CACHE_PAGE* p_page, pf_bool set_sig) {
pf_s32 err;
if (p_page != *pp_head) {
@@ -513,9 +490,6 @@ pf_s32 PFCACHE_DoWritePage(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_head, PF_CACHE_P
return 0;
}
#pragma dont_inline reset
#pragma dont_inline on
pf_s32 PFCACHE_DoWriteSector(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_head, const pf_u8* p_buf, pf_u32 sector) {
PF_CACHE_PAGE* p_page;
pf_u32 num_success;
@@ -548,8 +522,6 @@ pf_s32 PFCACHE_DoWriteSector(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_head, const pf
return 0;
}
#pragma dont_inline reset
pf_s32 PFCACHE_DoWriteNumSectorAndFreeIfNeeded(PF_VOLUME* p_vol, PF_CACHE_PAGE** pp_head, const pf_u8* p_buf, pf_u32 sector,
pf_u32 num_sector, pf_u32* p_num_success) {
PF_CACHE_PAGE* p_page = PF_NULL;
@@ -559,23 +531,7 @@ pf_s32 PFCACHE_DoWriteNumSectorAndFreeIfNeeded(PF_VOLUME* p_vol, PF_CACHE_PAGE**
pf_u8* p_ebuf;
*p_num_success = 0;
do {
if (p_page == PF_NULL) {
p_page = *pp_head;
} else {
p_page = p_page->p_next;
if (p_page == *pp_head) {
p_page = PF_NULL;
goto found_page;
}
}
for (; (p_page->stat & 1) != 0; p_page = p_page->p_next) {
if (p_page->sector != 0xFFFFFFFF) {
p_page->p_buf = p_page->buffer;
goto found_page;
}
}
p_page = PF_NULL;
found_page:
p_page = PFCACHE_NextValidPage(p_page, pp_head);
if (p_page != PF_NULL && p_page->sector != 0xFFFFFFFF) {
if (p_page->sector <= sector && (p_page->sector + p_page->size) >= (sector + num_sector)) {
pf_memcpy(&p_page->buffer[(sector - p_page->sector) << p_vol->bpb.log2_bytes_per_sector], (pf_u8*)p_buf,
@@ -638,9 +594,6 @@ pf_s32 PFCACHE_DoWriteNumSectorAndFreeIfNeeded(PF_VOLUME* p_vol, PF_CACHE_PAGE**
return 0;
}
#pragma dont_inline reset
#pragma dont_inline on
pf_s32 PFCACHE_DoFlushCache(PF_VOLUME* p_vol, PF_CACHE_PAGE* p_head) {
PF_CACHE_PAGE* p_page;
pf_s32 err;
@@ -666,8 +619,6 @@ pf_s32 PFCACHE_DoFlushCache(PF_VOLUME* p_vol, PF_CACHE_PAGE* p_head) {
return first_err;
}
#pragma dont_inline reset
void PFCACHE_SetCache(PF_VOLUME* p_vol, PF_CACHE_PAGE* p_cache_page, PF_CACHE_BUFFER* p_cache_buf, pf_u16 num_fat_pages, pf_u16 num_data_pages) {
p_vol->cache.pages = p_cache_page;
p_vol->cache.buffers = p_cache_buf;

View File

@@ -297,11 +297,9 @@ pf_s32 PFDIR_p_opendir(PF_VOLUME* volume, PFDIR_STR* path, PFDIR_DIR** opened_di
if (error != 0) {
return error;
}
goto open_directory;
} else if (PFSTR_StrNumChar(path, 1) == 2 &&
PFSTR_StrNCmp(path, (const pf_s8*)":", 1, 1, 1) == 0) {
error = PFVOL_GetCurrentDir(volume, &entry);
goto open_directory;
} else if (PFSTR_StrNumChar(path, 1) == 3 &&
PFSTR_StrNCmp(path, (const pf_s8*)":", 1, 1, 1) == 0 &&
(PFSTR_StrNCmp(path, (const pf_s8*)"\\", 1, 2, 1) == 0 ||
@@ -310,7 +308,6 @@ pf_s32 PFDIR_p_opendir(PF_VOLUME* volume, PFDIR_STR* path, PFDIR_DIR** opened_di
if (error != 0) {
return error;
}
goto open_directory;
} else {
if (PFSTR_StrNCmp(path, (const pf_s8*)":", 1, 1, 1) == 0 &&
(PFSTR_StrNCmp(path, (const pf_s8*)"\\", 1, 2, 1) == 0 ||
@@ -326,7 +323,6 @@ pf_s32 PFDIR_p_opendir(PF_VOLUME* volume, PFDIR_STR* path, PFDIR_DIR** opened_di
}
}
open_directory:
sdd = PFDIR_GetSDD(volume, &entry);
if (sdd == 0) {
return 0x15;
@@ -1567,10 +1563,9 @@ pf_s32 PFDIR_p_fsexec(PF_DTA* data, pf_u32 flags, pf_u32 mode) {
} else {
if ((flags & 0x20) != 0) { error = PFDIR_p_fsexec_opendir(data, &entry, &iter, flags); }
}
goto done;
} else {
return 10;
}
return 10;
done:
return error;
}

View File

@@ -119,7 +119,6 @@ pf_s32 PFENT_ITER_Advance(PFITER_ENT_ITER*, pf_u32);
pf_s32 PFENT_ITER_Retreat(PFITER_ENT_ITER*, pf_u32);
pf_s32 PFENT_ITER_FindDirEntryFromCluster(PFITER_ENT_ITER*, PF_DIR_ENT*, pf_u32, pf_bool*);
#pragma dont_inline on
pf_s32 PFENT_RecalcEntryIterator(PFITER_ENT_ITER* p_iter, pf_u32 may_allocate) {
pf_u32 file_sector_index;
pf_u32 previous_fsindex;
@@ -160,7 +159,6 @@ pf_s32 PFENT_RecalcEntryIterator(PFITER_ENT_ITER* p_iter, pf_u32 may_allocate) {
p_iter->offset = (p_iter->index & p_iter->offset_mask) * 32;
return 0;
}
#pragma dont_inline reset
static inline pf_s32 PFENT_ITER_LoadEntry(PFITER_ENT_ITER* p_iter) {
pf_u32 success_size;
@@ -271,60 +269,60 @@ pf_s32 PFENT_ITER_DoFindEntry(PFITER_ENT_ITER* p_iter, PF_DIR_ENT* p_ent, PF_STR
*p_is_found = 1;
return 0;
}
goto finish;
break;
}
}
for (; !PFENT_ITER_IsAtLogicalEnd(p_iter); err = AdvanceIterator(p_iter, 0)) {
pf_s32 attr;
if (err != 0) return err;
if (p_iter->buf[0] == 0) break;
if (p_iter->buf[0] == 0xe5) {
p_ent->num_entry_LFNs = 0;
p_ent->long_name[0] = 0;
continue;
}
attr = p_iter->buf[11];
if ((attr & 15) == 15) {
if (PFENT_LoadLFNEntryFieldsFromBuf(p_ent, p_iter->buf) != 0) {
} else {
for (; !PFENT_ITER_IsAtLogicalEnd(p_iter); err = AdvanceIterator(p_iter, 0)) {
pf_s32 attr;
if (err != 0) return err;
if (p_iter->buf[0] == 0) break;
if (p_iter->buf[0] == 0xe5) {
p_ent->num_entry_LFNs = 0;
p_ent->long_name[0] = 0;
continue;
}
attr = p_iter->buf[11];
if ((attr & 15) == 15) {
if (PFENT_LoadLFNEntryFieldsFromBuf(p_ent, p_iter->buf) != 0) {
p_ent->num_entry_LFNs = 0;
p_ent->long_name[0] = 0;
}
continue;
}
if (attr == 0) attr = 0x40;
if (attr_required & 0x80) {
attr_required &= 0x7f;
attr_forbidden &= 0x7f;
if ((attr_required && (pf_s32)(attr_required & attr) != (pf_s32)attr_required) ||
(attr_forbidden && (pf_s32)(attr_forbidden & attr) == (pf_s32)attr_forbidden)) err = -1;
} else if ((pf_u8)attr_required != 0x7f && (pf_u32)attr != (pf_u8)attr_required &&
(!(attr & (pf_u8)attr_required) || (attr & (pf_u8)attr_forbidden))) err = -1;
if (err == -1) {
p_ent->num_entry_LFNs = 0;
p_ent->long_name[0] = 0;
continue;
}
if (attr & 8) {
p_ent->num_entry_LFNs = 0;
p_ent->long_name[0] = 0;
}
continue;
}
if (attr == 0) attr = 0x40;
if (attr_required & 0x80) {
attr_required &= 0x7f;
attr_forbidden &= 0x7f;
if ((attr_required && (pf_s32)(attr_required & attr) != (pf_s32)attr_required) ||
(attr_forbidden && (pf_s32)(attr_forbidden & attr) == (pf_s32)attr_forbidden)) err = -1;
} else if ((pf_u8)attr_required != 0x7f && (pf_u32)attr != (pf_u8)attr_required &&
(!(attr & (pf_u8)attr_required) || (attr & (pf_u8)attr_forbidden))) err = -1;
if (err == -1) {
p_ent->num_entry_LFNs = 0;
p_ent->long_name[0] = 0;
continue;
}
if (attr & 8) {
PFENT_LoadShortNameFromBuf(p_ent, p_iter->buf);
if (p_ent->num_entry_LFNs && p_ent->ordinal == 1 && p_ent->check_sum == PFENT_CalcCheckSum(p_ent) &&
PFPATH_MatchFileNameWithPattern((pf_s8*)p_ent->long_name, p_pattern, 1)) {
LoadNumericEntry(p_iter, p_ent);
*p_is_found = 1;
return 0;
}
if (PFPATH_MatchFileNameWithPattern(p_ent->short_name, p_pattern, 0)) {
if (p_iter->buf[12] & 0x18) PFENT_ITER_MakeLongFileName(p_iter, p_ent);
LoadNumericEntry(p_iter, p_ent);
*p_is_found = 1;
return 0;
}
p_ent->num_entry_LFNs = 0;
p_ent->long_name[0] = 0;
}
PFENT_LoadShortNameFromBuf(p_ent, p_iter->buf);
if (p_ent->num_entry_LFNs && p_ent->ordinal == 1 && p_ent->check_sum == PFENT_CalcCheckSum(p_ent) &&
PFPATH_MatchFileNameWithPattern((pf_s8*)p_ent->long_name, p_pattern, 1)) {
LoadNumericEntry(p_iter, p_ent);
*p_is_found = 1;
return 0;
}
if (PFPATH_MatchFileNameWithPattern(p_ent->short_name, p_pattern, 0)) {
if (p_iter->buf[12] & 0x18) PFENT_ITER_MakeLongFileName(p_iter, p_ent);
LoadNumericEntry(p_iter, p_ent);
*p_is_found = 1;
return 0;
}
p_ent->num_entry_LFNs = 0;
p_ent->long_name[0] = 0;
}
finish:
return 0;
}

View File

@@ -178,6 +178,7 @@ s32 PFFAT_ReadFATSector(PF_VOLUME* volume, PF_CACHE_PAGE* page, u32 cluster)
} else {
currentFAT = 1;
}
// MWCC needs both retry paths to reach the shared error test.
for (;;) {
error = PFSEC_ReadFAT(volume, page->p_buf, page->sector, 0,
volume->bpb.bytes_per_sector);

View File

@@ -129,10 +129,11 @@ pf_s32 PFFAT16_ReadFATEntryWithBuf(PF_VOLUME* p_vol, pf_u32 cluster, pf_u32* p_v
VFiPFSEC_WriteFAT(p_vol, p_page->p_buf, p_page->sector + fat * p_vol->bpb.sectors_per_FAT, 0, p_vol->bpb.bytes_per_sector);
}
}
// MWCC needs the shared read-result block to preserve the retry branches.
do {
err = VFiPFSEC_ReadFAT(p_vol, p_page->p_buf, sector, 0, p_vol->bpb.bytes_per_sector);
if (err != 0x1000 || p_vol->p_callback == PF_NULL) {
goto block_22;
goto check_read_result;
}
result = ((PF_VOLUME_CB)p_vol->p_callback)(p_vol->last_driver_error);
if (result != 0) {
@@ -140,11 +141,11 @@ pf_s32 PFFAT16_ReadFATEntryWithBuf(PF_VOLUME* p_vol, pf_u32 cluster, pf_u32* p_v
current_fat++;
sector += p_vol->bpb.sectors_per_FAT;
} else {
goto block_22;
goto check_read_result;
}
}
continue;
block_22:
check_read_result:
if (err != 0) {
return err;
}

View File

@@ -139,10 +139,11 @@ pf_s32 PFFAT32_ReadFATEntryWithBuf(PF_VOLUME* p_vol, pf_u32 cluster, pf_u32* p_v
VFiPFSEC_WriteFAT(p_vol, p_page->p_buf, p_page->sector + fat * p_vol->bpb.sectors_per_FAT, 0, p_vol->bpb.bytes_per_sector);
}
}
// MWCC needs the shared read-result block to preserve the retry branches.
do {
err = VFiPFSEC_ReadFAT(p_vol, p_page->p_buf, sector, 0, p_vol->bpb.bytes_per_sector);
if (err != 0x1000 || p_vol->p_callback == PF_NULL) {
goto block_22;
goto check_read_result;
}
result = ((PF_VOLUME_CB)p_vol->p_callback)(p_vol->last_driver_error);
if (result != 0) {
@@ -150,11 +151,11 @@ pf_s32 PFFAT32_ReadFATEntryWithBuf(PF_VOLUME* p_vol, pf_u32 cluster, pf_u32* p_v
current_fat++;
sector += p_vol->bpb.sectors_per_FAT;
} else {
goto block_22;
goto check_read_result;
}
}
continue;
block_22:
check_read_result:
if (err != 0) {
return err;
}

View File

@@ -1346,22 +1346,21 @@ pf_s32 PFFILE_p_flock(PFFILE_FILE* file, pf_u32 mode) {
}
file->p_sfd->lock.count++;
file->lock_count++;
goto complete;
} else {
if (file->lock_count == 0 || file->p_sfd->lock.count == 0) {
return 0x27;
}
if ((file->p_sfd->lock.mode & 2) != 0 && file->p_sfd->lock.owner != (PF_FILE*)file) {
return 0x27;
}
file->lock_count--;
file->p_sfd->lock.count--;
if (file->p_sfd->lock.count == 0) {
PF_UnLockFile((PF_FILE*)file);
if ((file->p_sfd->lock.mode & 2) != 0) { file->p_sfd->lock.owner = 0; }
file->p_sfd->lock.mode &= ~3;
}
}
if (file->lock_count == 0 || file->p_sfd->lock.count == 0) {
return 0x27;
}
if ((file->p_sfd->lock.mode & 2) != 0 && file->p_sfd->lock.owner != (PF_FILE*)file) {
return 0x27;
}
file->lock_count--;
file->p_sfd->lock.count--;
if (file->p_sfd->lock.count == 0) {
PF_UnLockFile((PF_FILE*)file);
if ((file->p_sfd->lock.mode & 2) != 0) { file->p_sfd->lock.owner = 0; }
file->p_sfd->lock.mode &= ~3;
}
complete:
return 0;
}

View File

@@ -59,13 +59,13 @@ typedef struct FS_Callback {
u8 ioBuf[0x100] ALIGN32; // 0x00
ISFSCallback callback; // 0x100
void* callbackArg; // 0x104
u32 func; // 0x108
u32 operation; // 0x108
union {
ISFSStats* stats;
ISFSFileStats* fstats;
ISFSFileStats* fileStats;
u32* num;
u32* numEntries;
FS_GetAttr getAttr;
FS_GetUsage getUsage;
@@ -88,7 +88,7 @@ ISFSError ISFS_OpenLib() {
static void* lo = NULL;
static void* hi = NULL;
FS_Callback* __fsCtxt = NULL;
FS_Callback* heapBase = NULL;
if (!__fsInitialized) {
lo = IPCGetBufferLo();
@@ -110,20 +110,20 @@ ISFSError ISFS_OpenLib() {
goto out;
}
__fsCtxt = (FS_Callback*)__devfs;
heapBase = (FS_Callback*)__devfs;
if (!__fsInitialized && ((u32)__fsCtxt + FS_HEAP_SIZE) > (u32)hi) {
if (!__fsInitialized && ((u32)heapBase + FS_HEAP_SIZE) > (u32)hi) {
OSReport("APP ERROR: Not enough IPC arena\n");
ret = IPC_RESULT_ALLOC_FAILED;
goto out;
}
if (!__fsInitialized) {
IPCSetBufferLo((void*)((u32)__fsCtxt + FS_HEAP_SIZE));
IPCSetBufferLo((void*)((u32)heapBase + FS_HEAP_SIZE));
__fsInitialized = TRUE;
}
hId = iosCreateHeap(__fsCtxt, FS_HEAP_SIZE);
hId = iosCreateHeap(heapBase, FS_HEAP_SIZE);
if (hId < 0) {
ret = IPC_RESULT_ALLOC_FAILED;
@@ -174,7 +174,7 @@ static IOSError _FSReadDirCb(IOSError result, void* isfsCallbackArg) {
IOSIoVector* vec = (IOSIoVector*)_context->ioBuf;
ptr = (u8*)OSRoundUp32B((u8*)&vec[4]);
ptr = (u8*)OSRoundUp32B(ptr + FS_MAX_PATH);
*_context->args.num = *(u32*)ptr;
*_context->args.numEntries = *(u32*)ptr;
}
return ISFS_ERROR_OK;
@@ -216,7 +216,7 @@ static IOSError _FSGetFileStatsCb(IOSError result, void* isfsCallbackArg) {
FS_Callback* _context = (FS_Callback*)isfsCallbackArg;
if (result == IPC_RESULT_OK) {
memcpy(_context->args.fstats, _context->ioBuf, sizeof(*_context->args.fstats));
memcpy(_context->args.fileStats, _context->ioBuf, sizeof(*_context->args.fileStats));
}
return IPC_RESULT_OK;
@@ -227,7 +227,7 @@ IOSError _isfsFuncCb(IOSError result, void* isfsCallbackArg) {
ISFSError ret = result;
if (ret >= IPC_RESULT_OK) {
switch (_context->func) {
switch (_context->operation) {
case ISFS_CB_STATE_GET_STATS: {
_FSGetStatsCb(result, isfsCallbackArg);
break;
@@ -358,7 +358,7 @@ ISFSError ISFS_CreateDirAsync(const char* dirName, u32 dirAttr, u32 ownerAcc, u3
isfsCallbackArg->callback = callback;
isfsCallbackArg->callbackArg = callbackArg;
isfsCallbackArg->func = ISFS_CB_STATE_NONE;
isfsCallbackArg->operation = ISFS_CB_STATE_NONE;
pathAttrArgs = (ISFSPathAttrArgs*)isfsCallbackArg->ioBuf;
memcpy(pathAttrArgs->path, dirName, len + 1);
@@ -458,8 +458,8 @@ ISFSError ISFS_ReadDirAsync(const char* dirName, char* nameList, u32* num, ISFSC
isfsCallbackArg->callback = callback;
isfsCallbackArg->callbackArg = callbackArg;
isfsCallbackArg->func = ISFS_CB_STATE_READ_DIR;
isfsCallbackArg->args.num = num;
isfsCallbackArg->operation = ISFS_CB_STATE_READ_DIR;
isfsCallbackArg->args.numEntries = num;
vec = (IOSIoVector*)isfsCallbackArg->ioBuf;
@@ -556,7 +556,7 @@ ISFSError ISFS_SetAttrAsync(const char* fileName, u32 ownerId, u16 groupId, u32
isfsCallbackArg->callback = callback;
isfsCallbackArg->callbackArg = callbackArg;
isfsCallbackArg->func = ISFS_CB_STATE_NONE;
isfsCallbackArg->operation = ISFS_CB_STATE_NONE;
pathAttrArgs = (ISFSPathAttrArgs*)isfsCallbackArg->ioBuf;
memcpy(pathAttrArgs->path, fileName, len + 1);
@@ -646,7 +646,7 @@ ISFSError ISFS_GetAttrAsync(const char* fileName, u32* ownerId, u16* groupId, u3
isfsCallbackArg->args.getAttr.othersAcc = othersAcc;
isfsCallbackArg->callback = callback;
isfsCallbackArg->callbackArg = callbackArg;
isfsCallbackArg->func = ISFS_CB_STATE_GET_ATTR;
isfsCallbackArg->operation = ISFS_CB_STATE_GET_ATTR;
ptr = isfsCallbackArg->ioBuf;
memcpy(ptr, fileName, len + 1);
@@ -703,7 +703,7 @@ ISFSError ISFS_DeleteAsync(const char* fileName, ISFSCallback callback, void* ca
memcpy(isfsCallbackArg->ioBuf, fileName, len + 1);
isfsCallbackArg->callback = callback;
isfsCallbackArg->callbackArg = callbackArg;
isfsCallbackArg->func = ISFS_CB_STATE_NONE;
isfsCallbackArg->operation = ISFS_CB_STATE_NONE;
ret = IOS_IoctlAsync(__fsFd, ISFS_IOCTL_DELETE_PATH, isfsCallbackArg->ioBuf, FS_MAX_PATH, NULL, 0, _isfsFuncCb, isfsCallbackArg);
out:
@@ -765,7 +765,7 @@ ISFSError ISFS_RenameAsync(const char* oldName, const char* newName, ISFSCallbac
isfsCallbackArg->callback = callback;
isfsCallbackArg->callbackArg = callbackArg;
isfsCallbackArg->func = ISFS_CB_STATE_NONE;
isfsCallbackArg->operation = ISFS_CB_STATE_NONE;
pathsArgs = (ISFSPathsArgs*)isfsCallbackArg->ioBuf;
memcpy(pathsArgs->path1, oldName, oldLen + 1);
@@ -888,7 +888,7 @@ ISFSError ISFS_CreateFileAsync(const char* fileName, u32 fileAttr, u32 ownerAcc,
isfsCallbackArg->callback = callback;
isfsCallbackArg->callbackArg = callbackArg;
isfsCallbackArg->func = ISFS_CB_STATE_NONE;
isfsCallbackArg->operation = ISFS_CB_STATE_NONE;
pathAttrArgs = (ISFSPathAttrArgs*)isfsCallbackArg->ioBuf;
memcpy(pathAttrArgs->path, fileName, len + 1);
@@ -947,7 +947,7 @@ IOSFd ISFS_OpenAsync(const char* fileName, u32 access, ISFSCallback callback, vo
isfsCallbackArg->callback = callback;
isfsCallbackArg->callbackArg = callbackArg;
isfsCallbackArg->func = ISFS_CB_STATE_NONE;
isfsCallbackArg->operation = ISFS_CB_STATE_NONE;
memcpy(isfsCallbackArg->ioBuf, fileName, len + 1);
ret = IOS_OpenAsync((const char*)isfsCallbackArg->ioBuf, access, _isfsFuncCb, isfsCallbackArg);
@@ -1003,8 +1003,8 @@ ISFSError ISFS_GetFileStatsAsync(IOSFd fd, ISFSFileStats* stats, ISFSCallback ca
isfsCallbackArg->callback = callback;
isfsCallbackArg->callbackArg = callbackArg;
isfsCallbackArg->func = ISFS_CB_STATE_GET_FILE_STATS;
isfsCallbackArg->args.fstats = stats;
isfsCallbackArg->operation = ISFS_CB_STATE_GET_FILE_STATS;
isfsCallbackArg->args.fileStats = stats;
ret = IOS_IoctlAsync(fd, ISFS_IOCTL_GET_FILE_STATS, NULL, 0, isfsCallbackArg->ioBuf, sizeof(*stats), _isfsFuncCb, isfsCallbackArg);
out:
@@ -1027,7 +1027,7 @@ ISFSError ISFS_SeekAsync(IOSFd fd, s32 offset, u32 whence, ISFSCallback callback
isfsCallbackArg->callback = callback;
isfsCallbackArg->callbackArg = callbackArg;
isfsCallbackArg->func = ISFS_CB_STATE_NONE;
isfsCallbackArg->operation = ISFS_CB_STATE_NONE;
ret = IOS_SeekAsync(fd, offset, whence, _isfsFuncCb, isfsCallbackArg);
out:
@@ -1059,7 +1059,7 @@ ISFSError ISFS_ReadAsync(IOSFd fd, u8* buffer, u32 size, ISFSCallback callback,
isfsCallbackArg->callback = callback;
isfsCallbackArg->callbackArg = callbackArg;
isfsCallbackArg->func = ISFS_CB_STATE_NONE;
isfsCallbackArg->operation = ISFS_CB_STATE_NONE;
ret = IOS_ReadAsync(fd, buffer, size, _isfsFuncCb, isfsCallbackArg);
out:
@@ -1096,7 +1096,7 @@ ISFSError ISFS_WriteAsync(IOSFd fd, const char* buffer, u32 size, ISFSCallback c
isfsCallbackArg->callback = callback;
isfsCallbackArg->callbackArg = callbackArg;
isfsCallbackArg->func = ISFS_CB_STATE_NONE;
isfsCallbackArg->operation = ISFS_CB_STATE_NONE;
ret = IOS_WriteAsync(fd, (void*)buffer, size, _isfsFuncCb, isfsCallbackArg);
out:
@@ -1120,7 +1120,7 @@ ISFSError ISFS_CloseAsync(IOSFd fd, ISFSCallback callback, void* callbackArg) {
isfsCallbackArg->callback = callback;
isfsCallbackArg->callbackArg = callbackArg;
isfsCallbackArg->func = ISFS_CB_STATE_NONE;
isfsCallbackArg->operation = ISFS_CB_STATE_NONE;
ret = IOS_CloseAsync(fd, _isfsFuncCb, isfsCallbackArg);
out:
@@ -1140,7 +1140,7 @@ ISFSError ISFS_ShutdownAsync(ISFSCallback callback, void* callbackArg) {
isfsCallbackArg->callback = callback;
isfsCallbackArg->callbackArg = callbackArg;
isfsCallbackArg->func = ISFS_CB_STATE_NONE;
isfsCallbackArg->operation = ISFS_CB_STATE_NONE;
ret = IOS_IoctlAsync(__fsFd, ISFS_IOCTL_SHUTDOWN_FS, NULL, 0, NULL, 0, _isfsFuncCb, isfsCallbackArg);
out:

View File

@@ -132,7 +132,7 @@ void IpcReplyHandler(__OSInterrupt interrupt, OSContext* context) {
OSClearContext(&exceptionContext);
OSSetCurrentContext(&exceptionContext);
rep->callback(req->status, (void*)rep->callback_arg);
rep->callback(req->status, rep->callback_arg);
OSClearContext(&exceptionContext);
OSSetCurrentContext(context);
@@ -283,7 +283,7 @@ static inline IOSError __ios_Ipc1(IOSFd fd, u32 cmd, IOSIpcCb callback, void* ca
goto error;
}
*rpc = (IOSRpcRequest*)ipcAllocReq();
*rpc = ipcAllocReq();
if (*rpc == 0) {
ret = IPC_RESULT_ALLOC_FAILED;
@@ -302,7 +302,7 @@ error:
}
static IOSError __ios_Ipc2(IOSRpcRequest* rpc, IOSIpcCb callback) {
IOSError ret = IPC_RESULT_OK;
IOSError ret;
u32 inten;
IOSResourceRequest* req;
@@ -351,7 +351,7 @@ static IOSError __ios_Ipc2(IOSRpcRequest* rpc, IOSIpcCb callback) {
IOSError IOS_OpenAsync(const char* pPath, u32 flags, IOSIpcCb callback, void* callback_arg) {
IOSRpcRequest* rpc;
IOSError ret = IPC_RESULT_OK;
IOSError ret;
ret = __ios_Ipc1(0, IPC_REQ_OPEN, callback, callback_arg, &rpc);
@@ -372,7 +372,7 @@ error:
IOSError IOS_Open(const char* path, u32 flags) {
IOSRpcRequest* rpc;
IOSError ret = IPC_RESULT_OK;
IOSError ret;
ret = __ios_Ipc1(0, IPC_REQ_OPEN, NULL, NULL, &rpc);
@@ -394,7 +394,7 @@ error:
IOSError IOS_CloseAsync(IOSFd fd, IOSIpcCb callback, void* callbackArg) {
IOSRpcRequest* rpc;
IOSError ret = IPC_RESULT_OK;
IOSError ret;
ret = __ios_Ipc1(fd, IPC_REQ_CLOSE, callback, callbackArg, &rpc);
@@ -407,7 +407,7 @@ IOSError IOS_CloseAsync(IOSFd fd, IOSIpcCb callback, void* callbackArg) {
IOSError IOS_Close(IOSFd fd) {
IOSRpcRequest* rpc;
IOSError ret = IPC_RESULT_OK;
IOSError ret;
ret = __ios_Ipc1(fd, IPC_REQ_CLOSE, NULL, NULL, &rpc);
@@ -439,7 +439,7 @@ error:
IOSError IOS_ReadAsync(IOSFd fd, void* buf, u32 len, IOSIpcCb callback, void* callbackArg) {
IOSRpcRequest* rpc;
IOSError ret = IPC_RESULT_OK;
IOSError ret;
ret = __ios_Ipc1(fd, IPC_REQ_READ, callback, callbackArg, &rpc);
@@ -461,7 +461,7 @@ error:
IOSError IOS_Read(IOSFd fd, void* buf, u32 len) {
IOSRpcRequest* rpc;
IOSError ret = IPC_RESULT_OK;
IOSError ret;
ret = __ios_Ipc1(fd, IPC_REQ_READ, NULL, NULL, &rpc);
@@ -501,7 +501,7 @@ error:
IOSError IOS_WriteAsync(IOSFd fd, void* buf, u32 len, IOSIpcCb callback, void* callbackArg) {
IOSRpcRequest* rpc;
IOSError ret = IPC_RESULT_OK;
IOSError ret;
ret = __ios_Ipc1(fd, IPC_REQ_WRITE, callback, callbackArg, &rpc);
@@ -523,7 +523,7 @@ error:
IOSError IOS_Write(IOSFd fd, void* buf, u32 len) {
IOSRpcRequest* rpc;
IOSError ret = IPC_RESULT_OK;
IOSError ret;
ret = __ios_Ipc1(fd, IPC_REQ_WRITE, NULL, NULL, &rpc);
@@ -562,7 +562,7 @@ error:
IOSError IOS_SeekAsync(IOSFd fd, s32 offset, u32 whence, IOSIpcCb callback, void* callbackArg) {
IOSRpcRequest* rpc;
IOSError ret = IPC_RESULT_OK;
IOSError ret;
ret = __ios_Ipc1(fd, IPC_REQ_SEEK, callback, callbackArg, &rpc);
@@ -584,7 +584,7 @@ error:
IOSError IOS_Seek(IOSFd fd, s32 offset, u32 whence) {
IOSRpcRequest* rpc;
IOSError ret = IPC_RESULT_OK;
IOSError ret;
ret = __ios_Ipc1(fd, IPC_REQ_SEEK, NULL, NULL, &rpc);
@@ -630,7 +630,7 @@ error:
IOSError IOS_IoctlAsync(IOSFd fd, s32 cmd, void* input, u32 inputLen, void* output, u32 outputLen, IOSIpcCb callback, void* callbackArg) {
IOSRpcRequest* rpc;
IOSError ret = IPC_RESULT_OK;
IOSError ret;
ret = __ios_Ipc1(fd, IPC_REQ_IOCTL, callback, callbackArg, &rpc);
@@ -652,7 +652,7 @@ err:
IOSError IOS_Ioctl(IOSFd fd, s32 cmd, void* input, u32 inputLen, void* output, u32 outputLen) {
IOSRpcRequest* rpc;
IOSError ret = IPC_RESULT_OK;
IOSError ret;
ret = __ios_Ipc1(fd, IPC_REQ_IOCTL, NULL, NULL, &rpc);
@@ -692,7 +692,8 @@ static IOSError __ios_Ioctlv(IOSRpcRequest* rpc, s32 cmd, u32 readCount, u32 wri
v = &req->args.ioctlv;
for (i = 0, j = v->readCount; i < req->args.ioctlv.writeCount; i++) {
j = v->readCount;
for (i = 0; i < req->args.ioctlv.writeCount; i++) {
DCFlushRange(v->vector[j + i].base, v->vector[j + i].length);
v->vector[j + i].base = (v->vector[j + i].base) ? (u8*)OSCachedToPhysical(v->vector[j + i].base) : 0;
}
@@ -711,7 +712,7 @@ err:
IOSError IOS_IoctlvAsync(IOSFd fd, s32 cmd, u32 readCount, u32 writeCount, IOSIoVector* vect, IOSIpcCb callback, void* callbackArg) {
IOSRpcRequest* rpc;
IOSError ret = IPC_RESULT_OK;
IOSError ret;
ret = __ios_Ipc1(fd, IPC_REQ_IOCTLV, callback, callbackArg, &rpc);
@@ -733,7 +734,7 @@ err:
IOSError IOS_Ioctlv(IOSFd fd, s32 cmd, u32 readCount, u32 writeCount, IOSIoVector* vect) {
IOSRpcRequest* rpc;
IOSError ret = IPC_RESULT_OK;
IOSError ret;
ret = __ios_Ipc1(fd, IPC_REQ_IOCTLV, NULL, NULL, &rpc);
@@ -754,7 +755,7 @@ err:
}
IOSError IOS_IoctlvReboot(IOSFd fd, s32 cmd, u32 readCount, u32 writeCount, IOSIoVector* vect) {
IOSError ret = IPC_RESULT_OK;
IOSError ret;
u32 inten;
IOSResourceRequest* req;

View File

@@ -61,7 +61,7 @@ finish:
}
IOSError iosDestroyHeap(IOSHeapId id) {
IOSError ret = IPC_RESULT_ACCESS;
IOSError ret;
IOSHeap* h;
int enabled = OSDisableInterrupts();
@@ -126,6 +126,7 @@ static void* __iosAlloc(IOSHeapId id, u32 size, u32 alignment) {
size = OSRoundUp32B(size);
/* MWCC needs this result assignment to preserve the invalid-heap branch layout. */
if (id < 0 || id >= MAX_HEAPS || __heaps[id].base == NULL) {
ret = NULL;
goto finish;
@@ -217,6 +218,7 @@ IOSError iosFree(IOSHeapId id, void* ptr) {
goto finish;
}
/* MWCC needs this result assignment to preserve the invalid-heap branch layout. */
if (id < 0 || id >= MAX_HEAPS || __heaps[id].base == NULL) {
ret = IPC_RESULT_INVALID;
goto finish;

View File

@@ -216,7 +216,7 @@ static ISFSError nandCopy(IOSFd dest, IOSFd src, void* buffer, u32 length) {
}
}
// Force this unused function to link
// MWCC must retain this unreferenced SDK entry point in the linked image.
#pragma push
#pragma force_active on
s32 NANDSafeOpen(const char* path, NANDFileInfo* info, u8 accType, void* buffer, u32 length) {
@@ -681,4 +681,5 @@ static void nandCloseCallback(ISFSError result, void* callbackContext) {
}
// Force to align
// MWCC needs this object to preserve the data section layout.
char canYouAlignMe[] = "pretty pls?" ALIGN32;

View File

@@ -138,7 +138,7 @@ int NUP_GetStatus(void* instance, u64* status) {
OSLockMutex(&context->mutex);
if (status != 0) {
memcpy(status, &context->progress, 0x18);
memcpy(status, &context->progress, sizeof(NUPProgress));
}
s32 result = *(s32*)status;
OSUnlockMutex(&context->mutex);
@@ -428,7 +428,7 @@ static s32 __nupGetTicketViews(ESTitleId titleId, ESTicketView** ticketViews, u3
}
/* MWCC must keep this helper out of line to match its callers. */
#pragma dont_inline on
static u32 __nupSetAuditState(u8 state) NO_INLINE;
static u32 __nupSetAuditState(u8 state) {
const char* auditPath = "NUPAUDIT";
s32 result;
@@ -449,7 +449,6 @@ static u32 __nupSetAuditState(u8 state) {
}
return result;
}
#pragma dont_inline reset
static inline unsigned long __nupBase64EncodedSize(unsigned long length) {
return ((length + 2) / 3) * 4;
@@ -500,7 +499,7 @@ static s32 __nupGetAuditData(NUPContextInfo* context, char** auditData) {
u32 auditFormat = 0;
ESTicketView* ticketViews = 0;
u32 viewCount;
void* auditRecord = 0;
NUPAuditRecord* auditRecord = 0;
void* signatureCertificate = 0;
void* deviceCertificate = 0;
NUPSignedAuditData* signedData = 0;
@@ -550,25 +549,25 @@ static s32 __nupGetAuditData(NUPContextInfo* context, char** auditData) {
}
deviceInfo[0x20] = '\0';
auditRecord = nup::__nupMallocAlign(0xf8, 0x40);
auditRecord = (NUPAuditRecord*)nup::__nupMallocAlign(sizeof(NUPAuditRecord), 0x40);
if (auditRecord == 0) {
result = -5000;
} else {
memcpy(((NUPAuditRecord*)auditRecord)->deviceInfo, deviceInfo, 0x20);
memcpy(&((NUPAuditRecord*)auditRecord)->ticketView, &ticketViews[selectedIndex], sizeof(ESTicketView));
signatureCertificate = nup::__nupMallocAlign(0x180, 0x40);
memcpy(auditRecord->deviceInfo, deviceInfo, sizeof(auditRecord->deviceInfo));
memcpy(&auditRecord->ticketView, &ticketViews[selectedIndex], sizeof(ESTicketView));
signatureCertificate = nup::__nupMallocAlign(sizeof(ESCertSignature), 0x40);
if (signatureCertificate == 0) {
result = -5000;
} else {
result = ES_Sign(auditRecord, 0xf8, signature, (ESCertSignature*)signatureCertificate);
result = ES_Sign(auditRecord, sizeof(NUPAuditRecord), signature, (ESCertSignature*)signatureCertificate);
if (result == 0) {
deviceCertificate = nup::__nupMallocAlign(0x180, 0x40);
deviceCertificate = nup::__nupMallocAlign(sizeof(ESCertSignature), 0x40);
if (deviceCertificate == 0) {
result = -5000;
} else {
result = ES_GetDeviceCert(deviceCertificate);
if (result == 0) {
signedData = (NUPSignedAuditData*)nup::__nupMalloc(0x438);
signedData = (NUPSignedAuditData*)nup::__nupMalloc(sizeof(NUPSignedAuditData));
if (signedData == 0) {
result = -5000;
} else {
@@ -578,7 +577,7 @@ static s32 __nupGetAuditData(NUPContextInfo* context, char** auditData) {
auditCursor += sizeof(NUPAuditRecord);
memcpy(auditCursor, signature, sizeof(signature));
auditCursor += sizeof(signature);
memcpy(auditCursor, signatureCertificate, 0x180);
memcpy(auditCursor, signatureCertificate, sizeof(signedData->signatureCertificate));
memcpy(auditCursor + sizeof(signedData->signatureCertificate),
deviceCertificate, sizeof(signedData->deviceCertificate));
unsigned long auditSize = sizeof(NUPSignedAuditData);
@@ -623,7 +622,7 @@ done:
}
/* MWCC must keep this helper out of line to match its callers. */
#pragma dont_inline on
static s32 __nupGetTmdView(ESTitleId titleId, ESTmdView** tmdView) NO_INLINE;
static s32 __nupGetTmdView(ESTitleId titleId, ESTmdView** tmdView) {
u32 tmdViewSize;
s32 result;
@@ -644,7 +643,6 @@ static s32 __nupGetTmdView(ESTitleId titleId, ESTmdView** tmdView) {
*tmdView = view;
return result;
}
#pragma dont_inline reset
template <class Title>
static inline BOOL __nupHasContent(const Title* title, ESContentId contentId) {
@@ -776,20 +774,20 @@ static s32 __nupGetTicket(NUPTitleInfo* title, char* contentPrefixUrl) {
snprintf(url, urlSize, "%s/%016llx/cetk", contentPrefixUrl, title->titleId);
result = __nupHttpGetFull(url, &response, &responseSize, 0, 0, 0);
if (result == 0) {
if (responseSize <= 0x2a4) {
if (responseSize <= sizeof(ESTicket)) {
result = -0x138c;
} else {
title->ticket = nup::__nupMalloc(0x2a4);
title->ticket = nup::__nupMalloc(sizeof(ESTicket));
if (title->ticket == 0) {
result = -5000;
} else {
title->ticketCertificate = nup::__nupMalloc(responseSize - 0x2a4);
title->ticketCertificate = nup::__nupMalloc(responseSize - sizeof(ESTicket));
if (title->ticketCertificate == 0) {
result = -5000;
} else {
title->ticketCertificateSize = responseSize - 0x2a4;
memcpy(title->ticket, response, 0x2a4);
memcpy(title->ticketCertificate, response + 0x2a4, title->ticketCertificateSize);
title->ticketCertificateSize = responseSize - sizeof(ESTicket);
memcpy(title->ticket, response, sizeof(ESTicket));
memcpy(title->ticketCertificate, response + sizeof(ESTicket), title->ticketCertificateSize);
}
}
}
@@ -1092,7 +1090,6 @@ static s32 __nupUpdateTitle(NUPContextInfo* context, NUPTitleInfo* title, char*
if (result != 0) {
goto done;
}
goto cleanup;
} else {
result = __nupCheckTitleSpace(title);
if (result == 0) {
@@ -1127,7 +1124,6 @@ static s32 __nupUpdateTitle(NUPContextInfo* context, NUPTitleInfo* title, char*
goto done;
}
}
cleanup:
__nupCleanupTitleInfo(title);
title->updateRequired = 0;
done:

View File

@@ -133,12 +133,21 @@ static int __nupNhttpOp(char* url, NHTTPReqMethod method, char* headers, u8* bod
state.result = 0;
state.lastActivity = 0;
request = NHTTPCreateRequestEx(url, method, NULL, 0, __nupNhttpReqDone, &state, __nupNhttpBufFull, __nupNhttpBufFree);
if (request == NULL) { result = -7000 - NHTTPGetError(); goto cleanup; }
if (NHTTPSetSocketBufferSize(request, 0x8000) != 0) { result = -7000 - NHTTPGetError(); goto cleanup; }
if (request == NULL) {
result = -7000 - NHTTPGetError();
goto cleanup;
}
if (NHTTPSetSocketBufferSize(request, 0x8000) != 0) {
result = -7000 - NHTTPGetError();
goto cleanup;
}
if (headers != NULL) {
unsigned long size = strlen(headers) + 1;
headerCopy = (char*)nup::__nupMalloc(size);
if (headerCopy == NULL) { result = -5000; goto cleanup; }
if (headerCopy == NULL) {
result = -5000;
goto cleanup;
}
memcpy(headerCopy, headers, size);
char* field = headerCopy;
char* colon;
@@ -150,18 +159,42 @@ static int __nupNhttpOp(char* url, NHTTPReqMethod method, char* headers, u8* bod
while (*field && isspace(*field)) field++;
char* value = colon + 1;
while (*value && isspace(*value)) ++value;
if (NHTTPAddHeaderField(request, field, value) != 0) { result = -7000 - NHTTPGetError(); goto cleanup; }
if (NHTTPAddHeaderField(request, field, value) != 0) {
result = -7000 - NHTTPGetError();
goto cleanup;
}
field = end + 2;
}
}
if (NHTTPAddHeaderField(request, "Accept", "text/html, image/gif, image/jpeg, */*") != 0) { result = -7000 - NHTTPGetError(); goto cleanup; }
if (NHTTPAddHeaderField(request, "Content-type", "text/xml; charset=utf-8") != 0) { result = -7000 - NHTTPGetError(); goto cleanup; }
if (NHTTPAddHeaderField(request, "Connection", "Keep-Alive") != 0) { result = -7000 - NHTTPGetError(); goto cleanup; }
if (NHTTPSetClientCertDefault(request) != 0) { result = -7000 - NHTTPGetError(); goto cleanup; }
if (NHTTPSetRootCADefault(request) != 0) { result = -7000 - NHTTPGetError(); goto cleanup; }
if (NHTTPSetVerifyOption(request, 11) != 0) { result = -7000 - NHTTPGetError(); goto cleanup; }
if (NHTTPAddHeaderField(request, "Accept", "text/html, image/gif, image/jpeg, */*") != 0) {
result = -7000 - NHTTPGetError();
goto cleanup;
}
if (NHTTPAddHeaderField(request, "Content-type", "text/xml; charset=utf-8") != 0) {
result = -7000 - NHTTPGetError();
goto cleanup;
}
if (NHTTPAddHeaderField(request, "Connection", "Keep-Alive") != 0) {
result = -7000 - NHTTPGetError();
goto cleanup;
}
if (NHTTPSetClientCertDefault(request) != 0) {
result = -7000 - NHTTPGetError();
goto cleanup;
}
if (NHTTPSetRootCADefault(request) != 0) {
result = -7000 - NHTTPGetError();
goto cleanup;
}
if (NHTTPSetVerifyOption(request, 11) != 0) {
result = -7000 - NHTTPGetError();
goto cleanup;
}
NHTTPSetProxyDefault(request);
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);
if (requestId < 0) {
result = -7000 - NHTTPGetError();
@@ -180,16 +213,28 @@ static int __nupNhttpOp(char* url, NHTTPReqMethod method, char* headers, u8* bod
}
NCDSleep(OSMillisecondsToTicks(100));
}
if (state.result != 0) { result = -7000 - state.result; goto cleanup; }
if (state.result != 0) {
result = -7000 - state.result;
goto cleanup;
}
if (state.response != NULL) {
length = NHTTPGetBodyAll(state.response, &responseBody);
if (length < 0) { result = -5007; goto cleanup; }
if (length < 0) {
result = -5007;
goto cleanup;
}
__nupNhttpBufFull(&responseBody, (unsigned long*)&length, 0, NULL, NULL, &state);
}
if (state.error != 0) { result = state.error; goto cleanup; }
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; }
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;
@@ -218,7 +263,10 @@ static inline long AppendHttpString(unsigned long length, u8* data, unsigned lon
if (total > text->capacity) {
requested = HttpStringGrowthSize(text, total, requested);
next = (u8*)nup::__nupMalloc(requested);
if (next == NULL) { result = -5000; goto done; }
if (next == NULL) {
result = -5000;
goto done;
}
if (text->buffer != NULL) {
memcpy(next, text->buffer, text->length);
nup::__nupFree(text->buffer);

View File

@@ -85,15 +85,15 @@ void __OSPlayTimeFadeLastAIDCallback() {
u32 bytes = AIGetDMALength();
f32 delta = 0.995f;
int i = bytes;
while (i) {
int bytesRemaining = bytes;
while (bytesRemaining) {
*dest++ = __OSExpireAIFade->auxL;
*dest++ = __OSExpireAIFade->auxR;
__OSExpireAIFade->auxL *= delta;
__OSExpireAIFade->auxR *= delta;
i -= 4;
bytesRemaining -= 4;
}
DCFlushRange(buffer, bytes);
@@ -164,8 +164,8 @@ BOOL __OSWriteExpiredFlagIfSet() {
void* __OSPlayTimeRebootThread(void* args) {
BOOL enabled;
u32 frames = 1;
u32 fadeShift = 1;
u32 frames;
u32 fadeShift;
__OSExpireAIFadeStruct aiFade ALIGN32;
// Setup sound fade out
@@ -242,6 +242,7 @@ void __OSPlayTimeAlarmExpired(OSAlarm* alarm, OSContext* context) {
}
}
// MWCC needs the error-path result self-copies to preserve the original branches.
s32 __OSPlayTimeGetConsumption(ESTicketView* ticket, ESLpEntry* lpEntry, u32* entries) {
s32 ret = ESP_GetConsumption(ticket->ticketId, NULL, entries);
@@ -269,7 +270,7 @@ getout:
s32 __OSGetPlayTime(ESTicketView* ticket, OSPlayTimeType* type, u32* playTime) {
s32 ret;
u32 i, numEntries = 0, seenOther = 0;
u32 i, numEntries = 0, otherLimitIndex = 0;
ESTicketView ticketAligned ALIGN32;
ESLpEntry lpEntry[ES_LIMIT_MAX] ALIGN32;
@@ -299,22 +300,22 @@ s32 __OSGetPlayTime(ESTicketView* ticket, OSPlayTimeType* type, u32* playTime) {
*playTime = ticket->limits.data[i].limit - lpEntry[i].limit;
goto getout;
} else if (ticket->limits.data[i].code != OS_PLAYTIME_PERMANENT) {
seenOther = i + 1;
otherLimitIndex = i + 1;
}
}
if (!seenOther) {
if (!otherLimitIndex) {
*type = OS_PLAYTIME_PERMANENT;
*playTime = 0xFFFFFFFF;
} else {
seenOther--;
otherLimitIndex--;
if (ticket->limits.data[seenOther].code == OS_PLAYTIME_LAUNCH_LIMIT) {
if (ticket->limits.data[otherLimitIndex].code == OS_PLAYTIME_LAUNCH_LIMIT) {
*type = OS_PLAYTIME_LAUNCH_LIMIT;
*playTime = ticket->limits.data[seenOther].limit;
*playTime = ticket->limits.data[otherLimitIndex].limit;
if (numEntries > 0) {
*playTime -= lpEntry[seenOther].limit;
*playTime -= lpEntry[otherLimitIndex].limit;
}
} else {
*type = OS_PLAYTIME_UNKNOWN;

View File

@@ -168,7 +168,6 @@ static void makeCode(u32 addr, u32* i_buff);
static int cnvFarCode(RSOObjectHeader* rso, RSOImportTable* impTab, int impIndex, u32 addr, u32* i_buff);
static int cnvJumpCode(RSOObjectHeader* rso, RSOImportTable* impTab, int impIndex, u32 addr, u32* i_buff);
#pragma dont_inline on
#if SDK_VERSION > 20090224 && !defined(SDK_IPL)
void RSONotifyModuleLoaded(RSOObjectHeader* moduleHeader) {
}
@@ -193,7 +192,6 @@ void RSONotifyLink(RSOObjectHeader* moduleHeader) {
void RSONotifyUnlink(RSOObjectHeader* moduleHeader) {
}
#endif
#pragma dont_inline reset
static BOOL LocateObject(void* newModule, void* bss, RSOFixedLevel i_fixed_level) {
u32 i;

View File

@@ -19,6 +19,9 @@ SDKDefineVersion(SC, "Apr 20 2010", "11:21:17");
#define SC_SMALLARRAY_MAX 0xFF
#define SC_BIGARRAY_MAX 0xFFFF
#define SC_ITEM_TYPE_MASK 0xE0
#define SC_ITEM_NAME_LEN_MASK 0x1F
typedef enum {
SC_ITEM_BIGARRAY = (1 << 5),
SC_ITEM_SMALLARRAY = (2 << 5),
@@ -442,14 +445,14 @@ static SCStatus ParseConfBuf(u8* conf, u32 size) {
// Build lookup table
// MWCC needs the name load in this loop condition to preserve scheduling.
for (tblEnd = &tblIter[ItemIDMaxPlus1]; tblIter < tblEnd && (itName = tblIter->name) != (void*)NULL; tblIter++) {
for (tblEnd = &tblIter[ItemIDMaxPlus1]; tblIter < tblEnd && (itName = tblIter->name) != NULL; tblIter++) {
u32 itNameLen = strlen(itName);
for (i = 0; i < numItems; i++) {
SCConfItem* itData = (SCConfItem*)(confBegin + confItems[i]);
// Item length doesn't include terminator
if (itNameLen != (itData->desc & 0b00011111) + 1) {
if (itNameLen != (itData->desc & SC_ITEM_NAME_LEN_MASK) + 1) {
continue;
}
@@ -492,9 +495,9 @@ static BOOL UnpackItem(const SCConfItem* raw, SCItem* item) {
u8 type;
memset(item, 0, sizeof(SCItem));
type = raw->desc & 0b11100000;
type = raw->desc & SC_ITEM_TYPE_MASK;
item->name = raw->name;
item->nameLen = (raw->desc & 0b00011111) + 1;
item->nameLen = (raw->desc & SC_ITEM_NAME_LEN_MASK) + 1;
item->data = (u8*)raw + item->nameLen + 1;
switch (type) {
@@ -574,7 +577,7 @@ static void DeleteItemByID(SCItemID id) {
u16* confLut;
u16* confItemsBegin;
u16* confItemsEnd;
u32 sp14;
u32 prefixSize;
u16* it;
int i;
@@ -612,8 +615,8 @@ static void DeleteItemByID(SCItemID id) {
// Offset from next item
itemSize = itemOfs[1] - itemOfs[0] + sizeof(u16);
sp14 = *itemOfs - (itemOfsOfs + sizeof(u16));
memmove(conf + itemOfsOfs, conf + itemOfsOfs + sizeof(u16), sp14);
prefixSize = *itemOfs - (itemOfsOfs + sizeof(u16));
memmove(conf + itemOfsOfs, conf + itemOfsOfs + sizeof(u16), prefixSize);
// Adjust item offsets
for (it = confItemsEnd - 1; it >= confItemsBegin; it--) {
@@ -672,7 +675,7 @@ static BOOL CreateItemByID(SCItemID id, u8 primType, const void* src, u32 len) {
goto _error;
}
if (src == (void*)NULL) {
if (src == NULL) {
goto _error;
}
@@ -727,19 +730,19 @@ static BOOL CreateItemByID(SCItemID id, u8 primType, const void* src, u32 len) {
itemSize += len;
// MWCC needs the name load in this loop condition to preserve both branches.
for (; (itemName = it->name) != (void*)NULL; it++) {
for (; (itemName = it->name) != NULL; it++) {
if (it->id == id) {
break;
}
}
if (itemName == (void*)NULL) {
if (itemName == NULL) {
goto _error;
}
// Only five bits reserved for name length (minus one)
itemNameLen = strlen(itemName);
if (itemNameLen > 0b00011111 + 1) {
if (itemNameLen > SC_ITEM_NAME_LEN_MASK + 1) {
goto _error;
}
@@ -801,7 +804,7 @@ BOOL SCFindByteArrayItem(void* dst, u32 len, SCItemID id) {
success = FALSE;
enabled = OSDisableInterrupts();
if (dst != ((void*)NULL) && FindItemByID(id, &item) && item.arrayType != 0 && item.dataLen == len) {
if (dst != NULL && FindItemByID(id, &item) && item.arrayType != 0 && item.dataLen == len) {
memcpy(dst, item.data, len);
success = TRUE;
}
@@ -818,7 +821,7 @@ BOOL SCReplaceByteArrayItem(const void* src, u32 len, SCItemID id) {
success = FALSE;
enabled = OSDisableInterrupts();
if (src != ((void*)NULL)) {
if (src != NULL) {
if (FindItemByID(id, &item)) {
if (item.arrayType != 0 && item.dataLen == len) {
if (memcmp(item.data, src, len) != 0) {
@@ -977,7 +980,7 @@ void SCFlushAsync(SCFlushCallback callback) {
if (status == SC_STATUS_OK) {
SetBgJobStatus(SC_STATUS_BUSY);
if (callback == ((void*)NULL)) {
if (callback == NULL) {
callback = __SCFlushSyncCallback;
}
@@ -1131,7 +1134,7 @@ static void FinishFromFlush() {
ctrl->flushCallback = NULL;
callback(ctrl->flushStatus);
if (ctrl->threadQueue.head != ((void*)NULL)) {
if (ctrl->threadQueue.head != NULL) {
OSWakeupThread(&ctrl->threadQueue);
}
}

View File

@@ -44,7 +44,7 @@ typedef struct __sdCbArg {
u32 cmd; // 0x0C
u32 SDDevRca;
u32* resp; // 0x14
u8* SDSectorSize;
u8* commandBuffer;
} __sdCbArg;
enum {
@@ -96,8 +96,8 @@ IOSError __sdCb(s32 result, void* arg) {
data->cb(result, data->cbArg);
}
if (data->SDSectorSize != NULL) {
iosFree(__sdHeapId[0], data->SDSectorSize);
if (data->commandBuffer != NULL) {
iosFree(__sdHeapId[0], data->commandBuffer);
}
iosFree(__sdHeapId[0], data);
@@ -195,7 +195,7 @@ static IOSError sduCommandv(s32 fd, u32 cmd, u32 cmdType, u32 respType, u32 arg,
data->cbArg = cbArg;
data->resp = resp;
data->cmd = cmd;
data->SDSectorSize = (u8*)sdCmd;
data->commandBuffer = (u8*)sdCmd;
ret = IOS_IoctlvAsync(fd, 7, readCount, writeCount, __sdVect, __sdCb, data);
}
@@ -243,15 +243,15 @@ static ISD_Error sduCommand(s32 fd, u32 cmd, u32 cmdType, u32 respType, u32 arg,
data->resp = resp;
data->cmd = cmd;
data->SDDevRca = 1;
data->SDSectorSize = (u8*)sdCmd;
data->commandBuffer = (u8*)sdCmd;
ret = IOS_IoctlAsync(fd, 7, sdCmd, SD_CMD_SIZE /*typo?*/, __sdResp, 0x10, __sdCb, data);
ret = IOS_IoctlAsync(fd, 7, sdCmd, SD_CMD_SIZE, __sdResp, 0x10, __sdCb, data);
if (ret != IPC_RESULT_OK) {
ret = SD_ERROR_FATAL;
}
}
} else {
ret = IOS_Ioctl(fd, 7, sdCmd, 0x24, __sdResp, 0x10);
ret = IOS_Ioctl(fd, 7, sdCmd, SD_CMD_SIZE, __sdResp, 0x10);
if (ret != IPC_RESULT_OK) {
if (cmd == 7) {
ret = SD_ERROR_SUCCESS;
@@ -382,7 +382,7 @@ ISD_Error ISD_ReadMultiBlockAsync(SDDev* dev, u32 offset, u8* cmdResp, u32 cmdRe
}
if (offset + cmdRespSize > dev->SDDevSize) {
return -4;
return IPC_RESULT_INVALID;
}
OSLockMutex(&__reqMutex);
@@ -466,7 +466,7 @@ ISD_Error ISD_WriteMultiBlockAsync(SDDev* dev, u32 offset, u8* cmdResp, u32 cmdR
}
if (offset + cmdRespSize > dev->SDDevSize) {
return -4;
return IPC_RESULT_INVALID;
}
OSLockMutex(&__reqMutex);
@@ -672,7 +672,7 @@ ISD_Error ISD_ReadCardRegister(SDDev* dev, u32 cmd, u32* cmdResp, u32 cmdRespSiz
}
if (cmdResp == NULL || cmdRespSize == 0) {
ret = -4;
ret = IPC_RESULT_INVALID;
__sdReq = 0;
goto out;
}
@@ -699,7 +699,7 @@ ISD_Error ISD_ReadCardRegister(SDDev* dev, u32 cmd, u32* cmdResp, u32 cmdRespSiz
goto out;
}
default: {
return -4;
return IPC_RESULT_INVALID;
}
}
@@ -793,7 +793,7 @@ ISD_Error ISD_GetCardSize(SDDev* dev, u32* outSize, u32* outSize2, u32* outSecto
u32 resp[4];
memset(resp, 0, sizeof(resp));
ret = ISD_ReadCardRegister(dev, 9, resp, 0x10);
ret = ISD_ReadCardRegister(dev, 9, resp, sizeof(resp));
if (ret != SD_ERROR_SUCCESS) {
return ret;
}

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