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_metrics.c
File editor
#include "wp_layout_metrics.h" #include "wp_record_stream.h" #include "wp_parser_process.h" #include "wp_layout_flow.h" #include "wp_span_metrics.h" #include <string.h> extern void __cdecl16near layout_record_wide_temp_lo_hi_route_stage_1(WpLayoutGlobals *wl); extern uint16_t __cdecl16near layout_range_check_aux_return_ax(WpLayoutGlobals *wl); extern uint8_t __cdecl16near scan_memory_stride_3_for_char(WpLayoutGlobals *wl); uint16_t wp_layout_line_start_for_heap_depth(const WpLayoutGlobals *wl) { uint16_t start; if (wl == NULL) { return 0U; } start = (uint16_t)wl->line_start; if (wl->record_heap_flags_4bd6 > 1U) { if (wl->record_heap_flags_4bd6 < 4U) { if (wl->record_heap_flags_4bd6 == 3U) { start = (uint16_t)wl->emit_record_scratch_5033; } else { /* The decompiled code uses a 16-bit add plus CARRY2 bit to * compute the midpoint. A 17-bit host sum is equivalent. */ start = (uint16_t)(((uint32_t)(uint16_t)wl->emit_record_scratch_5033 + (uint32_t)(uint16_t)wl->emit_record_scratch_5031) >> 1U); } } else { start = (uint16_t)wl->line_build_word_51f9; } } return start; } uint16_t wp_layout_scale_extent_by_fraction(const WpLayoutGlobals *wl, uint8_t fraction_q8, bool enforce_minimum_span, uint16_t span_basis) { uint16_t line_span; uint16_t scaled; if (wl == NULL) { return 0U; } line_span = (uint16_t)((uint16_t)wl->emit_record_line_extent - (uint16_t)wl->line_start); scaled = (uint16_t)(((uint32_t)fraction_q8 * (uint32_t)line_span) >> 8U); if (enforce_minimum_span) { uint16_t delta4 = (uint16_t)((uint16_t)wl->span_metric_delta_4bda * 4U); if (span_basis <= delta4) { uint16_t minimum = (uint16_t)(delta4 - span_basis); if (minimum != 0U && scaled < minimum) { scaled = minimum; } } } if (scaled > line_span) { scaled = line_span; } return scaled; } bool wp_layout_measure_line_extent_dirty_heap(WpLayoutGlobals *wl, uint8_t fraction_q8, bool enforce_minimum_span, uint16_t span_basis, WpLayoutExtentResult *out_result) { WpLayoutExtentResult result; uint16_t emit_extent; uint16_t scaled; uint16_t candidate; uint16_t measure; uint16_t probe; if (out_result != NULL) { memset(out_result, 0, sizeof(*out_result)); } if (wl == NULL) { return false; } memset(&result, 0, sizeof(result)); result.line_span = (uint16_t)((uint16_t)wl->emit_record_line_extent - (uint16_t)wl->line_start); scaled = wp_layout_scale_extent_by_fraction(wl, fraction_q8, enforce_minimum_span, span_basis); emit_extent = (uint16_t)wl->emit_record_line_extent; candidate = (uint16_t)(emit_extent + scaled); measure = candidate; if ((wl->heap_control_flags_4bf1 & 0x01U) != 0U) { uint16_t cap = (uint16_t)((uint16_t)fraction_q8 + (uint16_t)wl->record_accum_cap_4c4a); result.heap_window_used = true; measure = 0x1000U; if (cap < measure) { measure = cap; } } wl->render_dirty_flags |= 0x08U; result.render_dirty_set = true; if (measure < emit_extent || wl->postprocess_mode != 0 || wl->record_heap_flags_4bd6 != 1U) { measure = emit_extent; result.clamped_to_emit_extent = true; } wl->measure_extent_50c8 = measure; /* The tail of layout_measure_line_extent_dirty_heap computes a negative * bound from another scaled probe and stores the magnitude. Host callers * pass the same recovered fraction; if the probe is before the current * extent, keep the positive distance, otherwise the bound is zero. */ probe = (uint16_t)(emit_extent + scaled); wl->measure_extent_bound_50c6 = probe < emit_extent ? (uint16_t)(emit_extent - probe) : 0U; result.scaled_span = scaled; result.candidate_extent = candidate; result.measure_extent = measure; result.measure_bound = (uint16_t)wl->measure_extent_bound_50c6; if (out_result != NULL) { *out_result = result; } return true; } static bool wp_layout_line_build_common(WpLayoutGlobals *wl, uint16_t span_metric, bool allow_growth, WpLayoutReconcileResult *out_result) { WpLayoutReconcileResult result; uint16_t cursor_word; uint16_t base_word; uint16_t raw_delta; int16_t signed_delta; uint16_t half_delta; uint16_t target; uint16_t floor_word; bool cursor_after_or_at_base; bool span_gate_blocks_cursor = false; if (out_result != NULL) { memset(out_result, 0, sizeof(*out_result)); } if (wl == NULL) { return false; } memset(&result, 0, sizeof(result)); cursor_word = (uint16_t)wl->cursor; base_word = (uint16_t)wl->line_build_word_51f7; cursor_after_or_at_base = base_word <= cursor_word; raw_delta = (uint16_t)(cursor_word - base_word); if (wl->postprocess_mode < 1) { if (cursor_after_or_at_base) { half_delta = (uint16_t)(raw_delta >> 1U); } else { signed_delta = (int16_t)raw_delta; half_delta = (uint16_t)(signed_delta >> 1); } } else { half_delta = raw_delta; } target = (uint16_t)((uint16_t)wl->line_build_word_51f3 - half_delta); if ((uint16_t)wl->line_build_word_51f3 < half_delta && cursor_after_or_at_base) { target = 0U; } floor_word = (uint16_t)wl->measure_extent_cap_50be; if ((((uint8_t)wl->postprocess_mode) & 0x20U) != 0U) { floor_word = (uint16_t)wl->emit_record_scratch_5031; } if (target < floor_word) { target = floor_word; result.target_clamped_to_floor = true; } result.cursor_delta = half_delta; result.target_floor = floor_word; result.span_metric = span_metric; result.old_span_word = (uint16_t)wl->line_build_word_51f5; result.old_cursor_word = (uint16_t)wl->line_build_word_51f7; result.new_span_word = result.old_span_word; result.new_cursor_word = result.old_cursor_word; if (!result.target_clamped_to_floor && span_metric != result.old_span_word) { bool in_direction = allow_growth ? (span_metric >= result.old_span_word) : (span_metric <= result.old_span_word); if (in_direction) { int16_t delta = (int16_t)(span_metric - result.old_span_word); wl->span_compare_word_51fb = span_metric; wl->record_aux_4b34 += delta; wl->line_build_word_51f5 = span_metric; wl->status_dirty_flags |= 0x02U; result.span_word_changed = true; result.span_delta = delta; result.new_span_word = span_metric; } else { span_gate_blocks_cursor = true; } } if (!span_gate_blocks_cursor && target != result.old_cursor_word) { bool in_direction = allow_growth ? (target >= result.old_cursor_word) : (target <= result.old_cursor_word); if (in_direction) { int16_t delta = (int16_t)(target - result.old_cursor_word); wl->span_compare_word_51ff = target; wl->cursor_alias_shadow_4b3e = (undefined2)((uint16_t)wl->cursor_alias_shadow_4b3e + (uint16_t)delta); wl->line_build_word_51f7 = target; wl->status_dirty_flags |= 0x02U; result.cursor_word_changed = true; result.cursor_delta_applied = delta; result.new_cursor_word = target; } } result.status_dirty_set = (wl->status_dirty_flags & 0x02U) != 0U; if (out_result != NULL) { *out_result = result; } return true; } bool wp_layout_reconcile_line_build_span_words(WpLayoutGlobals *wl, uint16_t span_metric, WpLayoutReconcileResult *out_result) { return wp_layout_line_build_common(wl, span_metric, false, out_result); } /* Raw wrapper for monolith compatibility @ 1000:2353-ish (actually logic from 1870/203c/etc) */ void __cdecl16near layout_reconcile_line_build_span_words(WpLayoutGlobals *wl) { WpLayoutReconcileResult result; (void)wp_layout_reconcile_line_build_span_words(wl, 0, &result); } bool wp_layout_increment_cursor_pack_state(WpLayoutGlobals *wl, uint16_t span_metric, WpLayoutReconcileResult *out_result) { return wp_layout_line_build_common(wl, span_metric, true, out_result); } static bool wp_layout_variant_common(WpLayoutGlobals *wl, uint16_t delta, bool subtract, WpLayoutVariantResult *out_result) { WpLayoutVariantResult result; uint16_t old_anchor; uint16_t old_total; uint16_t new_anchor; uint16_t new_total; if (out_result != NULL) { memset(out_result, 0, sizeof(*out_result)); } if (wl == NULL) { return false; } memset(&result, 0, sizeof(result)); old_anchor = (uint16_t)wl->variant_anchor; old_total = (uint16_t)wl->variant_total; if (subtract) { new_anchor = (uint16_t)(old_anchor - delta); new_total = (uint16_t)(old_total - delta); result.wrapped_or_borrowed = old_total <= new_total; } else { new_anchor = (uint16_t)(old_anchor + delta); new_total = (uint16_t)(old_total + delta); result.wrapped_or_borrowed = new_total <= old_total; } wl->variant_anchor = new_anchor; wl->variant_total = (int)(int16_t)new_total; if (result.wrapped_or_borrowed) { wl->parse_dirty_flags |= 0x08U; result.parse_dirty_set = true; } result.old_anchor = old_anchor; result.new_anchor = new_anchor; result.old_total = old_total; result.new_total = new_total; result.delta = delta; result.subtract = subtract; if (out_result != NULL) { *out_result = result; } return true; } bool wp_layout_add_to_variant_anchor_and_total(WpLayoutGlobals *wl, uint16_t delta, WpLayoutVariantResult *out_result) { return wp_layout_variant_common(wl, delta, false, out_result); } bool wp_layout_sub_from_variant_anchor_and_total(WpLayoutGlobals *wl, uint16_t delta, WpLayoutVariantResult *out_result) { return wp_layout_variant_common(wl, delta, true, out_result); } bool wp_layout_add_metrics_line_accum_to_variant_anchor_and_total(WpLayoutGlobals *wl, WpLayoutVariantResult *out_result) { if (wl == NULL) { if (out_result != NULL) { memset(out_result, 0, sizeof(*out_result)); } return false; } return wp_layout_add_to_variant_anchor_and_total(wl, (uint16_t)wl->metrics_line_accum_5037, out_result); } bool wp_layout_sub_metrics_line_accum_from_variant_anchor_and_total(WpLayoutGlobals *wl, WpLayoutVariantResult *out_result) { if (wl == NULL) { if (out_result != NULL) { memset(out_result, 0, sizeof(*out_result)); } return false; } return wp_layout_sub_from_variant_anchor_and_total(wl, (uint16_t)wl->metrics_line_accum_5037, out_result); } static bool wp_layout_make_stream_position(uint16_t index_word, uint16_t used_word, WpLayoutStreamPosition *out_position) { uint32_t base; uint32_t low_sum; WpLayoutStreamPosition position; if (out_position == NULL) { return false; } memset(&position, 0, sizeof(position)); base = ((uint32_t)index_word) * 0x800UL; low_sum = (base & 0xFFFFUL) + (uint32_t)used_word; position.low_word = (uint16_t)low_sum; position.carry_from_low_add = low_sum > 0xFFFFUL; position.high_word = (uint16_t)(((base >> 16U) + (position.carry_from_low_add ? 1U : 0U)) & 0xFFFFU); position.linear = (((uint32_t)position.high_word) << 16U) | (uint32_t)position.low_word; *out_position = position; return true; } static void wp_layout_balance_snapshot_before(WpLayoutGlobals *wl, WpLayoutVariantBalanceResult *result) { result->old_variant_total = (int16_t)(uint16_t)wl->variant_total; result->old_variant_balance = (int16_t)(uint16_t)wl->variant_balance_51bd; result->old_heap_delta = (int16_t)(uint16_t)wl->heap_delta_c5b6; result->old_variant_limit = (uint16_t)wl->variant_limit_c664; result->old_status_dirty_flags = wl->status_dirty_flags; result->old_status_extend = wl->status_extend_4976; } static void wp_layout_balance_snapshot_after(WpLayoutGlobals *wl, WpLayoutVariantBalanceResult *result) { result->new_variant_total = (int16_t)(uint16_t)wl->variant_total; result->new_variant_balance = (int16_t)(uint16_t)wl->variant_balance_51bd; result->new_heap_delta = (int16_t)(uint16_t)wl->heap_delta_c5b6; result->new_variant_limit = (uint16_t)wl->variant_limit_c664; result->new_status_dirty_flags = wl->status_dirty_flags; result->new_status_extend = wl->status_extend_4976; } bool wp_layout_update_variant_balance_and_flags(WpLayoutGlobals *wl, uint16_t delta, WpLayoutVariantBalanceResult *out_result) { WpLayoutVariantBalanceResult result; uint16_t old_balance; uint16_t combined; uint16_t screen_limit; if (out_result != NULL) { memset(out_result, 0, sizeof(*out_result)); } if (wl == NULL || out_result == NULL) { return false; } memset(&result, 0, sizeof(result)); wp_layout_balance_snapshot_before(wl, &result); result.add_path = true; result.delta = delta; screen_limit = (uint16_t)((uint16_t)wl->screen_extent_4741 - 1U); result.screen_extent_minus_one = screen_limit; old_balance = (uint16_t)wl->variant_balance_51bd; combined = (uint16_t)(old_balance + delta); if (screen_limit < combined) { uint16_t old_heap; uint16_t new_heap; uint16_t overflow_amount = (uint16_t)(combined - screen_limit); result.balance_clamped_to_screen = true; result.overflow_amount = overflow_amount; wl->status_extend_4976 |= 0x02U; wl->variant_balance_51bd = (int)(int16_t)screen_limit; old_heap = (uint16_t)wl->heap_delta_c5b6; new_heap = (uint16_t)(old_heap - overflow_amount); wl->heap_delta_c5b6 = (int)(int16_t)new_heap; if (old_heap < overflow_amount) { wl->status_dirty_flags |= 0x08U; wl->status_extend_4976 = 0U; result.heap_borrowed = true; } wl->status_dirty_flags |= 0x14U; result.far_refresh_would_run = true; if ((uint16_t)wl->secondary_record_used_bytes < 0x800U) { result.secondary_probe_would_run = true; } } else { wl->variant_balance_51bd = (int)(int16_t)combined; } wp_layout_balance_snapshot_after(wl, &result); *out_result = result; return true; } bool wp_layout_subtract_from_heap_delta_and_variant_balance(WpLayoutGlobals *wl, uint16_t delta, WpLayoutVariantBalanceResult *out_result) { WpLayoutVariantBalanceResult result; uint16_t old_heap; uint16_t old_balance; uint16_t new_balance; int16_t signed_balance; if (out_result != NULL) { memset(out_result, 0, sizeof(*out_result)); } if (wl == NULL || out_result == NULL) { return false; } memset(&result, 0, sizeof(result)); wp_layout_balance_snapshot_before(wl, &result); result.subtract_path = true; result.delta = delta; old_heap = (uint16_t)wl->heap_delta_c5b6; wl->heap_delta_c5b6 = (int)(int16_t)((uint16_t)(old_heap - delta)); old_balance = (uint16_t)wl->variant_balance_51bd; new_balance = (uint16_t)(old_balance - delta); wl->variant_balance_51bd = (int)(int16_t)new_balance; signed_balance = (int16_t)new_balance; if (signed_balance < 0) { uint16_t magnitude = (uint16_t)(0U - (uint16_t)signed_balance); uint16_t screen_extent = (uint16_t)wl->screen_extent_4741; uint16_t limit_candidate = magnitude; result.negative_balance = true; result.overflow_amount = magnitude; wl->status_extend_4976 |= 0x02U; if (magnitude < screen_extent && (wl->record_variant_gate_51c8 == 0 || (limit_candidate = (uint16_t)(delta + 1U), limit_candidate < screen_extent))) { if ((wl->status_dirty_flags & 0x20U) == 0U) { wl->variant_limit_c664 = (int)(int16_t)limit_candidate; wl->status_dirty_flags |= 0x20U; result.variant_limit_updated = true; } wl->status_extend_4976 = 0U; result.far_refresh_would_run = true; } else { wl->status_dirty_flags |= 0x40U; result.variant_limit_overflowed = true; } wl->status_dirty_flags |= 0x08U; } wp_layout_balance_snapshot_after(wl, &result); *out_result = result; return true; } bool wp_layout_reset_variant_total_and_update_dirty_flags(WpLayoutGlobals *wl, WpLayoutVariantBalanceResult *out_result) { WpLayoutVariantBalanceResult result; WpLayoutVariantBalanceResult branch; int16_t old_total; uint16_t transfer; uint16_t gate_candidate; if (out_result != NULL) { memset(out_result, 0, sizeof(*out_result)); } if (wl == NULL || out_result == NULL) { return false; } memset(&result, 0, sizeof(result)); wp_layout_balance_snapshot_before(wl, &result); result.reset_total = true; old_total = (int16_t)(uint16_t)wl->variant_total; wl->variant_total = 0; if (old_total >= 0) { transfer = (uint16_t)old_total; if (wp_layout_update_variant_balance_and_flags(wl, transfer, &branch)) { result.add_path = true; result.delta = branch.delta; result.screen_extent_minus_one = branch.screen_extent_minus_one; result.overflow_amount = branch.overflow_amount; result.balance_clamped_to_screen = branch.balance_clamped_to_screen; result.heap_borrowed = branch.heap_borrowed; result.far_refresh_would_run = branch.far_refresh_would_run; result.secondary_probe_would_run = branch.secondary_probe_would_run; } gate_candidate = 0U; } else { transfer = (uint16_t)(0U - (uint16_t)old_total); if (wp_layout_subtract_from_heap_delta_and_variant_balance(wl, transfer, &branch)) { result.subtract_path = true; result.delta = branch.delta; result.overflow_amount = branch.overflow_amount; result.negative_balance = branch.negative_balance; result.variant_limit_updated = branch.variant_limit_updated; result.variant_limit_overflowed = branch.variant_limit_overflowed; result.far_refresh_would_run = branch.far_refresh_would_run; } gate_candidate = transfer; } wl->render_dirty_flags |= 0x01U; result.render_dirty_set = true; if (wl->record_variant_gate_51c8 != 0) { uint16_t candidate = (uint16_t)(gate_candidate + (uint16_t)wl->variant_balance_51bd); if (wl->variant_count == 0 && candidate < (uint16_t)wl->variant_limit_c664) { wl->variant_limit_c664 = (int)(int16_t)(uint16_t)(candidate + 1U); wl->status_dirty_flags |= 0x22U; result.variant_limit_updated = true; } else { wl->status_dirty_flags |= 0x40U; result.variant_limit_overflowed = true; } } wp_layout_balance_snapshot_after(wl, &result); *out_result = result; return true; } uint16_t wp_layout_line_start_align(const WpLayoutGlobals *wl) { if (wl == NULL || wl->restore_mode != 1) { return 0U; } if ((wl->restore_control_flags & 0x08U) != 0U) { return (uint16_t)((uint16_t)wl->default_span_a + 400U + (uint16_t)wl->default_span_b); } return 400U; } bool wp_layout_record_stream_position(const WpLayoutGlobals *wl, WpLayoutStreamPosition *out_position) { if (wl == NULL) { if (out_position != NULL) { memset(out_position, 0, sizeof(*out_position)); } return false; } return wp_layout_make_stream_position((uint16_t)wl->record_block_index, (uint16_t)wl->record_used_bytes, out_position); } bool wp_layout_secondary_stream_position(const WpLayoutGlobals *wl, WpLayoutStreamPosition *out_position) { if (wl == NULL) { if (out_position != NULL) { memset(out_position, 0, sizeof(*out_position)); } return false; } return wp_layout_make_stream_position((uint16_t)wl->secondary_record_block_index, (uint16_t)wl->secondary_record_used_bytes, out_position); } bool wp_layout_span_metric_side_effect_position(const WpLayoutGlobals *wl, WpLayoutStreamPosition *out_position) { if (wl == NULL) { if (out_position != NULL) { memset(out_position, 0, sizeof(*out_position)); } return false; } return wp_layout_make_stream_position((uint16_t)wl->scale_fixed_point_51c4, (uint16_t)wl->record_used_bytes, out_position); } bool wp_layout_delta_from_saved_record_offset(const WpLayoutGlobals *wl, WpLayoutStreamDelta *out_delta) { WpLayoutStreamDelta delta; uint16_t saved_low; uint16_t saved_high; if (out_delta != NULL) { memset(out_delta, 0, sizeof(*out_delta)); } if (wl == NULL || out_delta == NULL) { return false; } memset(&delta, 0, sizeof(delta)); if (!wp_layout_record_stream_position(wl, &delta.current)) { return false; } saved_low = (uint16_t)wl->record_stream_offset_low; saved_high = (uint16_t)wl->record_stream_offset_high; delta.saved_low_word = saved_low; delta.saved_high_word = saved_high; delta.low_borrow = saved_low < delta.current.low_word; delta.delta_low_word = (uint16_t)(saved_low - delta.current.low_word); delta.delta_high_word = (uint16_t)(saved_high - delta.current.high_word - (delta.low_borrow ? 1U : 0U)); delta.underflow = saved_high < delta.current.high_word || (uint16_t)(saved_high - delta.current.high_word) < (delta.low_borrow ? 1U : 0U); delta.delta_linear = (((uint32_t)delta.delta_high_word) << 16U) | (uint32_t)delta.delta_low_word; *out_delta = delta; return true; } int wp_layout_compare_stream_position(uint16_t high_word, uint16_t low_word, const WpLayoutStreamPosition *position) { if (position == NULL) { return 1; } if (high_word < position->high_word) { return -1; } if (high_word > position->high_word) { return 1; } if (low_word < position->low_word) { return -1; } if (low_word > position->low_word) { return 1; } return 0; } bool wp_layout_reset_cursor_aliases_variant_table(WpLayoutGlobals *wl, WpLayoutMeasuredSpanResetResult *out_result) { WpLayoutMeasuredSpanResetResult result; 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.old_cursor = (uint16_t)wl->measured_span_cursor; result.new_cursor = (uint16_t)wl->cursor; result.old_span_a = (uint16_t)wl->measured_span_a; result.old_span_b = (uint16_t)wl->measured_span_b; result.old_span_flags = wl->measured_span_flags; result.old_dirty_flags = wl->measured_span_dirty_flags; result.old_total_flags = wl->measured_span_total_flags; if ((uint16_t)wl->measured_span_cursor != (uint16_t)wl->cursor) { result.cursor_changed = true; if ((uint16_t)wl->measured_span_a < (uint16_t)wl->default_span_a) { wl->measured_span_a = wl->default_span_a; result.span_a_raised = true; if (wl->measured_span_dirty_flags != 0U) { wl->measured_span_dirty_flags |= 0x80U; result.dirty_flags_marked = true; } if (wl->measured_span_total_flags != 0U) { wl->measured_span_total_flags |= 0x80U; result.total_flags_marked = true; } } if ((uint16_t)wl->measured_span_b < (uint16_t)wl->default_span_b) { wl->measured_span_b = wl->default_span_b; result.span_b_raised = true; if (wl->measured_span_total_flags != 0U) { wl->measured_span_total_flags |= 0x80U; result.total_flags_marked = true; } } wl->measured_span_cursor = (undefined2)wl->cursor; wl->measured_span_flags &= 0xFEU; result.low_active_flag_cleared = (result.old_span_flags & 0x01U) != 0U; } result.new_span_a = (uint16_t)wl->measured_span_a; result.new_span_b = (uint16_t)wl->measured_span_b; result.new_span_flags = wl->measured_span_flags; result.new_dirty_flags = wl->measured_span_dirty_flags; result.new_total_flags = wl->measured_span_total_flags; *out_result = result; return true; } bool wp_layout_apply_heap_control_branch(WpLayoutGlobals *wl, WpLayoutHeapBranchResult *out_result) { WpLayoutHeapBranchResult result; 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.old_record_window_word = (uint16_t)wl->record_window_word_4b40; result.new_record_window_word = (uint16_t)wl->record_window_word_502d; result.old_line_start = (uint16_t)wl->line_start; result.old_line_extent = (uint16_t)wl->emit_record_line_extent; if ((uint16_t)wl->record_window_word_502d != (uint16_t)wl->record_window_word_4b40) { result.window_changed = true; wl->emit_record_line_extent = (uint16_t)wl->emit_record_scratch_5033; wl->line_start = (uint16_t)wl->emit_record_scratch_5031; wl->record_window_word_4b40 = wl->record_window_word_502d; result.measure_ran = wp_layout_measure_line_extent_dirty_heap(wl, 0x80U, false, 0U, &result.measure_result); } result.new_line_start = (uint16_t)wl->line_start; result.new_line_extent = (uint16_t)wl->emit_record_line_extent; *out_result = result; return true; } bool wp_layout_flush_measured_span_then_scale_width_q8(WpLayoutGlobals *wl, uint8_t fraction_q8, bool enforce_minimum_span, uint16_t span_basis, WpLayoutFlushSpanResult *out_result) { WpLayoutFlushSpanResult result; uint16_t saved_a; uint16_t saved_b; uint16_t scaled; if (out_result != NULL) { memset(out_result, 0, sizeof(*out_result)); } if (wl == NULL || out_result == NULL) { return false; } memset(&result, 0, sizeof(result)); saved_b = (uint16_t)wl->measured_span_b; saved_a = (uint16_t)wl->measured_span_a; wl->measured_span_b = 0U; wl->measured_span_a = 0U; result.spans_temporarily_cleared = true; scaled = wp_layout_scale_extent_by_fraction(wl, fraction_q8, enforce_minimum_span, span_basis); wl->measured_span_b = saved_b; wl->measured_span_a = saved_a; result.saved_span_a = saved_a; result.saved_span_b = saved_b; result.scaled_width = scaled; result.return_value = (int)(int16_t)scaled + wl->carry_width + (int)(int16_t)(uint16_t)wl->pending_offset; result.variant_gate_would_trap = wl->variant_count != 0 && ((wl->variant_runtime_flags & 0x02U) == 0U); *out_result = result; return true; } /* Function: layout_line_window_prepare @ 1000:1fff */ uint16_t __cdecl16near layout_line_window_prepare(WpLayoutGlobals *wl) { if (parser_consume_next_input_byte(wl) == 0xFFFFU) return 0xFFFFU; return parser_process_token_stream(wl); } /* Function: layout_emit_scratch_pack @ 1000:201a */ uint32_t __cdecl16near layout_emit_scratch_pack(WpLayoutGlobals *wl, uint8_t al, uint16_t dx) { uint16_t bVar4; if ((((wl->emit_flags & 2) != 0) && (al == 0xd || al == 0xb)) || (dx <= wl->measure_extent_50c8)) { layout_range_check_aux_return_ax(wl); layout_aux_word_increment(wl, al); bVar4 = parser_consume_next_input_byte(wl); if (bVar4 == 0xFFFFU) return ((uint32_t)wl->record_wide_temp_hi_4b28 << 16) | wl->record_wide_temp_lo_4b26; if (0xbf < (uint8_t)bVar4) { /* Packet append logic is modeled by the surrounding host helpers. */ } layout_record_wide_temp_lo_hi_route_stage_1(wl); wl->parse_depth_counter -= 1; return ((uint32_t)wl->record_wide_temp_hi_4b28 << 16) | wl->record_wide_temp_lo_4b26; } return (uint32_t)layout_line_window_prepare(wl); } /* Function: layout_measure_dirty_reconcile @ 1000:203c */ uint32_t __cdecl16near layout_measure_dirty_reconcile(WpLayoutGlobals *wl, uint8_t al) { uint16_t bVar1; bool bVar3; if (wl->restore_mode != 0) { bVar3 = wl->restore_mode < 4; al = scan_memory_stride_3_for_char(wl); if (!bVar3) { return parser_parse_and_append_command_token_variant(wl); } } bVar3 = al < 0xc0; if (bVar3) { LAB_1000_207c: layout_range_check_aux_return_ax(wl); if (!bVar3) goto LAB_1000_2089; } else { bVar3 = al < 0xd0; if (bVar3) goto LAB_1000_207c; bVar1 = (uint16_t)layout_range_check_aux_return_ax(wl); if (!bVar3) { bVar3 = (uint8_t)bVar1 < 0xde; if ((uint8_t)bVar1 == 0xde) goto LAB_1000_2089; goto LAB_1000_207c; } } LAB_1000_2089: bVar1 = parser_consume_next_input_byte(wl); if (bVar1 == 0xFFFFU) return ((uint32_t)wl->record_wide_temp_hi_4b28 << 16) | wl->record_wide_temp_lo_4b26; layout_record_wide_temp_lo_hi_route_stage_1(wl); wl->parse_depth_counter -= 1; return ((uint32_t)wl->record_wide_temp_hi_4b28 << 16) | wl->record_wide_temp_lo_4b26; } /* Function: layout_span_table_select @ 1000:2086 */ uint32_t __cdecl16near layout_span_table_select(WpLayoutGlobals *wl) { layout_emit_measure_line_iteration(wl); if (parser_consume_next_input_byte(wl) == 0xFFFFU) return ((uint32_t)wl->record_wide_temp_hi_4b28 << 16) | wl->record_wide_temp_lo_4b26; layout_record_wide_temp_lo_hi_route_stage_1(wl); wl->parse_depth_counter -= 1; return ((uint32_t)wl->record_wide_temp_hi_4b28 << 16) | wl->record_wide_temp_lo_4b26; } /* Function: layout_compact_init @ 1000:2109 */ uint32_t __cdecl16near layout_compact_init(WpLayoutGlobals *wl, uint8_t al) { if ((wl->runtime_flags & 1) == 0) { record_append_byte_under_position_gate(wl, al); } wl->record_wide_temp_lo_4b26 = al; layout_record_wide_temp_lo_hi_route_stage_1(wl); wl->parse_depth_counter -= 1; return ((uint32_t)wl->record_wide_temp_hi_4b28 << 16) | wl->record_wide_temp_lo_4b26; } /* Function: layout_capture_temp_lo_hi_then_decrement_psp_depth @ 1000:2116 */ uint32_t __cdecl16near layout_capture_temp_lo_hi_then_decrement_psp_depth(WpLayoutGlobals *wl) { layout_record_wide_temp_lo_hi_route_stage_1(wl); wl->parse_depth_counter -= 1; return ((uint32_t)wl->record_wide_temp_hi_4b28 << 16) | wl->record_wide_temp_lo_4b26; } void __cdecl16near layout_record_wide_temp_lo_hi_route_stage_1(WpLayoutGlobals *wl) { wl->record_wide_temp_lo_4b26 = (uint16_t)wl->cursor; wl->record_wide_temp_hi_4b28 = (uint16_t)wl->carry_width; } uint32_t __cdecl16near layout_add_compact_metric_delta(WpLayoutGlobals *wl, uint16_t delta_high, uint16_t delta_low) { uint32_t base; uint16_t lo; uint16_t hi; (void)delta_high; (void)delta_low; base = ((uint32_t)wl->secondary_record_block_index << 11); lo = (uint16_t)base; hi = (uint16_t)(base >> 16); lo = (uint16_t)(lo + (uint16_t)wl->secondary_record_used_bytes); hi = (uint16_t)(hi + (uint16_t)ghidra_carry2((uint16_t)base, (uint16_t)wl->secondary_record_used_bytes)); return (((uint32_t)hi << 16) | lo); } uint32_t __cdecl16near layout_cursor_extent_clamp(WpLayoutGlobals *wl) { uint32_t offset; uint32_t limit; offset = layout_add_compact_metric_delta(wl, 0, 0); limit = ((uint32_t)wl->position_gate_remaining_high << 16) | wl->position_gate_remaining_low; while (offset <= limit) { uint8_t code = parser_consume_next_input_byte(wl); if (wl->record_used_bytes <= 0) { break; } if (code == 0) { break; } (void)parser_process_token_stream(wl); offset = layout_add_compact_metric_delta(wl, 0, 0); } return offset; } void __cdecl16near layout_measure_line_extent_dirty_heap(WpLayoutGlobals *wl) { uint16_t extent = (uint16_t)wl->emit_record_line_extent; uint16_t scaled = (uint16_t)((extent > wl->line_start) ? (extent - wl->line_start) : 0); scaled = (uint16_t)(((uint32_t)scaled * (wl->span_scale_q8_5039 & 0xff)) >> 8); if (scaled == 0) { scaled = 1; } wl->measure_extent_50c8 = extent + scaled; wl->measure_extent_bound_50c6 = wl->measure_extent_50c8; wl->render_dirty_flags |= 8; if ((wl->heap_control_flags_4bf1 & 1) != 0) { uint16_t cap = (uint16_t)(wl->record_accum_cap_4c4a + wl->measure_extent_50c8); if (cap < wl->measure_extent_50c8) { cap = wl->measure_extent_50c8; } wl->measure_extent_50c8 = cap; } } void __cdecl16near layout_record_wide_temp_lo_hi_route_stage_3(WpLayoutGlobals *wl, bool *bVar2) { wl->record_wide_temp_lo_4b26 = (uint16_t)wl->cursor; wl->record_wide_temp_hi_4b28 = (uint16_t)wl->carry_width; if (bVar2) { *bVar2 = (wl->cursor >= wl->line_start); } } void __cdecl16near layout_metric_word_adjust(WpLayoutGlobals *wl) { int delta = layout_get_active_span_total_width(wl); wl->metrics_line_accum_5037 += (delta >> 2); wl->variant_total -= (delta >> 3); if (wl->metrics_line_accum_5037 <= 0) { wl->metrics_line_accum_5037 = 1; } }
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