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_format_table.c
File editor
#include "wp_format_table.h" #include <stdio.h> #include <string.h> /* Missing symbols stubs */ void __cdecl16far engine_far_call_8fdb(uint16_t seg) { (void)seg; } void __cdecl16far engine_far_call_4ca6(void) {} void __cdecl16near engine_far_call_4c9d(void) {} void __cdecl16near format_main_hypervisor_table_loop(uint16_t seg) { (void)seg; } void __cdecl16far format_divide_normalize_state_slots(void) {} void __cdecl16near format_jump_route_step(void) {} uint16_t __cdecl16near format_no_op_return_immediate(void); void __cdecl16near format_byte_flag_route_step(void); void __cdecl16near overlay_early_startup_vector_table(uint16_t segment); /* Thunk: route_format_no_op_body_return @ 2000:4a79 */ int __cdecl16near route_format_no_op_body_return(void) { return (int)format_no_op_return_immediate(); } /* Thunk: route_format_byte_flag_branch @ 2000:4a7c */ uint16_t __cdecl16near route_format_byte_flag_branch(void) { format_byte_flag_route_step(); return 1U; } uint16_t __cdecl16near format_no_op_return_immediate(void) { /* Explicit decompiler-compatible adapter: historical non-zero path. */ return 1U; } void __cdecl16near format_byte_flag_route_step(void) { /* Host-safe adapter preserving control-flow shape for this thunk path. */ overlay_early_startup_vector_table(0x1000U); } static uint16_t wp_format_table_le16(const uint8_t *p) { return (uint16_t)((uint16_t)p[0] | ((uint16_t)p[1] << 8)); } void wp_format_table_clear(WpFormatTableInfo *table) { if (table != NULL) { memset(table, 0, sizeof(*table)); } } bool wp_format_table_decode_payload(const uint8_t *payload, uint16_t payload_length, uint8_t sub_code, WpFormatTableInfo *out_table) { WpFormatTableInfo table; size_t i; bool in_group = false; size_t current_group_words = 0U; bool have_previous_in_group = false; uint16_t previous_in_group = 0U; wp_format_table_clear(out_table); if (payload == NULL || out_table == NULL) { return false; } memset(&table, 0, sizeof(table)); table.is_present = true; table.sub_code = sub_code; table.payload_bytes = payload_length; table.word_count = payload_length / 2U; table.odd_payload_byte = (payload_length & 1U) != 0U; if (table.odd_payload_byte) { table.odd_payload_tail = payload[payload_length - 1U]; } for (i = 0U; i < table.word_count; ++i) { uint16_t value = wp_format_table_le16(payload + i * 2U); if (table.stored_word_count < WP_FORMAT_TABLE_MAX_STORED_WORDS) { table.stored_words[table.stored_word_count++] = value; } if (value == 0xFFFFU) { table.sentinel_word_count++; if (in_group) { if (current_group_words > table.longest_group_words) { table.longest_group_words = current_group_words; } current_group_words = 0U; in_group = false; have_previous_in_group = false; } continue; } table.usable_word_count++; if (value == 0U) { table.zero_word_count++; } if (!in_group) { table.group_count++; in_group = true; current_group_words = 0U; have_previous_in_group = false; } current_group_words++; if (!table.has_values) { table.has_values = true; table.first_value_index = (uint16_t)i; table.first_value = value; table.min_value = value; table.max_value = value; } else { if (value < table.min_value) { table.min_value = value; } if (value > table.max_value) { table.max_value = value; } } table.last_value_index = (uint16_t)i; table.last_value = value; if (have_previous_in_group) { if (value < previous_in_group) { table.nonmonotonic_step_count++; } else if (value > previous_in_group) { uint16_t step = (uint16_t)(value - previous_in_group); if (!table.has_positive_step) { table.has_positive_step = true; table.first_positive_step = step; table.min_positive_step = step; table.max_positive_step = step; } else { if (step < table.min_positive_step) { table.min_positive_step = step; } if (step > table.max_positive_step) { table.max_positive_step = step; } } table.positive_step_count++; } } previous_in_group = value; have_previous_in_group = true; } if (in_group && current_group_words > table.longest_group_words) { table.longest_group_words = current_group_words; } *out_table = table; return true; } bool wp_format_table_decode_record(const WpRecord *rec, WpFormatTableInfo *out_table) { wp_format_table_clear(out_table); if (rec == NULL || rec->type != WP_CODE_VARIABLE_LENGTH || rec->code != 0xD0U) { return false; } if (rec->data == NULL && rec->data_length != 0U) { return false; } return wp_format_table_decode_payload(rec->data, rec->data_length, rec->sub_code, out_table); } uint16_t wp_format_table_recommended_span_step(const WpFormatTableInfo *table) { if (table == NULL || !table->has_positive_step) { return 0U; } return table->first_positive_step; } bool wp_format_table_describe(const WpFormatTableInfo *table, char *out, size_t out_size) { if (out == NULL || out_size == 0U) { return false; } out[0] = '\0'; if (table == NULL || !table->is_present) { return false; } if (table->has_values) { snprintf(out, out_size, "format-table words=%lu groups=%lu sentinels=%lu zeros=%lu first[%u]=%u last[%u]=%u max=%u step=%u nonmono=%lu odd=%s", (unsigned long)table->word_count, (unsigned long)table->group_count, (unsigned long)table->sentinel_word_count, (unsigned long)table->zero_word_count, (unsigned)table->first_value_index, (unsigned)table->first_value, (unsigned)table->last_value_index, (unsigned)table->last_value, (unsigned)table->max_value, (unsigned)wp_format_table_recommended_span_step(table), (unsigned long)table->nonmonotonic_step_count, table->odd_payload_byte ? "yes" : "no"); } else { snprintf(out, out_size, "format-table words=%lu groups=0 sentinels=%lu odd=%s", (unsigned long)table->word_count, (unsigned long)table->sentinel_word_count, table->odd_payload_byte ? "yes" : "no"); } return true; } /* Ported Segment 2000 functions */ void __cdecl16far format_run_stream_table_main_loop(WpLayoutGlobals *wl, uint16_t *unaff_SI) { int16_t *piVar1; int iVar2; int16_t *piVar3; bool bVar4; if ((wl->stream_state_b9c6 == -1) && (wl->stream_type_char_b9c3 == 0x01)) { engine_far_call_8fdb(0x1000); } else { if ((wl->table_type_char_c53f == 'd') && (bVar4 = false, (wl->stream_flags_c546 & 1) != 0)) { format_main_hypervisor_table_loop(0x1000); if (!bVar4) { return; } wl->stream_flags_c546 &= 0xFFFE; } engine_far_call_4ca6(); while (*(int16_t *)unaff_SI != 0) { iVar2 = (int)*(int16_t *)unaff_SI - 1; piVar1 = (int16_t *)unaff_SI + 1; do { piVar3 = piVar1; wl->bresenham_p1_c3ce = *piVar3; wl->bresenham_p2_c3d0 = piVar3[1]; wl->bresenham_p3_c3d2 = piVar3[2]; wl->bresenham_p4_c3d4 = piVar3[3]; format_bresenham_line_step_core(wl, (uint16_t *)&wl->bresenham_p1_c3ce); iVar2--; piVar1 = piVar3 + 2; } while (iVar2 != 0); unaff_SI = (uint16_t *)(piVar3 + 4); } } } void __cdecl16near format_bresenham_line_step_core(WpLayoutGlobals *wl, uint16_t *unaff_SI_in) { int16_t *piVar1; bool bVar2; int iVar3; int iVar4; uint32_t uVar5; uint32_t uVar6; int iVar7; int16_t uVar8; int iVar9; int16_t *unaff_SI = (int16_t *)unaff_SI_in; int16_t *piVar10; /* Stack frame simulation */ int16_t step_index_1a = 1; /* BP - 0x1a */ int16_t dx_26; /* BP - 0x26 */ int16_t sx_22; /* BP - 0x22 */ int16_t dy_24; /* BP - 0x24 */ int16_t sy_20; /* BP - 0x20 */ int16_t err_1c; /* BP - 0x1c */ int16_t err2_1e; /* BP - 0x1e */ int16_t in_stack_0 = 0; /* Simulation for in_stack_00000000 if needed */ iVar4 = unaff_SI[1]; if (iVar4 == unaff_SI[3]) { format_divide_normalize_state_slots(); return; } if (unaff_SI[0] == unaff_SI[2]) { engine_far_call_4c9d(); return; } iVar3 = unaff_SI[2] - unaff_SI[0]; uVar8 = 1; if (iVar3 < 0) { uVar8 = -1; iVar3 = -iVar3; } dx_26 = (int16_t)iVar3; sx_22 = uVar8; iVar4 = unaff_SI[3] - iVar4; uVar8 = 1; if (iVar4 < 0) { uVar8 = -1; iVar4 = -iVar4; } dy_24 = (int16_t)iVar4; sy_20 = uVar8; if (dx_26 <= dy_24) { err_1c = dx_26 << 1; err2_1e = dy_24 << 1; err2_1e = err_1c - err2_1e; iVar4 = (int)err_1c - (int)dy_24; while (step_index_1a <= dy_24) { format_jump_route_step(); if (iVar4 < 1) { iVar3 = (int)err_1c; } else { iVar3 = (int)err2_1e; } iVar4 += iVar3; step_index_1a++; } format_jump_route_step(); return; } piVar10 = unaff_SI; if (sx_22 < 0) { piVar10 = (int16_t *)&wl->bresenham_aux_c3c6; iVar4 = unaff_SI[0]; wl->bresenham_aux_c3c6 = unaff_SI[2]; wl->bresenham_aux_c3ca = (int16_t)iVar4; iVar4 = unaff_SI[1]; iVar3 = unaff_SI[3]; wl->bresenham_aux_c3c8 = (int16_t)iVar3; wl->bresenham_aux_c3cc = (int16_t)iVar4; if (iVar3 < iVar4) { sy_20 = 1; } else { sy_20 = -1; } } if (dy_24 < (int16_t)((uint16_t)dx_26 >> 2)) { uVar5 = (uint32_t)(uint16_t)dx_26 / (uint32_t)(uint16_t)dy_24; uVar6 = (uint32_t)(uint16_t)dx_26 % (uint32_t)(uint16_t)dy_24; } else { uVar5 = 0; uVar6 = (uint32_t)(uint16_t)dx_26; do { uVar5++; uVar6 -= (uint32_t)(uint16_t)dy_24; } while ((uint32_t)(uint16_t)dy_24 <= uVar6); } err2_1e = (int16_t)uVar6; step_index_1a = (int16_t)uVar5; iVar4 = (int)(uVar5 >> 1) + 1; err_1c = dy_24; iVar3 = piVar10[1]; iVar9 = piVar10[0]; do { while (1) { dx_26 -= (int16_t)iVar4; format_divide_normalize_state_slots(); iVar7 = iVar4 + iVar9 + (int)sy_20; piVar1 = &err_1c; *piVar1 -= err2_1e; iVar9 = (int)in_stack_0; /* Not fully clear what in_stack_0 was meant to be, using 0 as fallback */ if (*piVar1 < 0) break; iVar4 = (int)step_index_1a; bVar2 = iVar3 == 1; iVar3 = iVar7; if (bVar2) goto LAB_2000_1e64; } err_1c += dy_24; iVar4 = (int)step_index_1a + 1; bVar2 = iVar3 != 1; iVar3 = iVar7; } while (bVar2); LAB_2000_1e64: format_divide_normalize_state_slots(); } void __cdecl16near format_rectangle_compact_initialize(WpLayoutGlobals *wl) { format_word_pair_stride_walk_loop(wl); if (wl->heap_cursor_c5b4 < (uint32_t)wl->heap_extent_c5ae) { wl->heap_cursor_c5b4 = (uint32_t)wl->heap_extent_c5ae; } } uint16_t __cdecl16near format_word_pair_stride_walk_loop(WpLayoutGlobals *wl) { int iVar1; uint16_t uStack_4 = 0; iVar1 = route_format_no_op_body_return(); if (((uint32_t)wl->heap_extent_c5ae < wl->metrics_window_limit_50bc) && (wl->metrics_window_base_50ba < (uint32_t)wl->heap_extent_c5ae + (uint32_t)iVar1)) { uStack_4 = route_format_byte_flag_branch(); } wl->heap_extent_c5ae += iVar1; return uStack_4; }
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