Skip to content

Commit 8ee6171

Browse files
author
dennis
committed
Manually decompiled parts of function_10001718(). I keep these changes
for maybe later use. It was found that retdec decompiles the code containing FDIVR opcode the wrong way around... See avast/retdec#293.
1 parent 3871671 commit 8ee6171

File tree

1 file changed

+102
-31
lines changed

1 file changed

+102
-31
lines changed

src/morrow/sa.c

+102-31
Original file line numberDiff line numberDiff line change
@@ -616,24 +616,30 @@ int32_t function_10001718(SET9052 *a1) {
616616
float64_t v3 = a1->stop;
617617
int32_t v4 = g11 - 1; // 0x1000174e
618618
float64_t v5 = a1->start;
619+
#ifdef ORIG
620+
// Next line gives negative value; after examining with IDA, I assume decompiled wrong.
619621
float64_t v6 = (float80_t) v5 - (float80_t) v3; // 0x10001754
622+
#else
623+
float64_t v6 = (float80_t) v3 - (float80_t) v5;
624+
#endif
620625
// DD: a1 is a pointer; what does 'a1&256' mean???
621626
// maybe, a1 = a1+0 = a1->op_mode ...
622627
// but what is with pointer dereference
623628
// i.e. there is no dereferencing, so it looks like being used as a pointer after all...
624629
if (/*((int32_t) a1 & 256)*/a1->op_mode == 0) {
625-
int32_t *v7 = &a1->deflt_pt_cnt;
626-
int32_t *v8 = &a1->num_swp_pts;
627-
*v8 = *v7;
628-
int32_t *v9 = &a1->num_step_pts;
629-
*v9 = *v7;
630+
int32_t *deflt_pt_cntPtr = &a1->deflt_pt_cnt;
631+
int32_t *num_swp_ptsPtr = &a1->num_swp_pts;
632+
*num_swp_ptsPtr = *deflt_pt_cntPtr;
633+
int32_t *num_step_ptsPtr = &a1->num_step_pts;
634+
*num_step_ptsPtr = *deflt_pt_cntPtr;
630635
g8 = a1;
631636
int16_t step_mode = a1->step_mode;
632637
if (step_mode != MR90XX_AUTO_ON /*1*/) {
638+
#ifdef ORIG
633639
if (step_mode == MR90XX_STEPCNT /*2*/) {
634-
int32_t v11 = *v9; // 0x10001aaa
640+
//int32_t v111 = *num_step_ptsPtr; // 0x10001aaa
635641
g8 = a1;
636-
a1->step = (float64_t) ((float80_t) (v11 - 1) / (float80_t) v6);
642+
a1->step = (float64_t) ((float80_t) (*num_step_ptsPtr - 1) / (float80_t) v6);
637643
if (a1->auto_rbw /* *(int16_t *)(a1 + 74)*/== MR90XX_AUTO_ON /*1*/) {
638644
setup_rbw(a1);
639645
}
@@ -645,9 +651,9 @@ int32_t function_10001718(SET9052 *a1) {
645651
if (step_mode == MR90XX_STEPSIZ /*3*/) {
646652
g11 = v4;
647653
int32_t v12 = __ftol((int32_t) step_mode) + 1; // 0x10001a57
648-
*v9 = v12;
654+
*num_step_ptsPtr = v12;
649655
g8 = v12;
650-
*v8 = v12;
656+
*num_swp_ptsPtr = v12;
651657
if (a1->auto_rbw /* *(int16_t *)(a1 + 74)*/== MR90XX_AUTO_ON /*1*/) {
652658
setup_rbw(a1);
653659
}
@@ -662,15 +668,28 @@ int32_t function_10001718(SET9052 *a1) {
662668
(float80_t) a1->step /* *(float64_t *)(a1 + 24)*/;
663669
g4 = v1;
664670
return (int32_t) a1 & -0x10000;
671+
#else
672+
if (a1->auto_rbw != MR90XX_AUTO_ON /*1*/) {
673+
if (a1->auto_vbw == MR90XX_AUTO_ON /*1*/) {
674+
setup_vbw(a1);
675+
}
676+
} else {
677+
setup_rbw(a1);
678+
}
679+
#endif
665680
}
681+
682+
#ifdef ORIG
666683
if (a1->auto_rbw /* *(int16_t *)(a1 + 74)*/!= MR90XX_AUTO_ON /*1*/) {
667684
if (a1->auto_vbw /* *(int16_t *)(a1 + 78) */== MR90XX_AUTO_ON /*1*/) {
668685
setup_vbw(a1);
669686
}
670687
} else {
671688
setup_rbw(a1);
672689
}
690+
#endif
673691
int16_t *cell_modePtr;
692+
#ifdef ORIG
674693
if (a1->auto_cell /* *(int16_t *)(a1 + 66) */!= MR90XX_AUTO_ON) {
675694
cell_modePtr = &a1->cell_mode; // (int16_t *)(a1 + 64);
676695
} else {
@@ -688,7 +707,60 @@ int32_t function_10001718(SET9052 *a1) {
688707
cell_modePtr = v14;
689708
}
690709
}
710+
#else
711+
if (a1->auto_cell != MR90XX_AUTO_ON) {
712+
} else {
713+
int16_t *v14 = &a1->cell_mode;
714+
if (*v14 == IE_FALSE) {
715+
float64_t var18 = v6 / (*deflt_pt_cntPtr - 1.0); // fdivr error in decompiler
716+
int32_t v15 = GetRBWwide(RBW_3MHZ /*4*/);
717+
float64_t var188 = v15 / 3;
718+
if (var188 != var18) {
719+
SetCellMode(a1, 1);
720+
}
721+
}
722+
}
723+
if (*cell_modePtr != IE_TRUE) { // loc_1000183F
691724

725+
} else {
726+
int32_t v24 = GetRBWwide(a1->rbw_code);
727+
float64_t v25 = v24/3;
728+
float64_t *v26 = &a1->step;
729+
*v26 = (float64_t) v25;
730+
float80_t v27 = v6;
731+
float80_t var277 = v6 / v25 + 1.0;
732+
int32_t v28 = __ftol(var277);
733+
*num_step_ptsPtr = v28;
734+
int32_t *v29 = &a1->num_cells; // (int32_t *)(a1 + 132); // 0x1000189c
735+
if (v28 < *v29) {
736+
int32_t v30 = *v29; // 0x100018aa
737+
int32_t v30 = *v29; // 0x100018aa
738+
*num_step_ptsPtr = v30;
739+
float80_t var301 = v6 / (v30 - 1);
740+
a1->step = var301;
741+
}
742+
*num_swp_ptsPtr = *num_step_ptsPtr;
743+
g8 = a1;
744+
if (IsValidStep(a1) != 0x1) {
745+
int32_t v31 = *num_step_ptsPtr; // 0x100018fa
746+
*num_step_ptsPtr = v31 + 10;
747+
float64_t var288 = v6 / (*num_step_ptsPtr - 1);
748+
a1->step = var288;
749+
750+
int32_t v32 = IsValidStep(a1);
751+
while (v32 != 1) {
752+
v31 = *num_step_ptsPtr;
753+
*num_step_ptsPtr = v31 + 10;
754+
float64_t var288 = v6 / (*num_step_ptsPtr - 1);
755+
a1->step = var288;
756+
}
757+
function_10001b13(a1); // 1a38
758+
}
759+
}
760+
if (a1->step == 1.0) { // 1af2
761+
result = 0xffff;
762+
}
763+
#endif
692764
if (*cell_modePtr != IE_TRUE) {
693765
int32_t v16 = GetRBWwide(a1->rbw_code /* *(int16_t *)(a1 + 72) */); // 0x10001948
694766
int32_t v17 = (0x100000000 * (int64_t) (v16 >> 31) | (int64_t) v16)
@@ -698,26 +770,26 @@ int32_t function_10001718(SET9052 *a1) {
698770
float80_t v19 = v6; // 0x10001967
699771
g11--;
700772
int32_t v20 = __ftol(v17); // 0x10001973
701-
*v9 = v20;
702-
if (v20 < *v7) {
703-
int32_t v21 = *v7; // 0x10001998
704-
*v9 = v21;
773+
*num_step_ptsPtr = v20;
774+
if (v20 < *deflt_pt_cntPtr) {
775+
int32_t v21 = *deflt_pt_cntPtr; // 0x10001998
776+
*num_step_ptsPtr = v21;
705777
*v18 = (float64_t) ((float80_t) (v21 - 1) / v19);
706778
}
707-
*v8 = *v9;
779+
*num_swp_ptsPtr = *num_step_ptsPtr;
708780
g8 = a1;
709781
if (0x10000 * IsValidStep(a1) != 0x10000) {
710-
int32_t v22 = *v9 + 10; // 0x100019eb
711-
*v9 = v22;
712-
*v8 = v22;
713-
*v18 = (float64_t) ((float80_t) (*v9 - 1) / v19);
782+
int32_t v22 = *num_step_ptsPtr + 10; // 0x100019eb
783+
*num_step_ptsPtr = v22;
784+
*num_swp_ptsPtr = v22;
785+
*v18 = (float64_t) ((float80_t) (*num_step_ptsPtr - 1) / v19);
714786
int32_t v23 = 0x10000 * IsValidStep(a1); // 0x10001a30
715787
g8 = v23 / 0x10000;
716788
while (v23 != 0x10000) {
717-
v22 = *v9 + 10;
718-
*v9 = v22;
719-
*v8 = v22;
720-
*v18 = (float64_t) ((float80_t) (*v9 - 1) / v19);
789+
v22 = *num_step_ptsPtr + 10;
790+
*num_step_ptsPtr = v22;
791+
*num_swp_ptsPtr = v22;
792+
*v18 = (float64_t) ((float80_t) (*num_step_ptsPtr - 1) / v19);
721793
v23 = 0x10000 * IsValidStep(a1);
722794
g8 = v23 / 0x10000;
723795
}
@@ -728,31 +800,30 @@ int32_t function_10001718(SET9052 *a1) {
728800
}
729801
} else {
730802
int32_t v24 = GetRBWwide(a1->rbw_code /* *(int16_t *)(a1 + 72) */); // 0x10001857
731-
int32_t v25 = (0x100000000 * (int64_t) (v24 >> 31) | (int64_t) v24)
732-
/ 3; // 0x10001865
803+
int32_t v25 = v24/3; // (0x100000000 * (int64_t) (v24 >> 31) | (int64_t) v24) / 3; // 0x10001865
733804
float64_t *v26 = &a1->step; // (float64_t *)(a1 + 24); // 0x10001870
734805
*v26 = (float64_t) v25;
735806
float80_t v27 = v6; // 0x10001876
736807
g11--;
737808
int32_t v28 = __ftol(v25); // 0x10001882
738-
*v9 = v28;
809+
*num_step_ptsPtr = v28;
739810
int32_t *v29 = &a1->num_cells; // (int32_t *)(a1 + 132); // 0x1000189c
740811
if (v28 < *v29) {
741812
int32_t v30 = *v29; // 0x100018aa
742-
*v9 = v30;
813+
*num_step_ptsPtr = v30;
743814
*v26 = (float64_t) ((float80_t) (v30 - 1) / v27);
744815
}
745-
*v8 = *v9;
816+
*num_swp_ptsPtr = *num_step_ptsPtr;
746817
g8 = a1;
747818
if (0x10000 * IsValidStep(a1) != 0x10000) {
748-
int32_t v31 = *v9; // 0x100018fa
749-
*v9 = v31 + 10;
819+
int32_t v31 = *num_step_ptsPtr; // 0x100018fa
820+
*num_step_ptsPtr = v31 + 10;
750821
*v26 = (float64_t) ((float80_t) (v31 + 9) / v27);
751822
int32_t v32 = 0x10000 * IsValidStep(a1); // 0x10001933
752823
g8 = v32 / 0x10000;
753824
while (v32 != 0x10000) {
754-
v31 = *v9;
755-
*v9 = v31 + 10;
825+
v31 = *num_step_ptsPtr;
826+
*num_step_ptsPtr = v31 + 10;
756827
*v26 = (float64_t) ((float80_t) (v31 + 9) / v27);
757828
v32 = 0x10000 * IsValidStep(a1);
758829
g8 = v32 / 0x10000;

0 commit comments

Comments
 (0)