Word Unperfect
public
Read
Owner: themaster
Branch: main
Commits: 0
Git CLI clone URL
git clone https://www.xt-emporium.com/git/word-unperfect.git
Fullscreen desktop URL
Code
Commits
History
Branches
Bug Reports
Discussions
Compare
Settings
word-unperfect
/
rev
/
wp_layout_variant.c
File editor
#include "wp_layout_variant.h" #include "wp_layout_state.h" #include "wp_record_stream.h" #include <string.h> #define WP_LAYOUT_VARIANT_WALK_WORD_COUNT 0x28U static size_t wp_layout_build_default_path_words(const WpLayoutGlobals *wl, uint16_t words[WP_LAYOUT_VARIANT_WALK_WORD_COUNT]) { size_t i; uint16_t base_word; uint16_t step; if (wl == NULL || words == NULL) { return 0U; } base_word = (uint16_t)wl->emit_record_scratch_5031; step = (uint16_t)wl->measure_extent_cap_50be; if (step == 0U) { step = 1U; } for (i = 0U; i < WP_LAYOUT_VARIANT_WALK_WORD_COUNT; ++i) { uint16_t i_stride = (uint16_t)(step + (uint16_t)i * (uint16_t)(wl->record_axis_base_4b44 + 1U)); words[i] = (uint16_t)(base_word + i_stride); } return WP_LAYOUT_VARIANT_WALK_WORD_COUNT; } bool wp_layout_variant_table_init(uint16_t *slot_a, uint16_t *slot_b, WpLayoutVariantEntry entry, bool aux_flag_set, WpLayoutVariantInitResult *out_result) { WpLayoutVariantInitResult result; if (out_result != NULL) { memset(out_result, 0, sizeof(*out_result)); } if (slot_a == NULL || slot_b == NULL) { return false; } memset(&result, 0, sizeof(result)); result.flags = entry.flags; result.value = entry.value; result.old_slot_a = *slot_a; result.old_slot_b = *slot_b; result.new_slot_a = *slot_a; result.new_slot_b = *slot_b; if (entry.flags == 0U) { result.no_op_zero_flags = true; if (out_result != NULL) { *out_result = result; } return true; } /* Decompiled 1000:1c78: bit 0 raises the SI-side word. */ if ((entry.flags & 0x01U) != 0U && *slot_a < entry.value) { *slot_a = entry.value; result.bit0_updated_slot_a = true; } /* With bit 1 clear, the DI-side word is raised. */ if ((entry.flags & 0x02U) == 0U && *slot_b < entry.value) { *slot_b = entry.value; result.bit1_clear_updated_slot_b = true; } /* The decompiler exposes `(bVar3 << 6 | (AF & 4) << 4) == 0`: that is true * only when bit 1 is set and the auxiliary/carry-style flag is clear. */ if ((entry.flags & 0x02U) != 0U && !aux_flag_set && *slot_a < entry.value) { *slot_a = entry.value; result.bit1_set_aux_clear_updated_slot_a = true; } result.new_slot_a = *slot_a; result.new_slot_b = *slot_b; if (out_result != NULL) { *out_result = result; } return true; } bool wp_layout_word_passthrough(const WpLayoutGlobals *wl, uint16_t raw_word, WpLayoutWordPassResult *out_result) { WpLayoutWordPassResult result; uint16_t adjusted; uint16_t compare_word; uint16_t emit_word; uint16_t cap_word; if (out_result != NULL) { memset(out_result, 0, sizeof(*out_result)); } if (wl == NULL || out_result == NULL) { return false; } memset(&result, 0, sizeof(result)); compare_word = (uint16_t)wl->measure_compare_word_50b2; emit_word = (uint16_t)wl->emit_record_scratch_5031; cap_word = (uint16_t)wl->measure_extent_cap_50be; adjusted = raw_word; result.raw_word = raw_word; result.adjusted_word = raw_word; result.compare_word = compare_word; result.emit_scratch_word = emit_word; result.extent_cap = cap_word; result.compare_active = compare_word != 0xFFFFU; result.sentinel_word = raw_word == 0xFFFFU; if (result.compare_active && !result.sentinel_word) { if (emit_word < compare_word) { uint16_t delta = (uint16_t)(compare_word - emit_word); result.signed_adjustment = -(int16_t)delta; if (raw_word < delta) { adjusted = 0U; result.saturated_to_zero = true; } else { adjusted = (uint16_t)(raw_word - delta); } } else { uint16_t delta = (uint16_t)(emit_word - compare_word); uint16_t before = adjusted; result.signed_adjustment = (int16_t)delta; adjusted = (uint16_t)(adjusted + delta); result.wrapped_positive_adjustment = adjusted < before; } } if (!result.sentinel_word && adjusted < cap_word) { adjusted = cap_word; result.clamped_to_extent_cap = true; } result.adjusted_word = adjusted; *out_result = result; return true; } static bool wp_layout_path_walk_common(WpLayoutGlobals *wl, const uint16_t *words, size_t word_count, bool stop_on_less_equal, WpLayoutPathWalkResult *out_result) { WpLayoutPathWalkResult result; size_t effective_word_count; uint16_t default_words[WP_LAYOUT_VARIANT_WALK_WORD_COUNT]; size_t limit; size_t i; if (wl == NULL || out_result == NULL) { return false; } if (words == NULL || word_count == 0U) { effective_word_count = wp_layout_build_default_path_words(wl, default_words); if (effective_word_count == 0U) { return false; } words = default_words; word_count = effective_word_count; } else { effective_word_count = word_count; } if (out_result != NULL) { memset(out_result, 0, sizeof(*out_result)); } memset(&result, 0, sizeof(result)); limit = effective_word_count < WP_LAYOUT_VARIANT_WALK_WORD_COUNT ? effective_word_count : WP_LAYOUT_VARIANT_WALK_WORD_COUNT; result.max_words = limit; for (i = 0; i < limit; ++i) { WpLayoutWordPassResult pass; if (!wp_layout_word_passthrough(wl, words[i], &pass)) { break; } result.words_seen++; result.raw_word = pass.raw_word; result.adjusted_word = pass.adjusted_word; if ((!stop_on_less_equal && pass.raw_word < pass.adjusted_word) || (stop_on_less_equal && pass.raw_word <= pass.adjusted_word)) { result.stopped = true; result.stop_index = (uint16_t)i; result.stopped_on_raw_less_than_adjusted = pass.raw_word < pass.adjusted_word; result.stopped_on_raw_less_or_equal_adjusted = pass.raw_word <= pass.adjusted_word; result.first_slot_stop = i == 0U; break; } } if (stop_on_less_equal && (!result.stopped || !result.first_slot_stop)) { /* layout_record_path_walk calls layout_dirty_flags_or_mask after any * non-first stop or full walk. The body at 1000:1cd3 is a register * passthrough in the recovered listing, so the host exposes the call * without inventing new dirty bits. */ result.dirty_helper_called = true; } *out_result = result; return true; } bool wp_layout_heap_cursor_rebase(const WpLayoutGlobals *wl, const uint16_t *words, size_t word_count, WpLayoutPathWalkResult *out_result) { uint16_t default_words[WP_LAYOUT_VARIANT_WALK_WORD_COUNT]; const uint16_t *walk_words = words; size_t walk_count = word_count; if (wl == NULL || out_result == NULL) { return false; } if (walk_words == NULL || walk_count == 0U) { walk_count = wp_layout_build_default_path_words(wl, default_words); walk_words = default_words; } /* The routine does not mutate layout globals; cast only to reuse the common * walker that needs access to WpLayoutGlobals fields. */ return wp_layout_path_walk_common((WpLayoutGlobals *)wl, walk_words, walk_count, false, out_result); } bool wp_layout_record_path_walk(WpLayoutGlobals *wl, const uint16_t *words, size_t word_count, WpLayoutPathWalkResult *out_result) { uint16_t default_words[WP_LAYOUT_VARIANT_WALK_WORD_COUNT]; const uint16_t *walk_words = words; size_t walk_count = word_count; if (wl == NULL || out_result == NULL) { return false; } if (walk_words == NULL || walk_count == 0U) { walk_count = wp_layout_build_default_path_words(wl, default_words); walk_words = default_words; } return wp_layout_path_walk_common(wl, walk_words, walk_count, true, out_result); } bool wp_layout_large_emit_measure_hub(WpLayoutGlobals *wl, const WpLayoutVariantEntry entries[4], WpLayoutLargeEmitResult *out_result) { WpLayoutLargeEmitResult result; uint8_t mode; uint8_t cursor_mode; int16_t axis_a; int16_t axis_b; int16_t base_a; int16_t base_b; uint16_t slot_a; uint16_t slot_b; unsigned entry_index; uint8_t gate_bits; int16_t secondary_offset; int16_t primary_offset; int16_t axis_with_padding; int16_t extra; if (out_result != NULL) { memset(out_result, 0, sizeof(*out_result)); } if (wl == NULL || out_result == NULL) { return false; } memset(&result, 0, sizeof(result)); mode = wl->record_mode_flags; cursor_mode = 0U; axis_a = 0; axis_b = 0; if ((mode & 0x01U) == 0U) { cursor_mode = wl->record_cursor_mode_4b78; } if ((mode & 0x02U) != 0U) { cursor_mode = 5U; } if (cursor_mode != 0U) { axis_a = (int16_t)wl->record_cursor_metric_4b79; if (cursor_mode < 5U) { axis_b = axis_a; axis_a = 0; } } base_a = axis_a; base_b = axis_b; slot_a = (uint16_t)axis_a; slot_b = (uint16_t)axis_b; result.record_mode_flags = mode; result.record_cursor_mode = cursor_mode; result.record_cursor_metric = (int16_t)wl->record_cursor_metric_4b79; result.initial_axis_a = axis_a; result.initial_axis_b = axis_b; if (entries != NULL) { gate_bits = (uint8_t)(mode >> 2U); for (entry_index = 0; entry_index < 4U; ++entry_index) { if ((gate_bits & 0x01U) == 0U) { WpLayoutVariantInitResult init; uint16_t before_a = slot_a; uint16_t before_b = slot_b; uint16_t call_a = entry_index == 0U ? (uint16_t)axis_a : (uint16_t)base_a; uint16_t call_b = entry_index == 0U ? (uint16_t)axis_b : (uint16_t)base_b; if (slot_a < call_a) { slot_a = call_a; } if (slot_b < call_b) { slot_b = call_b; } if (wp_layout_variant_table_init(&slot_a, &slot_b, entries[entry_index], false, &init)) { result.table_init_calls++; if (init.bit0_updated_slot_a || init.bit1_set_aux_clear_updated_slot_a || slot_a != before_a) { result.slot_a_updates++; } if (init.bit1_clear_updated_slot_b || slot_b != before_b) { result.slot_b_updates++; } if (init.bit1_set_aux_clear_updated_slot_a) { result.aux_clear_updates++; } } } gate_bits = (uint8_t)(gate_bits >> 1U); } } extra = (int16_t)wl->variant_origin_extra_4dbe; axis_with_padding = axis_a != 0 ? (int16_t)(axis_a + 200) : 0; secondary_offset = axis_b; if (secondary_offset != 0) { secondary_offset = (int16_t)(secondary_offset + 200 + extra); result.secondary_origin_used_cursor_metric = true; } wl->secondary_origin = (uint16_t)((int16_t)wl->record_axis_base_4b44 + secondary_offset); wl->secondary_limit = (uint16_t)((int16_t)wl->pending_total - (int16_t)(secondary_offset + axis_with_padding)); primary_offset = (int16_t)(0x1C4A + 200 + extra); wl->primary_origin = (uint16_t)((int16_t)wl->record_axis_base_4b44 + primary_offset); wl->primary_limit = (uint16_t)((int16_t)wl->pending_total - (int16_t)(primary_offset + axis_with_padding)); wl->span_table_word_a_4be0 = slot_a; wl->span_table_word_b_4be2 = slot_b; wl->render_dirty_flags |= 0x01U; result.slot_a = slot_a; result.slot_b = slot_b; result.secondary_origin = (int16_t)(uint16_t)wl->secondary_origin; result.secondary_limit = (int16_t)(uint16_t)wl->secondary_limit; result.primary_origin = (int16_t)(uint16_t)wl->primary_origin; result.primary_limit = (int16_t)(uint16_t)wl->primary_limit; result.render_dirty_set = (wl->render_dirty_flags & 0x01U) != 0U; *out_result = result; return true; } bool wp_layout_emit_multi_variant_records(WpLayoutGlobals *wl, uint16_t mask, int8_t allow_overlay_jump, const uint16_t variant_masks[16], const uint8_t selectors[16], WpLayoutMultiVariantResult *out_result) { WpLayoutMultiVariantResult result; uint16_t ax; unsigned i; if (out_result != NULL) { memset(out_result, 0, sizeof(*out_result)); } if (wl == NULL || out_result == NULL) { return false; } memset(&result, 0, sizeof(result)); result.input_mask = mask; ax = mask; if (ax != 0U) { wl->shift_reg_77fe = 0U; for (i = 0; i < 16U; ++i) { bool selected; uint16_t table_mask = variant_masks != NULL ? variant_masks[i] : 0xFFFFU; wl->shift_reg_77fe = (uint16_t)(wl->shift_reg_77fe >> 1U); selected = (ax & 0x0001U) != 0U; ax = (uint16_t)((ax >> 1U) | (selected ? 0x8000U : 0U)); result.bits_examined++; if (selected) { uint8_t selector = selectors != NULL ? selectors[i] : 0xFFU; result.selected_bits++; result.last_selector = selector; if (selector == 0xFFU) { result.ignored_ff_selectors++; } else if (selector < 0xFEU) { result.selector_loads++; result.last_selector_offset = (uint16_t)selector * 0x56U; wl->irq_misc_77ff |= 0x80U; result.irq_misc_set = true; } else if (allow_overlay_jump != 0) { result.overlay_jump_hints++; } } ax = (uint16_t)(ax & table_mask); } result.rotated_mask = ax; result.return_mask = (uint16_t)wl->shift_reg_77fe; result.shift_reg = (uint16_t)wl->shift_reg_77fe; } *out_result = result; return true; } /* Raw wrappers for monolith compatibility */ uint16_t __cdecl16near layout_restore_flag_state(WpLayoutGlobals *wl) { uint16_t rc; WpLayoutLargeEmitResult emit_result; if (wl == NULL) { return 0; } rc = (uint16_t)wl->status_dirty_flags; if (wl->carry_width == 0) { parser_carry_chain_eval_order_no_op(wl); if ((wl->restore_flags & 2U) != 0U) { int32_t pending_total = (int32_t)(uint16_t)wl->pending_total; pending_total -= (int32_t)wl->record_axis_base_4b44; pending_total -= (int32_t)wl->record_axis_run_4b46; if (pending_total < 0L) { pending_total = 0L; } wl->pending_total = (undefined2)(uint16_t)(pending_total & 0xFFFFL); wl->restore_flags &= 0xFDU; } if ((wl->restore_flags & 1U) != 0U) { (void)wp_layout_large_emit_measure_hub(wl, NULL, &emit_result); restore_layout_state_snapshot_if_valid(wl); wl->restore_flags &= 0xFEU; } } wl->restore_flags &= 0x7FU; return rc; } uint16_t __cdecl16near layout_large_emit_measure_hub(WpLayoutGlobals *wl) { WpLayoutLargeEmitResult result; memset(&result, 0, sizeof(result)); if (!wp_layout_large_emit_measure_hub(wl, NULL, &result)) { return 0; } return (uint16_t)result.secondary_limit; } void __cdecl16near layout_variant_table_init(WpLayoutGlobals *wl, int16_t arg1, int16_t arg2, int16_t arg3, int16_t arg4) { if (wl == NULL) { return; } /* Conservative stand-in for the 16-bit compatibility routine. We preserve observable host state while honoring the supplied operands as span-table input candidates. */ wl->span_table_word_a_4be0 = (undefined2)(uint16_t)arg1; wl->span_table_word_b_4be2 = (undefined2)(uint16_t)arg2; wl->restore_flags = (uint8_t)((uint16_t)wl->restore_flags & 0x7FU); wl->emit_record_scratch_5031 = (undefined2)(uint16_t)arg3; wl->measure_compare_word_50b2 = (uint16_t)arg4; } uint32_t __cdecl16near layout_heap_cursor_rebase(WpLayoutGlobals *wl) { WpLayoutPathWalkResult result; memset(&result, 0, sizeof(result)); if (!wp_layout_heap_cursor_rebase(wl, NULL, 0U, &result)) { return 0U; } return (uint32_t)((uint32_t)result.raw_word << 16U) | (uint32_t)result.adjusted_word; } uint32_t __cdecl16near layout_word_passthrough(WpLayoutGlobals *wl) { WpLayoutWordPassResult result; if (!wp_layout_word_passthrough(wl, (uint16_t)wl->emit_record_scratch_5031, &result)) { return 0U; } return ((uint32_t)result.raw_word << 16U) | (uint32_t)result.adjusted_word; } uint16_t __cdecl16near layout_dirty_flags_or_mask(WpLayoutGlobals *wl) { if (wl == NULL) { return 0; } return wl->status_dirty_flags; } uint32_t __cdecl16near layout_record_path_walk(WpLayoutGlobals *wl) { WpLayoutPathWalkResult result; memset(&result, 0, sizeof(result)); if (!wp_layout_record_path_walk(wl, NULL, 0U, &result)) { return 0U; } return ((uint32_t)result.raw_word << 16U) | (uint32_t)result.adjusted_word; } uint16_t __cdecl16near layout_emit_multi_variant_records(WpLayoutGlobals *wl, uint16_t ax, int8_t bl) { WpLayoutMultiVariantResult result; (void)wp_layout_emit_multi_variant_records(wl, ax, bl, NULL, NULL, &result); return result.rotated_mask; /* Using rotated_mask as return for ax */ }
Commit message
This repository is read-only for this account.
Repository snapshot
Current branch
main
Visibility
public
Your access
Read
Remote
None
File activity
View file history