summaryrefslogtreecommitdiffstats
path: root/private/mvdm/wow16/write/format.asm
blob: 631adb45210f9e0498ff86b973a299b91385ff1f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
;* ****************************************************************************
;*
;*      COPYRIGHT (C) 1985-1992 MICROSOFT
;*
;* ****************************************************************************
;
        TITLE    Format.asm line formatting routines for windows Write
;  Module: format.asm
;     contains native code versions of FormatLine, Justify, FGrowFormatHeap,
;         FFirstIch, DxpFromCh, and ValidateMemoryDC
;
;*
;* REVISION HISTORY
;*
;* Date         Who Rel Ver     Remarks
;* 5/23/85      bz              initial translation from c
;* 6/21/85      bl              Set ?WIN == 0 for windows header
;* 7/09/85      pnt             Call WinFailure() if vhMDC == NULL
;* 7/16/85      pnt             Truncate tabs at right margin
;* 7/21/85      pnt             Treat running heads like normal paragraphs
;* 7/30/85      bl              Fixed bug in FFirstIch -- change scasb to scasw
;* 8/05/85      pnt             Added ValidateMemoryDC()
;* 8/05/85      pnt             DxpFromCh returns dxpSpace if ch < space
;* 8/07/85      pnt             cchCHPUsed changed from 9 to 7
;* 8/09/85      pnt             Ensure there tabs don't back up on the screen
;* 8/14/85      pnt             Map center and right tabs to left tabs
;* 8/27/85	pnt		Single spacing changed to font leading only
;* 8/29/85	pnt		Lines with no breaks can be right, center flush
;* 10/01/85	pnt		Forced section mark to be in stardard font
;* 10/07/85	pnt		DxpFromCh returns dxpSpace iff width unimportant
;* 10/10/85	pnt		Validity of vfli cache depends on flm
;* 10/10/85	pnt		fPrevSpace not set for null runs
;* 10/30/89 pault   set code to use SYSENDMARK code in FORM1.C
;* (7.23.91)    v-dougk         changed dxp char arrays to int arrays
SYSENDMARK EQU 1
;*
;* ************************************************************************* */

;* ************************************************************************* */
;          Naming conventions used here
;
;       rxx_name   register variable - reg is xx. This may be a temporary naming
;                       of a register (e.g. rax_ichT)
;       c_name     defined constant in c program (e.g. c_false)
;
;* ************************************************************************* */
        subttl Conditional variables and cmacros
        page

; *************** Conditional variables *************************
; ***** These variables should be defined using the -D command line
; ***** option in masm. They are only checked for being defined, not
; ***** for a particular value
;
; DEBUG   define with   -DDEBUG ; ** controls ASSERT code **
; SCRIBBLE  define with -DSCRIBBLE ; ** controls SCRIBBLE code **
; CASHMERE ; ** code taken out for Write, to be used for Cashmere **
;
; ***************  End conditional variables *************************

        memM =   1     ; medium model for cmacros
        ?WIN    = 1    ; windows header used here
        .xlist
        include cmacros.inc
        page
        .list
        ;.sall
        createSeg FORM1_TEXT,FORM1_TEXT,BYTE,PUBLIC,CODE

        ASSUME  CS: FORM1_TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP

        subttl Public definitions
        page
;
;   Public definitions for this module
;
PUBLIC  DxpFromCh
PUBLIC  FormatLine
PUBLIC  Justify
PUBLIC  FGrowFormatHeap
PUBLIC  FFirstIch
PUBLIC  ValidateMemoryDC

;
;   External procedures referenced from this module
;

EXTRN   IMAX:FAR
EXTRN   CCHDIFFER:FAR
EXTRN   CACHESECT:FAR
EXTRN   FCHNGSIZEH:FAR
EXTRN   CACHEPARA:FAR
EXTRN   FORMATGRAPHICS:FAR
EXTRN   FFORMATSPECIALS:FAR
EXTRN   MULTDIV:FAR
EXTRN   FETCHCP:FAR
EXTRN   SETTEXTJUSTIFICATION:FAR
EXTRN   GETTEXTEXTENT:FAR
EXTRN   LOADFONT:FAR
EXTRN   WINFAILURE:FAR
EXTRN   GETDEVICECAPS:FAR
EXTRN   SETBKMODE:FAR
EXTRN   SETTEXTCOLOR:FAR
EXTRN   CREATECOMPATIBLEDC:FAR
EXTRN	GETPRINTERDC:FAR

        ; **** Debugging code **********
IFDEF DEBUG
IFDEF SCRIBBLE
EXTRN   FNSCRIBBLE:FAR
ENDIF
ENDIF


        subttl External definitions
        page
;
;   External definitions referenced from this module
;
        sBegin DATA

EXTRN   PLOCALHEAP:WORD
;EXTRN   DOCHELP:WORD
EXTRN   VFLI:BYTE
EXTRN   VHGCHPFORMAT:WORD
EXTRN   ICHPMACFORMAT:WORD
EXTRN   VCHPABS:BYTE
EXTRN   VPAPABS:BYTE
EXTRN   VSEPABS:BYTE
EXTRN   VSEPPAGE:BYTE
EXTRN   VCHPNORMAL:BYTE
EXTRN   VCPFIRSTPARACACHE:DWORD
EXTRN   VCPFETCH:DWORD
EXTRN   YPSUBSUPER:WORD
EXTRN   VPCHFETCH:WORD
EXTRN   VCCHFETCH:WORD
EXTRN   YPSUBSUPERPR:WORD
EXTRN   VHMDC:WORD
EXTRN   VHDCPRINTER:WORD
EXTRN   DXPLOGINCH:WORD
EXTRN   DYPLOGINCH:WORD
EXTRN   DXAPRPAGE:WORD
EXTRN   DYAPRPAGE:WORD
EXTRN   DXPPRPAGE:WORD
EXTRN   DYPPRPAGE:WORD
EXTRN   DYPMAX:WORD
EXTRN   VFMISCREEN:BYTE
EXTRN   VFMIPRINT:BYTE
EXTRN   VFOUTOFMEMORY:WORD
EXTRN   VFMONOCHROME:WORD
EXTRN   RGBTEXT:DWORD
EXTRN   PWWDCUR:WORD
EXTRN   VCHDECIMAL:BYTE
EXTRN   VZATABDFLT:BYTE
        sEnd DATA

        ;sBegin BSS
        sBegin DATA
$S784_ichpFormat        DB 02H DUP (?)
        EVEN
        sEnd DAT
        ;sEnd BSS

        subttl Macros
        page
; ********************************************************************
; macros done here for speed, rather than doing far procedure call

;-----------------------------------------------------------------------------
; bltc (pTo, wFill, cw) - fills cw words of memory starting at pTo with wFill.
;-----------------------------------------------------------------------------
;  macro bltc destroys ax,es,cx

bltc    MACRO pTo,wFill,cw
        push    di
        mov     ax,ds               ; we are filling in the data segment
        mov     es,ax
        mov     di,pTo              ; get the destination, constant, and count
        mov     ax,wFill
        mov     cx,cw
        cld                         ; the operation is forward
        rep     stosw               ; fill memory
        pop     di
        ENDM

;-----------------------------------------------------------------------------
; bltbc (pTo, bFill, cb) - fills cb bytes of memory starting at pTo with
; bFill.
;-----------------------------------------------------------------------------

;  macro bltbc destroys ax,es,cx

bltbc   MACRO pTo,bFill,cb
        push    di
        mov     ax,ds               ; we are filling in the data segment
        mov     es,ax
        mov     di,pTo              ; get the destination, constant, and count
        mov     al,bFill
        mov     cx,cb
        cld                         ; the operation is forward
        rep     stosb               ; fill memory
        pop     di
        ENDM

;------------------------------------------------------------------------------
; blt (pFrom, pTo, cw) - a block transfer of wFills from pFrom to pTo;
; The size of the block is cw wFills.  This blt() handles the case of
; overlapping source and destination.  blt() returns a pointer to the
; end of the destination buffer (pTo + cw).  NOTE - use this blt() to
; to transfer within the current DS only--use the bltx for FAR blts.
;-----------------------------------------------------------------------------

;  macro blt destroys ax,bx,cx,es

blt     MACRO pFrom,pTo,cw
        local   blt1
        push    si
        push    di
        mov     si,pFrom            ; get pointers and length of blt
        mov     di,pTo
        mov     cx,cw
        mov     ax,ds               ; set up segment registers
        mov     es,ax
        mov     ax,di               ; calculate return value
        mov     bx,cx
        shl     bx,1
        add     ax,bx
        cmp     si,di               ; reverse direction of the blt if
        jae     blt1                ;  necessary

        dec     bx
        dec     bx
        add     si,bx
        add     di,bx
        std
blt1:
        rep     movsw
        cld
        pop     di
        pop     si
        ENDM


        subttl C structures Used in this module
        page
;
;       *** The following structure definitions were used when this module
;       *** was being developed:
;
;struct IFI
        ;{
        ;int             xp;
        ;int             xpLeft;
        ;int             xpRight;
        ;int             xpReal;
        ;int            xpPr;
        ;int            xpPrRight;
        ;int             ich;
        ;int             ichLeft;
        ;int             ichPrev;
        ;int             ichFetch;
        ;int             dypLineSize;
        ;int             cchSpace;
        ;int             cBreak;
        ;int             chBreak;
        ;int             jc;

;#ifdef CASHMERE
        ;int             tlc;
;#endif /* CASHMERE */

        ;int             fPrevSpace;
        ;};
; ***************************************************************************
; ***** Equates for IFI structure ifi offsets ****************

        IFI_STRUC       STRUC
        xp              DW      ?
        xpLeft_Ifi      DW      ?
        xpRight_Ifi     DW      ?
        xpReal_Ifi      DW      ?
        xpPr            DW      ?
        xpPrRight       DW      ?
        ich_Ifi         DW      ?
        ichLeft         DW      ?
        ichPrev         DW      ?
        ichFetch        DW      ?
        dypLineSize     DW      ?
        cchSpace        DW      ?
        cBreak_Ifi      DW      ?
        chBreak         DW      ?
        _jc             DW      ? ; (2.27.91) D. Kent
        fPrevSpace      DW      ?
        IFI_STRUC       ENDS

        oIfi_xp         EQU 0
        oIfi_xpLeft     EQU 2
        oIfi_xpRight    EQU 4
        oIfi_xpReal     EQU 6
        oIfi_xpPr       EQU 8
        oIfi_xpPrRight  EQU 10
        oIfi_ich        EQU 12
        oIfi_ichLeft    EQU 14
        oIfi_ichPrev    EQU 16
        oIfi_ichFetch   EQU 18
        oIfi_dypLineSize        EQU 20
        oIfi_cchSpace   EQU 22
        oIfi_cBreak     EQU 24
        oIfi_chBreak    EQU 26
        oIfi_jc         EQU 28
        oIfi_fPrevSpace EQU 30

        page
; ***************************************************************************

;/* Formatted line structure.
;Reorganized KJS, CS Sept 3 */
;/* booleans in bytes to simplify machine code */
;struct FLI
        ;{
        ;typeCP          cpMin;
        ;int             ichCpMin;
        ;typeCP          cpMac;
        ;int             ichCpMac;
        ;int             ichMac;
        ;int             dcpDepend;
        ;unsigned        fSplat : 8;
;/* First character in region where spaces have additional pixel */
        ;unsigned        ichFirstWide : 8;
;/* ichMac, with trailing blanks excluded */
        ;int             ichReal;
        ;int             doc;

        ;int             xpLeft;
        ;int             xpRight;
;/* xpRight, with trailing blanks excluded */
        ;int             xpReal;
;/* the right margin where insert will have to break the line */
        ;int             xpMarg;
;
        ;unsigned        fGraphics : 8;
        ;unsigned        fAdjSpace : 8;  /* Whether you adjust the spaces */

        ;unsigned        dxpExtra;
;/* the interesting positions in order from top to bottom are:
        ;top:                  yp+dypLine
        ;top of ascenders:     yp+dypAfter+dypFont
        ;base line:            yp+dypBase
        ;bottom of descenders: yp+dypAfter
        ;bottom of line:       yp
;distances between the points can be determined by algebraic subtraction.
;e.g. space before = yp+dypLine - (yp+dypAfter+dypFont)
;*/
        ;int             dypLine;
        ;int             dypAfter;
        ;int             dypFont;
        ;int             dypBase;

        ;int            ichLastTab;
        ;int             rgdxp[ichMaxLine];
        ;CHAR            rgch[ichMaxLine];
        ;};
; ***************************************************************************
ichMaxLine EQU  255
dxpNil     EQU  0FFFFH

        FLI STRUC
        cpMin_OFF       DW      ?
        cpMin_SEG       DW      ?
        ichCpMin        DW      ?
        cpMac_OFF       DW      ?
        cpMac_SEG       DW      ?
        ichCpMac        DW      ?
        ichMac          DW      ?
        dcpDepend       DW      ?
        fSplat          DB      ?
        ichFirstWide    DB      ?
        ichReal         DW      ?
        doc_Fli         DW      ?
        xpLeft_Fli      DW      ?
        xpRight         DW      ?
        xpReal_Fli      DW      ?
        xpMarg          DW      ?
        fGraphics_Fli   DB      ?
        fAdjSpace       DB      ?
        dxpExtra        DW      ?
        dypLine         DW      ?
        dypAfter        DW      ?
        dypFont         DW      ?
        dypBase         DW      ?
        fSplatNext      DW      ?
        ichLastTab      DW      ?
	flm_Fli		DW	?
        rgdxp           DW ichMaxLine DUP (?)
        rgch            DB ichMaxLine DUP (?)
        FLI     ENDS

        page

; **************************************************************************
;struct TBD      /* Tab Descriptor */
        ;{
        ;unsigned        dxa;        /* distance from left margin of tab stop */
        ;unsigned char   jc : 3;     /* justification code */
        ;unsigned char   tlc : 3;    /* leader dot code */
        ;unsigned char   opcode : 2; /* operation code for Format Tabs */
        ;CHAR            chAlign;    /* ASCII code of char to align on
                                       ;if jcTab=3, or 0 to align on '.' */
        ;};
; ***************************************************************************
; ***** Equates for TBD structure offsets ****************
        TBD     STRUC
        dxa     DW      ?
        jc_Tbd  DB      ?  ; 3 bits
        chAlign DB      ?  ;char
        TBD     ENDS

            ;/* bit field equates in TBD structure */
        tlc     EQU jc_Tbd  ; 3 bits
        opcode  EQU jc_Tbd  ; 2 bits

        page
; **************************************************************************
;struct PAP      /* Paragraph properties */
        ;{
        ;unsigned        fStyled : 1;                            /* BYTE 0 */
        ;unsigned        stc : 7;
        ;unsigned        jc : 2;                                 /* BYTE 1 */
        ;unsigned        fKeep : 1;
        ;unsigned        fKeepFollow : 1;
        ;unsigned        : 4;
        ;unsigned        stcNormChp : 7;                         /* BYTE 2 */
        ;unsigned        : 9;                                    /* BYTE 3 */
        ;unsigned        dxaRight;                               /* BYTE 4-5 */
        ;unsigned        dxaLeft;                                /* BYTE 6-7 */
        ;unsigned        dxaLeft1;                               /* BYTE 8-9 */
        ;unsigned        dyaLine;                                /* 10-11 */
        ;unsigned        dyaBefore;                              /* 12-13 */
        ;unsigned        dyaAfter;                               /* 14-15 */
        ;unsigned        rhc : 4;        /* Running hd code */
        ;unsigned        fGraphics : 1; /* Graphics bit */
        ;unsigned        wUnused1 : 11;
        ;int             wUnused2;
        ;int             wUnused3;
        ;struct TBD      rgtbd[itbdMaxWord];
        ;};

; ***************************************************************************
; ***** Equates for PAP structure offsets ****************

        PAP     STRUC
        fStyled         DB      ?       ;1 bit         /* BYTE 0 */
        jc_Pap          DB      ?       ;2 bits        /* BYTE 1 */
        rmChp           DB      ?       ;7 bits          /* BYTE 2 */
        unused9         DB      ?       ;9 bits          /* BYTE 3 */
        dxaRight        DW      ?       ;/* BYTE 4-5 */
        dxaLeft         DW      ?       ;/* BYTE 6-7 */
        dxaLeft1        DW      ?       ;/* BYTE 8-9 */
        dyaLine         DW      ?       ;/* 10-11 */
        dyaBefore       DW      ?       ;/* 12-13 */
        dyaAfter        DW      ?       ;/* 14-15 */
                                        ;/* BYTE 16-17 */
        rhc             DW      ?       ;4 bits        /* Running hd code */
        wUnused2        DW      ?       ;/* BYTE 18-19 */
        wUnused3        DW      ?       ;/* BYTE 20-21 */
        rgtbd           DW      ?       ;/* BYTE 23-23 */
        PAP     ENDS
            ;/* bit field equates in PAP structure */
        stc_Pap     EQU fStyled         ;7 bits
        fKeep       EQU jc_Pap          ;1 bit
        fKeepFollow EQU jc_Pap          ;1 bit
        unused4     EQU jc_Pap          ;4 bits
        fGraphics_Pap   EQU rhc         ;1 bits /* Graphics bit */
        wUnused1    EQU rhc             ;11 bits
        page

; **************************************************************************
;struct SEP
;       { /* Section properties */
;       unsigned        fStyled : 1;                            /* BYTE 0 */
;       unsigned        stc : 7;
;       unsigned        bkc : 3;        /* Break code */        /* BYTE 1 */
;       unsigned        nfcPgn : 3;     /* Pgn format code */
;       unsigned        :2;
;       unsigned        yaMac;          /* Page height */       /* BYTE 2-3 */
;       unsigned        xaMac;          /* Page width */        /* BYTE 4-5 */
;       unsigned        pgnStart;       /* Starting pgn */      /* BYTE 6-7 */
;       unsigned        yaTop;          /* Start of text */     /* BYTE 8-9 */
;       unsigned        dyaText;        /* Height of text */    /* 10-11 */
;       unsigned        xaLeft;         /* Left text margin */  /* 12-13 */
;       unsigned        dxaText;        /* Width of text */     /* 14-15 */
;       unsigned        rhc : 4;        /* *** RESERVED *** */  /* 16 */
;                                       /* (Must be same as PAP) */
;       unsigned        : 2;
;       unsigned        fAutoPgn : 1;   /* Print pgns without hdr */
;       unsigned        fEndFtns : 1;   /* Footnotes at end of doc */
;       unsigned        cColumns : 8;   /* # of columns */      /* BYTE 17 */
;       unsigned        yaRH1;          /* Pos of top hdr */    /* 18-19 */
;       unsigned        yaRH2;          /* Pos of bottom hdr */ /* 20-21 */
;       unsigned        dxaColumns;     /* Intercolumn gap */   /* 22-23 */
;       unsigned        dxaGutter;      /* Gutter width */      /* 24-25 */
;       unsigned        yaPgn;          /* Y pos of page nos */ /* 26-27 */
;       unsigned        xaPgn;          /* X pos of page nos */ /* 28-29 */
;       CHAR            rgbJunk[cchPAP - 30]; /* Pad to cchPAP */
;       };

; ***************************************************************************
; ***** Equates for SEP structure offsets ****************
        SEP     STRUC
        fStyled_Sep     DB      ?       ;1 bit          /* BYTE 0 */
        bkc             DB      ?       ;3 bits /* BYTE 1 */
        yaMac           DW      ?       ; /* Page height */ /* BYTE 2-3 */
        xaMac           DW      ?       ;/* Page width */  /* BYTE 4-5 */
        pgnStart        DW      ?       ; /* Starting pgn */      /* BYTE 6-7 */
        yaTop           DW      ?       ; /* Start of text */     /* BYTE 8-9 */
        dyaText         DW      ?       ; /* Height of text */    /* 10-11 */
        xaLeft_Sep      DW      ?       ; /* Left text margin */  /* 12-13 */
        dxaText         DW      ?       ; /* Width of text */     /* 14-15 */
        rhc_Sep         DB      ?       ;4 bits   /* 16 */
        ;                                       /* (Must be same as PAP) */
        cColumns        DB      ?       ; /* # of columns */      /* BYTE 17 */
        yaRH1           DW      ?       ; /* Pos of top hdr */    /* 18-19 */
        yaRH2           DW      ?       ; /* Pos of bottom hdr */ /* 20-21 */
        dxaColumns      DW      ?       ;/* Intercolumn gap */   /* 22-23 */
        dxaGutter       DW      ?       ; /* Gutter width */      /* 24-25 */
        yaPgn           DW      ?       ; /* Y pos of page nos */ /* 26-27 */
        xaPgn           DW      ?       ; /* X pos of page nos */ /* 28-29 */
        rgbJunk         DW      ?       ; /* Pad to cchPAP */
        SEP     ENDS

            ;/* bit field equates in SEP structure */

        stc_Sep EQU fStyled_Sep     ;7 bits
        nfcPgn EQU bkc  ; 3 bits     /* Pgn format code */
        junk1_Sep  EQU bkc  ; 2 bits
        junk2_Sep  EQU rhc_Sep  ;2 bits
        fAutoPgn EQU rhc_Sep    ;1 bit   /* Print pgns without hdr */
        fEndFtns EQU rhc_Sep    ;1 bit   /* Footnotes at end of doc */


        page

; **************************************************************************
;typedef struct FMI     /* font metric information */
        ;{
        ;int *mpchdxp;         /* pointer to width table */
                                ;/* NOTE - we actually point chDxpMin entries
                                          ;before the start of the table, so
                                          ;that the valid range begins at the
                                          ;start of the actual table */
        ;int dxpSpace;          /* width of a space */
        ;int dxpOverhang;       /* overhang for italic/bold chars */
        ;int dypAscent;         /* ascent */
        ;int dypDescent;                /* descent */
        ;int dypBaseline;       /* difference from top of cell to baseline */
        ;int dypLeading;        /* accent space plus recommended leading */
        ;};

; ***************************************************************************
; ***** Equates for FMI  structure offsets ****************
        FMI     STRUC
        mpchdxp         DW      ?
        dxpSpace        DW      ?
        dxpOverhang     DW      ?
        dypAscent_Fmi   DW      ?
        dypDescent_Fmi  DW      ?
        dypBaseline     DW      ?
        dypLeading      DW      ?
        FMI     ENDS
        page

; **************************************************************************
;struct CHP      /* Character properties */
        ;{
        ;unsigned       fStyled : 1;                            /* BYTE 0 */
        ;unsigned       stc : 7;        /* style */
        ;unsigned       fBold : 1;                              /* BYTE 1 */
        ;unsigned       fItalic : 1;
        ;unsigned       ftc : 6;        /* Font code */
        ;unsigned       hps : 8;        /* Size in half pts */  /* BYTE 2 */
        ;unsigned       fUline : 1;                             /* BYTE 3 */
        ;unsigned       fStrike : 1;
        ;unsigned       fDline: 1;
        ;unsigned       fOverset : 1;
        ;unsigned       csm : 2;        /* Case modifier */
        ;unsigned       fSpecial : 1;
        ;unsigned       : 1;
        ;unsigned       ftcXtra : 3;                            /* BYTE 4 */
        ;unsigned       fOutline : 1;
        ;unsigned       fShadow : 1;
        ;unsigned       : 3;
        ;unsigned       hpsPos : 8;                             /* BYTE 5 */
        ;unsigned       fFixedPitch : 8;        /* used internally only */
        ;unsigned       chLeader : 8;
        ;unsigned       ichRun : 8;
        ;unsigned       cchRun : 8;
        ;};

; ***************************************************************************
; ***** Equates for CHP structure offsets ****************
        CHP     STRUC
        fStyled_Chp     DB      ?       ;1 bit   /* BYTE 0 */
        fBold           DB      ?       ;1 bit   /* BYTE 1 */
        hps             DB      ?       ;8 bits  /* BYTE 2 */
        fUline          DB      ?       ;1 bit   /* BYTE 3 */
        ftcXtra         DB      ?       ;3 bits  /* BYTE 4 */
        hpsPos          DB      ?       ;8 bits  /* BYTE 5 */
        fFixedPitch     DB      ?       ;8 bits  /* BYTE 6 */
        chLeader        DB      ?       ;8 bits  /* BYTE 7 */
        ichRun          DB      ?       ;8 bits  /* BYTE 8 */
        cchRun          DB      ?       ;8 bits  /* BYTE 9 */
        CHP     ENDS

            ;/* bit field equates in CHP structure */
        stc_Chp         EQU fStyled_Chp ;7 bits        /* style */
        fItalic         EQU fBold       ;1 bit
        ftc             EQU fBold       ;6 bits
        fStrike         EQU fUline      ;1 bit
        fDline          EQU fUline      ;1 bit
        fOverset        EQU fUline      ;1 bit
        csm             EQU fUline      ;2 bits        /* Case modifier */
        fSpecial        EQU fUline      ;1 bit
        chp_unused1     EQU fUline      ;1 bit
        fOutline        EQU ftcXtra     ;1 bit
        fShadow         EQU ftcXtra     ;1 bit
        chp_unused2     EQU ftcXtra     ;3 bits

; **************************************************************************
        subttl  Bit masks
        page

        mask_0001       EQU 1
        mask_0010       EQU 2
        mask_0011       EQU 3
        mask_0100       EQU 4
        mask_0101       EQU 5
        mask_0110       EQU 6
        mask_0111       EQU 7
        mask_1000       EQU 8
        mask_1001       EQU 9
        mask_1010       EQU 10
        mask_1011       EQU 11
        mask_1100       EQU 12
        mask_1101       EQU 13
        mask_1110       EQU 14
        mask_1111       EQU 15
        mask_0001_0000  EQU 16
        mask_1111_1111  EQU 65535
        mask_0100_0000  EQU 64

        subttl Defined C Constants

        c_True          EQU     1
        c_False         EQU     0
        c_hpsDefault    EQU     20
        c_cwFLIBase     EQU     22
        c_cwIFI         EQU     16
        c_cwCHP         EQU     5
        c_docNil        EQU     -1
        c_cpNil         EQU     -1
        c_czaInch       EQU     1440
	c_czaLine	EQU	240
        c_xaRightMax    EQU     31680
        c_hpsNegMin     EQU     128
                ;/* Justification codes: must agree with menu.mod */
        c_jcLeft        EQU     0
        c_jcCenter      EQU     1
        c_jcRight       EQU     2
        c_jcBoth        EQU     3

        c_jcTabMin      EQU     4
        c_jcTabLeft     EQU     4
        c_jcTabCenter   EQU     5
        c_jcTabRight    EQU     6
        c_jcTabDecimal  EQU     7

                ;/* Tab leader codes: must agree with menu.mod */
        c_tlcWhite      EQU     0
        c_tlcDot        EQU     1
        c_tlcHyphen     EQU     2
        c_tlcUline      EQU     3

        c_chEmark       EQU     164

        c_chNil         EQU     -1
        c_chDelPrev     EQU     8
        c_chTab         EQU     9
        c_chEol         EQU     10
        c_chNewLine     EQU     11
        c_chSect        EQU     12
        c_chReturn      EQU     13
        c_chNRHFile     EQU     31
        c_chSpace       EQU     32
        c_chSplat       EQU     46
        c_chHyphen      EQU     45


        subttl FormatLine()
        page
; **************************************************************************
        sBegin FORM1_TEXT
;***
;
; FormatLine(doc, cp, ichCp, cpMac, flm)
;   int doc;
;   typeCP cp;
;   int ichCp;
;   typeCP cpMac;
;   int flm;
;
;  This procedure fills up vfli with a line of text. It is very large
;   and called often - each time a character is typed, at least.
;
;***
        cProc FormatLine,<PUBLIC,FAR>,<di,si>
                parmW   doc
                parmD   cp
                parmW   ichCp
                parmD   cpMac
                parmW   flm
; Line 79

                localW  dyaFormat
                localW  fFlmPrinting
                localDP psep
                localW  xaRight
                localW  dypAscentMac
                localW  ichpNRH
                localW  ypSubSuperFormat
                localW  dxpFormat
                localW  dypFormat
                localDP ppap
                localW  dypAscent

                localV  ifi,%(size IFI_STRUC)

                localW  xpTab
                localW  fTruncated
                localW  xaLeft
                localW  dypDescentMac
                localDP ptbd
                localW  dypDescent
                localW  dxaFormat
                localW  dxp
                localW  cch
                localDP pch
                localW  xpPrev
                localW  iichNew
                localW  dxpPr
                localW  cchUsed
                localW  dich
                localW  fSizeChanged
                localW  chT
                localW  cch2
                localW  dxpCh
                localW  xaTab
                localW  xaPr
                localW  chT2
                localW  dxpNew

                localV  chpLocal,%(size CHP)

        cBegin FormatLine

; Line 107
        mov     ax,flm
        and     ax,1
        mov     fFlmPrinting,ax
; Line 113
        mov     fTruncated,0

    ;** Check for fli current */
; Line 122
        mov     ax,WORD PTR VFLI.doc_Fli
        cmp     doc,ax
        jne     $I845
        mov     ax,WORD PTR VFLI.cpMin_OFF
        mov     dx,WORD PTR VFLI.cpMin_SEG
        cmp     SEG_cp,dx
        jne     $I845
        cmp     OFF_cp,ax
        jne     $I845
        mov     ax,WORD PTR VFLI.ichCpMin
        cmp     ichCp,ax
        jne     $I845
	mov	ax,WORD PTR VFLI.flm_Fli
	cmp	flm,ax
	jne	$I845

        ;* Just did this one */

        jmp     $RetFormat    ; *** return ****
; Line 125
$I845:
IFDEF DEBUG
IFDEF SCRIBBLE
        mov     ax,5
        push    ax
        mov     ax,70
        push    ax
        call    FAR PTR FNSCRIBBLE
ENDIF
ENDIF
; Line 129
    ;*
    ;* This means:
    ;*  vfli.fSplat = false;
    ;*  vfli.dcpDepend = 0;
    ;*  vfli.ichCpMac = 0;
    ;*  vfli.dypLine = 0;
    ;*  vfli.dypAfter = 0;
    ;*  vfli.dypFont = 0;
    ;*  vfli.dypBase = 0;
    ;*
    ;                         *** macro bltc destroys ax,es,cx
        bltc    <OFFSET VFLI>,0,c_cwFLIBase
        mov     WORD PTR VFLI.fSplatNext, 0
; Line 141
     ;* Rest of FormatLine loads up cache with current data *****

        mov     ax,doc
        mov     WORD PTR VFLI.doc_Fli,ax
	mov	ax,flm
	mov	WORD PTR VFLI.flm_Fli,ax
; Line 142
; *********** Register variables ********************
        rax_OFF_cp      EQU     ax
        rdx_SEG_cp      EQU     dx
; ****************************************************
        mov     rax_OFF_cp,OFF_cp
        mov     rdx_SEG_cp,SEG_cp
        mov     WORD PTR VFLI.cpMin_OFF,rax_OFF_cp
        mov     WORD PTR VFLI.cpMin_SEG,rdx_SEG_cp
; Line 143
        mov     cx,ichCp
        mov     WORD PTR VFLI.ichCpMin,cx
; Line 145
               ; *** if (cp > cpMac)
        cmp     rdx_SEG_cp,SEG_cpMac
        jl      $initRunTbl
        jg      $spAftEnd
        cmp     rax_OFF_cp,OFF_cpMac
        jbe     $initRunTbl
$spAftEnd:
        ;/* Space after the endmark. Reset the cache because the footnotes come
        ;at the same cp in the footnote window */
; Line 149
        mov     WORD PTR VFLI.doc_Fli,c_docNil
; Line 150
        mov     WORD PTR VFLI.cpMac_OFF,rax_OFF_cp
        mov     WORD PTR VFLI.cpMac_SEG,rdx_SEG_cp
; Line 151
        mov     WORD PTR VFLI.rgdxp,0
; Line 159
        ;  /* Line after end mark is taller than screen */
        mov     ax,DYPMAX
        mov     WORD PTR VFLI.dypLine,ax
        sar     ax,1
        mov     WORD PTR VFLI.dypFont,ax
        mov     WORD PTR VFLI.dypBase,ax
        jmp     $ScribRet       ; Scribble and return
;
; *************** EXIT POINT **********************************************
;


$initRunTbl:
                ;/* Initialize run tables */
        mov     WORD PTR $S784_ichpFormat,0
; Line 185
                ;/* Cache section and paragraph properties */
        push    doc
        push    SEG_cp
        push    OFF_cp
        call    FAR PTR CACHESECT
; Line 188
        mov     psep,OFFSET VSEPABS
; Line 190
        push    doc
        push    SEG_cp
        push    OFF_cp
        call    FAR PTR CACHEPARA
; Line 191
        mov     ppap,OFFSET VPAPABS

                ;/* Now we have:
                        ;ppap    paragraph properties
                        ;psep    division properties
                ;*/

; Line 198
                ; *** if (ppap->fGraphics)
        mov     bx,ppap
        test    WORD PTR [bx].fGraphics_Pap,mask_0001_0000
        je      $I851
; Line 201
                ;*** Format a picture paragraph in a special way (see picture.c)
        push    doc
        push    SEG_cp
        push    OFF_cp
        push    ichCp
        push    SEG_cpMac
        push    OFF_cpMac
        push    flm
        call    FAR PTR FORMATGRAPHICS
        jmp     $ScribRet       ; Scribble and return
;
; *************** EXIT POINT **********************************************
;
$I851:
                ; *** /* Assure we have a good memory DC for font stuff */
        call    FAR PTR VALIDATEMEMORYDC
        cmp     VHMDC,0
        je      $L20000
        cmp     VHDCPRINTER,0
        jne     $L20001
$L20000:
        call    FAR PTR WINFAILURE
        jmp     $ScribRet       ; Scribble and return
;
; *************** EXIT POINT **********************************************
;
$L20001:

; Line 216
        ; *** bltc(&ifi, 0, cwIFI);
        ; ***/* This means:
                ; ***ifi.ich = 0;
                ; ***ifi.ichPrev = 0;
                ; ***ifi.ichFetch = 0;
                ; ***ifi.cchSpace = 0;
                ; ***ifi.ichLeft = 0;
        ; ****/

    ;                         *** macro bltc destroys ax,es,cx
        lea     dx,ifi
        bltc    dx,0,c_cwIFI
; Line 225
        mov     ifi._jc,c_jcTabLeft
; Line 226
        mov     ifi.fPrevSpace,c_True
; Line 230
        ; *** /* Set up some variables that have different value depending on
        ; *** whether we are printing or not */

        ; ***   if (fFlmPrinting)

        cmp     fFlmPrinting,0
        je      $NoPrint
; Line 232
        mov     ax,DXAPRPAGE
        mov     dxaFormat,ax
; Line 233
        mov     ax,DYAPRPAGE
        mov     dyaFormat,ax
; Line 234
        mov     ax,DXPPRPAGE
        mov     dxpFormat,ax
; Line 235
        mov     ax,DYPPRPAGE
        mov     dypFormat,ax
; Line 236
        mov     ax,YPSUBSUPERPR
        jmp     SHORT $CalcHgt

$NoPrint:
; Line 240
        mov     ax,c_czaInch
        mov     dyaFormat,ax
        mov     dxaFormat,ax
; Line 241
        mov     ax,DXPLOGINCH
        mov     dxpFormat,ax
; Line 242
        mov     ax,DYPLOGINCH
        mov     dypFormat,ax
; Line 243
        mov     ax,YPSUBSUPER

$CalcHgt:
        mov     ypSubSuperFormat,ax

        ; *** /* Calculate line height and width measures.  Compute
                ; *** xaLeft    left indent 0 means at left margin
                ; *** xaRight   width of column measured from left
                ; ***           margin (not from left indent).
        ; *** */
        ; *** xaLeft = ppap->dxaLeft;

; Line 251
; *********** Register variables ********************
        rbx_ppap EQU    bx
; ****************************************************
        mov     rbx_ppap,ppap
        mov     ax,[rbx_ppap].dxaLeft
        mov     xaLeft,ax
; Line 255

        ; *** /* If this is the first line of a paragraph,
        ; ***      adjust xaLeft for the first
        ; *** line indent.  (Also, set dypBefore, since its handy.) */
        ; *** if (cp == vcpFirstParaCache)

        mov     ax,WORD PTR VCPFIRSTPARACACHE
        mov     dx,WORD PTR VCPFIRSTPARACACHE+2
        cmp     SEG_cp,dx
        jne     $setMargins
        cmp     OFF_cp,ax
        jne     $setMargins
; Line 257
        mov     ax,[rbx_ppap].dxaLeft1
        add     xaLeft,ax
; Line 273
$setMargins:
; Line 274
        ; *** /* Now, set xaRight (width measured in twips). */

IFDEF CASHMERE
        test    WORD PTR [rbx_ppap].rhc,15
        je      $L20005
        mov     ax,WORD PTR VSEPPAGE.xaMac
        sub     ax,WORD PTR VSEPPAGE.dxaGutter
        jmp     SHORT $L20006
$L20005:
ENDIF

        mov     si,psep
        mov     ax,[si].dxaText
$L20006:
        sub     ax,[rbx_ppap].dxaRight
        mov     xaRight,ax
; Line 277
        ; *** /* Do necessary checks on xaLeft and xaRight */

; *********** Register variables ********************
        rcx_xaRightMax EQU      cx
; ****************************************************
        mov     rcx_xaRightMax,c_xaRightMax
        cmp     ax,rcx_xaRightMax
        jbe     $I859
; Line 279
        mov     xaRight,rcx_xaRightMax
; Line 281
$I859:
; *********** Register variables ********************
        rax_xaLeft EQU  ax
; ****************************************************
        mov     rax_xaLeft,xaLeft
        cmp     rax_xaLeft,rcx_xaRightMax
        jbe     $I861
; Line 283
        mov     xaLeft,rcx_xaRightMax
; Line 285
$I861:
        cmp     rax_xaLeft,0
        jge     $I863
; Line 287
        xor     rax_xaLeft,rax_xaLeft
        mov     xaLeft,rax_xaLeft
; Line 289
$I863:
        cmp     xaRight,rax_xaLeft
        jae     $I865
; Line 291
        inc     rax_xaLeft
        mov     xaRight,rax_xaLeft
; Line 294
$I865:
        push    xaLeft
        push    dxpFormat
        push    dxaFormat
        call    FAR PTR MULTDIV
        mov     ifi.xpLeft_Ifi,ax
        mov     ifi.xp,ax
        mov     WORD PTR VFLI.xpLeft_Fli,ax
; Line 295
        push    xaLeft
        push    DXPPRPAGE
        push    DXAPRPAGE
        call    FAR PTR MULTDIV
        mov     ifi.xpPr,ax
; Line 296
        push    xaRight
        push    dxpFormat
        push    dxaFormat
        call    FAR PTR MULTDIV
        mov     ifi.xpRight_Ifi,ax
        mov     WORD PTR VFLI.xpMarg,ax
; Line 297
        push    xaRight
        push    DXPPRPAGE
        push    DXAPRPAGE
        call    FAR PTR MULTDIV
        mov     ifi.xpPrRight,ax
; Line 300
        ; *** /* Get a pointer to the tab-stop table. */
        mov     ax,ppap
        add     ax,rgtbd
        mov     ptbd,ax
; Line 303
        ; *** /* Turn off justification. */
        cmp     fFlmPrinting,0
        je      $L20007
        mov     ax,VHDCPRINTER
        jmp     SHORT $L20008
$L20007:
        mov     ax,VHMDC
$L20008:
        push    ax
        xor     ax,ax
        push    ax
        push    ax
        call    FAR PTR SETTEXTJUSTIFICATION
; Line 306
        ; *** /* Initialize the line height information. */
        xor     ax,ax
        mov     dypDescentMac,ax
        mov     dypAscentMac,ax
; Line 309
        ; ***   /* To tell if there were any tabs */
        mov     ifi.ichLeft,65535
; Line 312
        ; *** /* Get the first run, and away we go... */
        push    doc
        push    SEG_cp
        push    OFF_cp
        push    ichCp
        jmp     SHORT $L20037

$NullRun:
; Line 357
        mov     ax,c_cpNil
        push    ax
        push    ax   ; high word of cpNil
        push    ax
        xor     ax,ax
        push    ax
$L20037:
        mov     ax,11
        push    ax
        call    FAR PTR FETCHCP
$FirstCps:
; Line 360
        mov     cchUsed,0
; Line 364
        ; *** /* Continue fetching runs until a run is found with a nonzero
        ; ***    length */
        mov     ax,VCCHFETCH
        mov     cch,ax
        or      ax,ax
        je      $NullRun
        mov     ax,VPCHFETCH
        mov     pch,ax
; Line 371
        mov     ax,WORD PTR VCPFETCH
        mov     dx,WORD PTR VCPFETCH+2
        cmp     SEG_cpMac,dx
        jg      $I886
        jl      $L20009
        cmp     OFF_cpMac,ax
        jbe     $L20009
	cmp	fFlmPrinting,0
	jne	$I886
	mov	bx,pch
	cmp	BYTE PTR [bx],c_chSect
	jne	$I886
$L20009:
; Line 374
        ; *** /* Force end mark to be in standard system font */
;                   *** macro blt destroys ax,bx,cx,es
        blt     <OFFSET VCHPNORMAL>,<OFFSET VCHPABS>,c_cwCHP
; Line 375
IFDEF SYSENDMARK
                ; *** vchpAbs.ftc = ftcSystem;
        mov     BYTE PTR VCHPABS.ftc,248       ; 0x3e << 2 == 0xF8 == 248
ELSE
                ; *** vchpAbs.ftc = 0;
        and     BYTE PTR VCHPABS.ftc,3
ENDIF
; Line 376
                ; *** vchpAbs.ftcXtra = 0;
        and     BYTE PTR VCHPABS.ftcXtra,248

                ; *** vchpAbs.hps = hpsDefault;
        mov     BYTE PTR VCHPABS.hps,c_hpsDefault
; Line 394
$I886:
              ; *** not from original c code: copy VCHPABS into chpLocal
              ; *** and use chpLocal hereafter ***********
;                   *** macro blt destroys ax,bx,cx,es
        lea     dx,chpLocal
        blt     <OFFSET VCHPABS>,dx,c_cwCHP
; Line 375
                ; *** vchpAbs.ftc = 0;
        cmp     fFlmPrinting,0
        je      $I888
; Line 396
        push    doc
        lea     ax,chpLocal
        push    ax
        mov     ax,3
        push    ax
        call    FAR PTR LOADFONT
; Line 397
        mov     ax,WORD PTR VFMIPRINT.dypAscent_Fmi
        add     ax,WORD PTR VFMIPRINT.dypLeading
        mov     dypAscent,ax
; Line 398
        mov     ax,WORD PTR VFMIPRINT.dypDescent_Fmi
        jmp     SHORT $L20038
$I888:
; Line 402
        push    doc
        lea     ax,chpLocal
        push    ax
        mov     ax,2
        push    ax
        call    FAR PTR LOADFONT
; Line 403
        mov     ax,WORD PTR VFMISCREEN.dypAscent_Fmi
        add     ax,WORD PTR VFMISCREEN.dypLeading
        mov     dypAscent,ax
; Line 404
        mov     ax,WORD PTR VFMISCREEN.dypDescent_Fmi
$L20038:
        mov     dypDescent,ax

ifdef ENABLE    /* BRYANL 8/27/27; see comment in C source */
        ; *** /* Bail out if there is a memory failure. */
        cmp     VFOUTOFMEMORY,0
        je      $I889
        jmp     $DoBreak
$I889:
endif   ; ENABLE 

; Line 408
        ; lines 408-417 removed
; Line 418
        ; ***   /* Floating line size algorithm */
        ; ***      if (chpLocal.hpsPos != 0)

        test    BYTE PTR chpLocal.hpsPos,-1
        je      $I895
; Line 421
                   ; *** /* Modify font for subscript/superscript */
        ; ***      if (chpLocal.hpsPos < hpsNegMin)

        mov     al,BYTE PTR chpLocal.hpsPos
        cmp     al,c_hpsNegMin
        jae     $I894
; Line 423
        mov     ax,ypSubSuperFormat
        add     dypAscent,ax
; Line 425
        jmp     SHORT $I895
$I894:
; Line 427
        mov     ax,ypSubSuperFormat
        add     dypDescent,ax
; Line 428
$I895:
                ; *** /* Update the maximum ascent and descent of the line. */
; Line 432
        mov     fSizeChanged,0
; Line 433
        mov     ax,dypDescent
        cmp     dypDescentMac,ax
        jge     $I896
; Line 435
        mov     dypDescentMac,ax
; Line 436
        mov     fSizeChanged,1
; Line 438
$I896:
        mov     ax,dypAscent
        cmp     dypAscentMac,ax
        jge     $I897
; Line 440
        mov     dypAscentMac,ax
; Line 441
        mov     fSizeChanged,1
; Line 444
;       dypUser EQU bp-88
;       dypAuto EQU bp-90
; *********** Register variables ********************
        rsi_dypAuto EQU si
        rdi_dypUser EQU di
; ****************************************************
$I897:
        cmp     fSizeChanged,0
        je      $OldRun
; Line 485
        mov     rsi_dypAuto,dypDescentMac
        add     rsi_dypAuto,dypAscentMac
; Line 487
        mov     bx,ppap
        mov	ax,WORD PTR [bx].dyaLine
	cmp	ax,c_czaLine
	jle	$I898
	push	ax
        push    dypFormat
        push    dyaFormat
        call    FAR PTR MULTDIV
        push    ax
        mov     ax,1
        push    ax
        call    FAR PTR IMAX
        mov     rdi_dypUser,ax
; Line 490
        cmp     rsi_dypAuto,rdi_dypUser
        jle     $L20011
$I898:
        mov     ifi.dypLineSize,rsi_dypAuto
        jmp     SHORT $L20012
$L20011:
        mov     ifi.dypLineSize,rdi_dypUser
$L20012:
; Line 496
$OldRun:
; Line 498
            ; *** /* Calculate length of the run but no greater than 256 */
        mov     ax,WORD PTR VCPFETCH
        sub     ax,WORD PTR VFLI
; Line 499
        cmp     ax,255
        jl      $I902
; Line 501
        mov     ax,254
; Line 503
$I902:
        mov     iichNew,ax
        sub     ax,ifi.ich_Ifi
        mov     dich,ax
; Line 509
                ; *** /* Ensure that all tab and non-required
                ; ***        hyphen characters start at
                ; *** beginning of run */
        cmp     WORD PTR $S784_ichpFormat,0
        jle     $L20013
        or      ax,ax
        jg      $L20013
        lea     ax,chpLocal
        push    ax
        mov     ax,10
        imul    WORD PTR $S784_ichpFormat
        mov     bx,VHGCHPFORMAT
        add     ax,[bx]
        sub     ax,10
        push    ax
        mov     ax,7
        push    ax
        call    FAR PTR CCHDIFFER
        or      ax,ax
        jne     $L20013
        mov     bx,pch
        cmp     BYTE PTR [bx],9
        je      $L20013
        cmp     BYTE PTR [bx],31
        je      $+5
        jmp     $I905
;       pchp EQU bp-92
;       register si=pchp
$L20013:
; Line 511
        mov     ax,ICHPMACFORMAT
        cmp     WORD PTR $S784_ichpFormat,ax
        jne     $L20014
        call    FGrowFormatHeap
        or      ax,ax
        jne     $+5
        jmp     $I905
$L20014:
; Line 514
; *********** Register variables ********************
        rsi_pchp EQU    si
; ****************************************************
        mov     ax,10
        imul    WORD PTR $S784_ichpFormat
        mov     rsi_pchp,ax
        sub     rsi_pchp,10
        mov     bx,VHGCHPFORMAT
        add     rsi_pchp,[bx]    ; si = pch
; Line 516
        cmp     WORD PTR $S784_ichpFormat,0
        jle     $I907
; Line 518
        mov     ax,ifi.ich_Ifi
        sub     ax,ifi.ichPrev
        mov     BYTE PTR [rsi_pchp].cchRun,al
; Line 519
        mov     al,BYTE PTR (ifi.ichPrev)
        mov     BYTE PTR [rsi_pchp].ichRun,al
; Line 521
$I907:
        add     rsi_pchp,10
;                   *** macro blt destroys ax,bx,cx,es
        mov     dx,rsi_pchp
        lea     ax,chpLocal  ; ax not destroyed in blt until after value used
        blt     ax,dx,c_cwCHP

; Line 529
        or      BYTE PTR [rsi_pchp].cchRun,255
; Line 530
        cmp     dich,0
        jg      $I908
; Line 532
        mov     al,BYTE PTR (ifi.ich_Ifi)
        jmp     SHORT $L20048
$I908:
; Line 537
                ; *** bltc (&vfli.rgdxp[ifi.ich],0,dich)

        mov     dx,ifi.ich_Ifi
        shl     dx,1
        add     dx,OFFSET VFLI.rgdxp
    ;                         *** macro bltc destroys ax,es,cx
        bltc    dx,0,dich
; Line 538
                ; *** bltbc (&vfli.rgch[ifi.ich],0,dich)
        mov     dx,ifi.ich_Ifi
        add     dx,OFFSET VFLI.rgch
                ;***  macro bltbc destroys ax,es,cx
        bltbc   dx,0,dich

; Line 539
        mov     ax,iichNew
        mov     ifi.ich_Ifi,ax
$L20048:
        mov     BYTE PTR [rsi_pchp].ichRun,al
; Line 541
        mov     ax,ifi.ich_Ifi
        mov     ifi.ichPrev,ax
; Line 542
        inc     WORD PTR $S784_ichpFormat
; Line 544
$I905:
; Line 546
        mov     ax,WORD PTR VCPFETCH
        mov     dx,WORD PTR VCPFETCH+2
        cmp     SEG_cpMac,dx
        jle     $+5
        jmp     $I911
        jl      $L20016
        cmp     OFF_cpMac,ax
        jbe     $+5
        jmp     $I911
$L20016:
; Line 549
        cmp     ifi.fPrevSpace,0
        je      $L20015
                        ; *** note ax:dx still holds vcpFetch
        cmp     SEG_cp,dx
        jne     $I912
        cmp     OFF_cp,ax
        jne     $I912
$L20015:
; Line 551
        mov     ax,ifi.ich_Ifi
        mov     WORD PTR VFLI.ichReal,ax
; Line 552
        mov     ax,ifi.xp
        mov     ifi.xpReal_Ifi,ax
        mov     WORD PTR VFLI.xpReal_Fli,ax
; Line 554
$I912:
        cmp     fFlmPrinting,0
        jne     $I913
        ;mov     ax,DOCHELP
        ;cmp     doc,ax
        ;je      $I913
; Line 556
        mov     bx,ifi.ich_Ifi
        mov     BYTE PTR VFLI.rgch[bx],c_chEmark
; Line 558
        mov     ax,c_chEmark
        push    ax
        xor     ax,ax
        push    ax
        call    FAR PTR DxpFromCh
        mov     bx,ifi.ich_Ifi
        inc     ifi.ich_Ifi
        shl     bx,1
        mov     WORD PTR VFLI.rgdxp[bx],ax
        add     WORD PTR VFLI.xpReal_Fli,ax
; Line 560
$I913:
        mov     ax,ifi.dypLineSize
        mov     WORD PTR VFLI.dypLine,ax
; Line 561
        mov     ax,dypDescentMac
        mov     WORD PTR VFLI.dypBase,ax
; Line 562
        mov     ax,dypAscentMac
        add     ax,dypDescentMac
        mov     WORD PTR VFLI.dypFont,ax
; Line 563
        mov     ax,ifi.ich_Ifi
        mov     WORD PTR VFLI.ichReal,ax
        mov     WORD PTR VFLI.ichMac,ax
; Line 564
        mov     ax,OFF_cpMac
        mov     dx,SEG_cpMac
        add     ax,1
        adc     dx,0
        mov     WORD PTR VFLI.cpMac_OFF,ax
        mov     WORD PTR VFLI.cpMac_SEG,dx
; Line 565
        jmp     $JustEol
$I911:
        mov     ax,ifi.ich_Ifi
        add     ax,cch
        cmp     ax,255
        jle     $I916
; Line 573
        mov     ax,255
        sub     ax,ifi.ich_Ifi
        mov     cch,ax
; Line 574
        mov     fTruncated,1
; Line 577
$I916:
        mov     ifi.ichFetch,0
; Line 603
                ; *** if (chpLocal.fSpecial)
        test    BYTE PTR chpLocal.fSpecial,mask_0100_0000
        jne     $+5
        jmp     $GetCh
; Line 605
        lea     ax,ifi
        push    ax
        push    flm
        mov     ax,WORD PTR VSEPABS
        mov     cl,11
        shr     ax,cl
        and     ax,7
        push    ax
        call    FAR PTR FFORMATSPECIALS
        or      ax,ax
        je      $+5
        jmp     $GetCh
; Line 607
        cmp     ifi.chBreak,0
        jne     $+5
        jmp     $Unbroken
$I986:
        mov     ax,ifi.ichFetch
        sub     ax,WORD PTR VFLI.cpMac_OFF
        add     ax,WORD PTR VCPFETCH
        mov     WORD PTR VFLI.dcpDepend,ax
; Line 1026
$JustBreak:
; Line 1027
        cmp     WORD PTR ifi.chBreak,31
        je      $+5
        jmp     $I992
; Line 1032
        mov     ax,45
        push    ax
        push    fFlmPrinting
        call    FAR PTR DxpFromCh  ; *** ax will have width of hyphen

                 ; **** up to line 1036 rearranged bz
        mov     bx,WORD PTR VFLI.ichReal
; Line 1035
        mov     WORD PTR VFLI.ichMac,bx  ; ** ichMac = ichReal

        dec     bx    ; ichReal - 1
        mov     BYTE PTR VFLI.rgch[bx],45 ; ** rgch[ichReal-1] = "-

        shl     bx,1
        mov     WORD PTR VFLI.rgdxp[bx],ax
        add     ifi.xpReal_Ifi,ax
; Line 1033
        mov     ax,ifi.xpReal_Ifi
        mov     WORD PTR VFLI.xpReal_Fli,ax
        mov     WORD PTR VFLI.xpRight,ax


; Line 1036
        mov     ax,WORD PTR $S784_ichpFormat
        dec     ax
        cmp     ichpNRH,ax
        jge     $I992
;       pchp EQU bp-112
; *********** Register variables ********************
        rdi_pchp EQU    di
; ****************************************************
;       register di=pchp
;       =-114
;       =-116
; Line 1039
                ; ** register struct CHP *pchp=&(**vhgchpFormat)[ichpNRH]
        mov     ax,10
        imul    ichpNRH
        mov     rdi_pchp,ax
        mov     bx,VHGCHPFORMAT
        add     rdi_pchp,[bx]
; Line 1041
                ; ** pchp->cchRun++;
        inc     BYTE PTR [rdi_pchp].cchRun
; Line 1042
                ; ** if (pchp->ichRun >= vfli.ichMac)
        mov     dx,WORD PTR VFLI.ichMac
        cmp     BYTE PTR [rdi_pchp].ichRun,dl
        jb      $I992
; Line 1044
                ; ** pchp->ichRun = vfli.ichMac - 1;
        dec     dx
        mov     BYTE PTR [rdi_pchp].ichRun,dl
; Line 1046
$I992:
; Line 1049
        cmp     fFlmPrinting,0
        je      $I993
; Line 1051
        mov     ax,WORD PTR VFLI.ichReal
        mov     WORD PTR VFLI.ichMac,ax
; Line 1057
$I993:
        cmp     ifi._jc,c_jcTabLeft
        jne     $+5
        jmp     $I994
; Line 1061
$L20051:
        lea     ax,ifi
        push    ax
        push    xpTab
        jmp     $L20046
;       ch=-94
; *********** Register variables ********************
        rsi_ch EQU      si
; ****************************************************
;       register si=ch
$I877:
; Line 625
        mov     bx,ifi.ichFetch
        inc     ifi.ichFetch
        mov     di,pch
        mov     al,[bx][di]
        sub     ah,ah
        mov     rsi_ch,ax
; Line 627
$NormChar:
; Line 628
        cmp     rsi_ch,c_chSpace
        jne     $NotSpace
; Line 632
        cmp     fFlmPrinting,0
        je      $L20017
        mov     ax,WORD PTR VFMIPRINT+2
        jmp     SHORT $L20018
$L20017:
        mov     ax,WORD PTR VFMISCREEN+2
$L20018:
        mov     dxp,ax
        mov     bx,ifi.ich_Ifi
        shl     bx,1
        mov     WORD PTR VFLI.rgdxp[bx],ax
        add     ifi.xp,ax
; Line 633
        mov     ax,WORD PTR VFMIPRINT+2
        mov     dxpPr,ax
        add     ifi.xpPr,ax
; Line 634
        mov     bx,ifi.ich_Ifi
        inc     ifi.ich_Ifi
        mov     BYTE PTR VFLI.rgch[bx],c_chSpace

; Line 635
        jmp     $BreakOppr

$NotSpace:
; Line 641
        cmp     rsi_ch,c_chSpace
        jl      $L20019
        cmp     rsi_ch,128
        jge     $L20019
        mov     bx,WORD PTR VFMIPRINT
        shl     rsi_ch,1
        mov     ax,WORD PTR [bx][rsi_ch]
        shr     rsi_ch,1
        mov     dxpPr,ax
        cmp     ax,dxpNil
        jne     $I928
$L20019:
; Line 643
        push    rsi_ch
        mov     ax,1
        push    ax
        call    FAR PTR DxpFromCh
        mov     dxpPr,ax
; Line 646
$I928:
        cmp     fFlmPrinting,0
        je      $I929
; Line 650
        mov     ax,dxpPr
        jmp     SHORT $L20045
$I929:
; Line 653
        cmp     rsi_ch,c_chSpace
        jl      $L20020
        cmp     rsi_ch,128
        jge     $L20020
        mov     bx,WORD PTR VFMISCREEN
        shl     rsi_ch,1
        mov     ax,WORD PTR [bx][rsi_ch]
        shr     rsi_ch,1
        mov     dxp,ax
        cmp     ax,dxpNil
        jne     $I931
$L20020:
; Line 654
        push    rsi_ch
        xor     ax,ax
        push    ax
        call    FAR PTR DxpFromCh
$L20045:
        mov     dxp,ax
; Line 656
$I931:
        mov     bx,ifi.ich_Ifi
        shl     bx,1
                ; *** here ax = dxp from above
        mov     WORD PTR VFLI.rgdxp[bx],ax
        add     ifi.xp,ax
; Line 657
        mov     ax,dxpPr
        add     ifi.xpPr,ax
; Line 658
        mov     bx,ifi.ich_Ifi
        inc     ifi.ich_Ifi
        mov     ax,rsi_ch
        mov     BYTE PTR VFLI.rgch[bx],al
; Line 662
        cmp     rsi_ch,45
        jle     $SwitchCh
; Line 1001
$DefaultCh:
; Line 1002
        mov     ax,ifi.xpPrRight
        cmp     ifi.xpPr,ax
        jle     $PChar
; Line 1003
$DoBreak:
; Line 1005
        cmp     ifi.chBreak,0
        je      $+5
        jmp     $I986
; Line 1006
$Unbroken:
; Line 1011
        mov     ax,ifi.ich_Ifi
        dec     ax
        push    ax
        call    FFirstIch
        or      ax,ax
        jne     $+5
        jmp     $I987
        cmp     ifi.ich_Ifi,255
        jl      $+5
        jmp     $I987
; Line 1013
$PChar:
; Line 1087
        mov     ifi.fPrevSpace,0
; Line 1089
        jmp     SHORT $GetCh

                ; ***** end for default case **************
$SwitchCh:
        mov     ax,rsi_ch
        cmp     ax,c_chSect
        jne     $+5
        jmp     $SC942
        jle     $+5
        jmp     $L20028
        cmp     ax,c_chTab
        jne     $+5
        jmp     $SC951
        cmp     ax,c_chEol
        jl      $DefaultCh
        cmp     ax,c_chNewLine
        jg      $+5
        jmp     $SC971
        jmp     SHORT $DefaultCh
$SC938:
; Line 671
        dec     ifi.ich_Ifi
; Line 672
        mov     ax,dxp
        sub     ifi.xp,ax
; Line 673
        mov     ax,dxpPr
        sub     ifi.xpPr,ax

        page
; Line 674
$GetCh:         ; ****** START of main FOR loop ********************
; Line 335
        mov     ax,cch
        cmp     ifi.ichFetch,ax
        je      $+5
        jmp     $I877
; Line 341
        cmp     ifi.ich_Ifi,255
        jge     $DoBreak
; Line 344
        cmp     fTruncated,0
        jne     $+5
        jmp     $NullRun
; Line 349
        add     cchUsed,ax
; Line 350
        mov     ax,cchUsed
        add     ax,VPCHFETCH
        mov     pch,ax
; Line 351
        mov     ax,VCCHFETCH
        sub     ax,cchUsed
        mov     cch,ax
; Line 352
        mov     fTruncated,0
; Line 353
        jmp     $OldRun
$SC939:
; Line 679
        dec     ifi.ich_Ifi
; Line 680
        mov     ax,dxp
        sub     ifi.xp,ax
; Line 681
        mov     ax,dxpPr
        sub     ifi.xpPr,ax
; Line 683
        mov     ax,WORD PTR $S784_ichpFormat
        dec     ax
        mov     ichpNRH,ax
; Line 684
        mov     ax,c_chHyphen
        push    ax
        mov     ax,1
        push    ax
        call    FAR PTR DxpFromCh
        add     ax,ifi.xpPr
        cmp     ax,ifi.xpPrRight
        jle     $+5
        jmp     $DoBreak
; Line 687
        mov     ax,ifi.xp
        mov     xpPrev,ax
; Line 700
        mov     bx,ifi.ich_Ifi
        mov     BYTE PTR VFLI.rgch[bx],c_chTab
; Line 701
        jmp     $Tab0
$SC942:
; Line 705
        dec     ifi.ich_Ifi
; Line 706
        mov     ax,dxp
        sub     ifi.xp,ax
; Line 707
        mov     ax,dxpPr
        sub     ifi.xpPr,ax
; Line 710
        mov     ax,dypDescentMac
        mov     WORD PTR VFLI.dypBase,ax
        add     ax,dypAscentMac
        mov     WORD PTR VFLI.dypLine,ax
        mov     WORD PTR VFLI.dypFont,ax
; Line 711
        mov     ax,ifi.ichFetch
        cwd
        add     ax,WORD PTR VCPFETCH
        adc     dx,WORD PTR VCPFETCH+2
        mov     WORD PTR VFLI.cpMac_OFF,ax
        mov     WORD PTR VFLI.cpMac_SEG,dx
; Line 712
        push    ifi.ich_Ifi
        call    FFirstIch
        or      ax,ax
        jne     $+5
        jmp     $I943
; Line 715
        mov     ax,WORD PTR VFLI.fSplat
        mov     al,1
        mov     WORD PTR VFLI.fSplat,ax
; Line 716
        cmp     fFlmPrinting,0
        je      $+5
        jmp     $I944
        ;chT EQU bp-96
        ;cch EQU bp-98
        ;dxpCh EQU bp-100
; Line 723
        mov     chT,c_chSplat
; Line 726
        push    chT
        xor     ax,ax
        push    ax
        call    FAR PTR DxpFromCh
        mov     dxpCh,ax
; Line 730
        mov     ax,17
        imul    DXPLOGINCH
        cwd
        sub     ax,dx
        sar     ax,1
        cwd
        mov     cx,dxpCh
        idiv    cx
        cmp     ax,223
        jge     $L20021
        jmp     SHORT $L20022
$L20021:
        mov     ax,223
$L20022:
        mov     cch2,ax
; Line 732
               ; ***             bltbc(&vfli.rgch[ifi.ich], chT, cch);
        mov     dx,ifi.ich_Ifi
        add     dx,OFFSET VFLI.rgch
                 ;***  macro bltbc destroys ax,es,cx
        bltbc   dx,<BYTE PTR (chT)>,cch2
; Line 733
               ; ***             bltc(&vfli.rgdxp[ifi.ich], dxpCh, cch);
        mov     dx,ifi.ich_Ifi
        shl     dx,1
        add     dx,OFFSET VFLI.rgdxp
    ;                         *** macro bltc destroys ax,es,cx
        bltc    dx,dxpCH,cch2
; Line 734
        mov     ax,ifi.ich_Ifi
        add     ax,cch2
        mov     WORD PTR VFLI.ichMac,ax
; Line 736
        push    VHMDC
        mov     ax,OFFSET VFLI.rgch
        push    ds
        push    ax
        push    cch2
        call    FAR PTR GETTEXTEXTENT
        mov     WORD PTR VFLI.xpReal_Fli,ax
; Line 737
        mov     WORD PTR VFLI.xpLeft_Fli,0
; Line 739
        jmp     $EndFormat
$I944:
; Line 741
        mov     WORD PTR VFLI.ichMac,0
; Line 743
        jmp     $EndFormat
$I943:
        mov     WORD PTR VFLI.fSplatNext, 1

        mov     ax,cchUsed
        dec     ax
        cwd
        add     WORD PTR VFLI.cpMac_OFF,ax
        adc     WORD PTR VFLI.cpMac_SEG,dx
; Line 749
        mov     WORD PTR VFLI.dcpDepend,1
; Line 750
        cmp     ifi.fPrevSpace,0
        jne     $I950
; Line 752
        mov     ax,ifi.cchSpace
        mov     ifi.cBreak_Ifi,ax
; Line 753
        mov     ax,ifi.ich_Ifi
        mov     WORD PTR VFLI.ichReal,ax
; Line 754
        mov     ax,ifi.xp
        mov     ifi.xpReal_Ifi,ax
        mov     WORD PTR VFLI.xpReal_Fli,ax
; Line 756
$I950:
        mov     ax,ifi.ich_Ifi
        mov     WORD PTR VFLI.ichMac,ax
; Line 757
        mov     ax,ifi.dypLineSize
        mov     WORD PTR VFLI.dypLine,ax
; Line 758
        jmp     $JustBreak
$SC951:
; Line 762
        dec     ifi.ich_Ifi
; Line 763
        mov     ax,dxp
        sub     ifi.xp,ax
; Line 764
        mov     ax,dxpPr
        sub     ifi.xpPr,ax
        ;xaTab EQU bp-102
        ;xaPr EQU bp-104
;       pchp EQU bp-106
;       register di=pchp
; Line 766
        mov     ax,ifi.xpPrRight
        cmp     ifi.xpPr,ax
        jl      $+5
        jmp     $I952
; Line 772
        cmp     ifi.fPrevSpace,0
        jne     $I956
; Line 776
        mov     ax,ifi.cchSpace
        mov     ifi.cBreak_Ifi,ax
; Line 777
        mov     ax,ifi.ich_Ifi
        mov     WORD PTR VFLI.ichReal,ax
; Line 778
        mov     ax,ifi.xp
        mov     ifi.xpReal_Ifi,ax
; Line 781
$I956:
        cmp     ifi._jc,c_jcTabLeft
        je      $I957
; Line 783
        lea     ax,ifi
        push    ax
        push    xpTab
        push    flm
        call    Justify
; Line 785
$I957:
        mov     ax,ifi.xp
        mov     xpPrev,ax
; Line 788
        push    ifi.xpPr
        push    DXAPRPAGE
        push    DXPPRPAGE
        call    FAR PTR MULTDIV
        mov     xaPr,ax
; Line 789
        jmp     SHORT $L20041
$WC958:
        mov     ax,xaRight
        cmp     xaTab,ax
        jb      $I959
        mov     xaTab,ax
$I959:
; Line 791
        mov     ax,xaPr
        cmp     xaTab,ax
        jb      $I960
; Line 799
        add     ptbd,4
        mov     al, [bx].jc_Tbd
        sub     ah,ah
        and     ax,7
        add     ax,c_jcTabMin
;#ifdef ENABLE /* we do the mapping in HgtbdCreate */
;        cmp    ax,c_jcTabDecimal
;        je     $I1958
;        mov    ax,c_jcTabLeft
;#endif
$I1958:
        mov     ifi._jc,ax
; Line 800
        jmp     SHORT $TabFound
$I960:
        add     ptbd,4
; Line 803
$L20041:
        mov     bx,ptbd
        mov     ax,[bx]
        mov     xaTab,ax
        or      ax,ax
        jne     $WC958
; Line 806
        mov     ax,xaPr
        sub     dx,dx
        mov     cx,WORD PTR VZATABDFLT
        div     cx
        mul     cx
        add     ax,cx
        mov     xaTab,ax
; Line 812
        mov     ifi._jc,c_jcTabLeft
; Line 814
$TabFound:
; Line 815
        push    xaTab
        push    dxpFormat
        push    dxaFormat
        call    FAR PTR MULTDIV
        cmp     ifi.xp,ax
        jle     $I1961
        mov     ax,ifi.xp
$I1961:
        mov     xpTab,ax
; Line 822
        cmp     ifi._jc,c_jcTabLeft
        jne     $I962
; Line 825
        mov     ifi.xp,ax
; Line 826
        push    xaTab
        push    DXPPRPAGE
        push    DXAPRPAGE
        call    FAR PTR MULTDIV
        mov     ifi.xpPr,ax
; Line 828
$I962:
        mov     ax,ifi.xp
        mov     ifi.xpLeft_Ifi,ax
; Line 829
        mov     ax,ifi.ich_Ifi
        mov     ifi.ichLeft,ax
; Line 830
        mov     ifi.cchSpace,0
; Line 831
        mov     ifi.chBreak,0
; Line 832
$Tab0:
; Line 833
        mov     ifi.fPrevSpace,0
; Line 834
        mov     ax,ifi.ich_Ifi
        mov     WORD PTR VFLI.ichMac,ax
; Line 835
        mov     ax,ifi.xp
        mov     WORD PTR VFLI.xpReal_Fli,ax
; Line 836
        mov     ax,ifi.dypLineSize
        mov     WORD PTR VFLI.dypLine,ax
; Line 837
        mov     ax,dypDescentMac
        mov     WORD PTR VFLI.dypBase,ax
; Line 838
        mov     ax,dypAscentMac
        add     ax,dypDescentMac
        mov     WORD PTR VFLI.dypFont,ax
; Line 841
        cmp     ifi.ichFetch,1
        je      $I963
        mov     ax,ICHPMACFORMAT
        cmp     WORD PTR $S784_ichpFormat,ax
        jne     $L20023
        call    FGrowFormatHeap
        or      ax,ax
        je      $I963
$L20023:
; Line 845
; *********** Register variables ********************
;       rdi_pchp EQU    di
; ****************************************************
;       register di=pchp
        mov     ax,10
        imul    WORD PTR $S784_ichpFormat
        mov     rdi_pchp,ax
        sub     rdi_pchp,10
        mov     bx,VHGCHPFORMAT
        add     rdi_pchp,[bx]
; Line 846
        cmp     WORD PTR $S784_ichpFormat,0
        jle     $I964
; Line 849
        mov     al,BYTE PTR (ifi.ichPrev)
        mov     BYTE PTR [rdi_pchp].ichRun,al
; Line 850
        mov     ax,ifi.ich_Ifi
        sub     ax,ifi.ichPrev
        mov     BYTE PTR [rdi_pchp].cchRun,al
; Line 853
$I964:
        add     rdi_pchp,10     ; ** ++pchp
        lea     ax,chpLocal  ; ax not destroyed in blt until after value used
                   ;*** macro blt destroys ax,bx,cx,es
        blt     ax,rdi_pchp,c_cwCHP

; Line 854
        inc     WORD PTR $S784_ichpFormat
; Line 856
        jmp     SHORT $I965
$I963:
; Line 858
        mov     ax,10
        imul    WORD PTR $S784_ichpFormat
        mov     rdi_pchp,ax
        sub     rdi_pchp,10
        mov     bx,VHGCHPFORMAT
        add     rdi_pchp,[bx]
; Line 859
$I965:
; Line 860
        mov     al,BYTE PTR (ifi.ich_Ifi)
        mov     BYTE PTR [rdi_pchp].ichRun,al
; Line 861
        or      BYTE PTR [rdi_pchp].cchRun,255

; Line 867
        mov     bx,ifi.ich_Ifi
        inc     ifi.ich_Ifi
        mov     ifi.ichPrev,bx
        shl     bx,1
        mov     ax,ifi.xp
        sub     ax,xpPrev
        mov     WORD PTR VFLI.rgdxp[bx],ax
; Line 869
        cmp     rsi_ch,c_chTab
        jne     $BreakOppr
        jmp     $GetCh
$I952:
; Line 878
        mov     rsi_ch,160
; Line 879
        jmp     $NormChar
$SC968:
; Line 883
        mov     ax,ifi.xpPrRight
        cmp     ifi.xpPr,ax
        jle     $+5
        jmp     $DoBreak
; Line 885
$BreakOppr:
; Line 891
        cmp     ifi.ich_Ifi,255
        jl      $+5
        jmp     $Unbroken
; Line 893
$SC971:
; Line 898
        mov     ifi.chBreak,rsi_ch
; Line 899
        mov     ax,ifi.ichFetch
        add     ax,cchUsed
        cwd
        add     ax,WORD PTR VCPFETCH
        adc     dx,WORD PTR VCPFETCH+2
        mov     WORD PTR VFLI.cpMac_OFF,ax
        mov     WORD PTR VFLI.cpMac_SEG,dx
; Line 900
        mov     ax,ifi.xp
        mov     WORD PTR VFLI.xpReal_Fli,ax
; Line 901
        mov     ax,ifi.ich_Ifi
        mov     WORD PTR VFLI.ichMac,ax
; Line 902
        mov     ax,ifi.dypLineSize
        mov     WORD PTR VFLI.dypLine,ax
; Line 904
        mov     ax,dypDescentMac
        mov     WORD PTR VFLI.dypBase,ax
        add     ax,dypAscentMac
        mov     WORD PTR VFLI.dypFont,ax
; Line 906
        cmp     rsi_ch,45
        je      $L20024
        cmp     rsi_ch,31
        jne     $I972
$L20024:
; Line 908
        mov     ax,ifi.cchSpace
        mov     ifi.cBreak_Ifi,ax
; Line 909
        mov     ax,ifi.ich_Ifi
        mov     WORD PTR VFLI.ichReal,ax
; Line 910
        mov     ax,ifi.xp
        mov     ifi.xpReal_Ifi,ax
        mov     WORD PTR VFLI.xpReal_Fli,ax
; Line 912
        jmp     $GetCh
$I972:
; Line 914
        cmp     ifi.fPrevSpace,0
        jne     $I974
; Line 916
        mov     ax,ifi.cchSpace
        mov     ifi.cBreak_Ifi,ax
; Line 917
        mov     ax,ifi.ich_Ifi
        dec     ax
        mov     WORD PTR VFLI.ichReal,ax
; Line 918
        mov     ax,ifi.xp
        mov     WORD PTR VFLI.xpReal_Fli,ax
        sub     ax,dxp
        mov     ifi.xpReal_Ifi,ax
; Line 920
        ;chT EQU bp-108
        ;dxpNew EQU bp-110
$I974:
        cmp     rsi_ch,10
        je      $L20025
        cmp     rsi_ch,11
        jne     $I975
$L20025:
; Line 943
        mov     chT2,c_chSpace
; Line 946
        push    chT2
        push    fFlmPrinting
        call    FAR PTR DxpFromCh
                ; *** ax will contain dxpNew at this point ****
; Line 948
        mov     bx,ifi.ich_Ifi
        mov     dl,BYTE PTR (chT2)
        mov     BYTE PTR VFLI.rgch[bx-1],dl
; Line 950
        shl     bx,1
                ;** difference was -1 in c - shifted to get -2
        mov     WORD PTR VFLI.rgdxp[bx-2],ax   ; ax has dxpNew

        cmp     ifi.fPrevSpace,0   ; only reset vfli.xp/ich real if not prev sp
        jne     $TestEol

        sub     ax,dxp
        add     WORD PTR VFLI.xpReal_Fli,ax
; Line 956
        mov     ax,ifi.ich_Ifi
        dec     ax
        mov     WORD PTR VFLI.ichReal,ax
; Line 961
$TestEol:
        cmp     rsi_ch,10
        je      $+5
        jmp     $JustBreak
; Line 963
$JustEol:
; Line 964
        cmp     fFlmPrinting,0
        je      $I979
; Line 966
        mov     ax,WORD PTR VFLI.ichReal
        mov     WORD PTR VFLI.ichMac,ax
; Line 972
$I979:
        cmp     ifi._jc,c_jcTabLeft
        je      $+5
        jmp     $L20051
; Line 980
        mov     bx,ppap
        mov     al,BYTE PTR [bx].jc_Pap
        and     ax,3        ; pick up low 2 bits in ax
        mov     ifi._jc,ax
        cmp     ax,3
        je      $I996
        jmp     SHORT $L20050
$I975:
        inc     ifi.cchSpace
; Line 995
        mov     ifi.fPrevSpace,1
; Line 1093
        jmp     $GetCh
$I987:
        mov     ax,ifi.ichFetch
        add     ax,cchUsed
        cwd
        add     ax,WORD PTR VCPFETCH
        adc     dx,WORD PTR VCPFETCH+2
        sub     ax,1
        sbb     dx,0
        mov     WORD PTR VFLI.cpMac_OFF,ax
        mov     WORD PTR VFLI.cpMac_SEG,dx
; Line 1016
        mov     ax,ifi.ich_Ifi
        dec     ax
        mov     WORD PTR VFLI.ichMac,ax
        mov     WORD PTR VFLI.ichReal,ax
; Line 1017
        mov     ax,ifi.dypLineSize
        mov     WORD PTR VFLI.dypLine,ax
; Line 1019
        mov     ax,dypDescentMac
        mov     WORD PTR VFLI.dypBase,ax
        add     ax,dypAscentMac
        mov     WORD PTR VFLI.dypFont,ax
; Line 1020
        mov     WORD PTR VFLI.dcpDepend,1
; Line 1021
        mov     ax,ifi.xp
        sub     ax,dxp
	mov	ifi.xpReal_Ifi,ax
        mov     WORD PTR VFLI.xpReal_Fli,ax
$I994:
        mov     bx,ppap
        mov     al,BYTE PTR [bx].jc_Pap
        and     ax,3
        mov     ifi._jc,ax
$L20050:
        or      ax,ax
        je      $I996
; Line 1065
        lea     ax,ifi
        push    ax
        push    ifi.xpRight_Ifi
$L20046:
        push    flm
        call    Justify
; Line 1067
$I996:
        mov     ax,ifi.xpRight_Ifi
$L20043:
        mov     WORD PTR VFLI.xpRight,ax
; Line 1068
$EndFormat:
; Line 1069
        mov     ax,ifi.ichLeft
        mov     WORD PTR VFLI.ichLastTab,ax
        jmp     SHORT $ScribRet ; Scribble and return
$L20028:
        cmp     ax,13
        jne     $+5
        jmp     $SC938
        cmp     ax,31
        jne     $+5
        jmp     $SC939
        cmp     ax,45
        jne     $+5
        jmp     $SC968
        jmp     $DefaultCh
$ScribRet:
IFDEF DEBUG
IFDEF SCRIBBLE
        mov     ax,5
        push    ax
        mov     ax,c_chSpace
        push    ax
        call    FAR PTR FNSCRIBBLE
ENDIF
ENDIF
; Line 1096
$RetFormat:
        cEnd FormatLine

        subttl Justify()
        page
; ***
;  Function Justify
;
;  near Justify(pifi, xpTab, flm)
;  struct IFI *pifi;
;  unsigned xpTab;
;  int flm;
;
; ***

; Line 1101
        cProc Justify,<PUBLIC,NEAR>,<di,si>
                parmDP  pifi
                parmW   xpTab
                parmW   flm

                LocalW  cWideSpaces
                LocalW  cxpQuotient
; *********** Register variables ********************
        rbx_pifi        EQU     bx
        rdx_dxp         EQU     dx
; ****************************************************
        cBegin Justify
; Line 1109
        mov     rbx_pifi,pifi
; Line 1110
        mov     ax,[rbx_pifi]._jc
        cmp     ax,c_jcBoth
        je      $JcBothCase
        cmp     ax,c_jcCenter
        je      $JcCenterCase
        cmp     ax,c_jcRight
        je      $JcRightCase
        cmp     ax,c_jcTabDecimal
        jne     $JustCaseBrk
; Line 1130
JcTabDecCase:
; *********** Register variables ********************
        rsi_ichT        EQU     si
; ****************************************************
        mov     rdx_dxp,xpTab
        sub     rdx_dxp,[rbx_pifi].xpLeft_Ifi
; Line 1132
        mov     rsi_ichT,[rbx_pifi].ichLeft
        inc     rsi_ichT
$TabDecFor:
        cmp     rsi_ichT,WORD PTR VFLI.ichReal
        jge     $JustCaseBrk
	mov     al,VCHDECIMAL
        cmp     BYTE PTR VFLI.rgch[rsi_ichT],al
        je      $JustCaseBrk
; Line 1134
        shl     rsi_ichT,1
        sub     rdx_dxp,WORD PTR VFLI.rgdxp[rsi_ichT]
        shr     rsi_ichT,1
; Line 1135
        inc     rsi_ichT
        jmp     SHORT $TabDecFor

$JcCenterCase:
; Line 1139
        mov     rdx_dxp,xpTab
        sub     rdx_dxp,[rbx_pifi].xpReal_Ifi
        or      rdx_dxp,rdx_dxp
        jg      $+5
        jmp     $JustifyRet
                ; **** EXIT POINT *****************************
; Line 1141
        sar     rdx_dxp,1
; Line 1144

$JustCaseBrk:
; Line 1212
        cmp     rdx_dxp,0
        jle     $+5
        jmp     $JustCleanup
; Line 1215
        jmp     $JustifyRet
                ; **** EXIT POINT *****************************

$JcRightCase:
; Line 1147
        mov     rdx_dxp,xpTab
        sub     rdx_dxp,[rbx_pifi].xpReal_Ifi
; Line 1148
        jmp     SHORT $JustCaseBrk

$JcBothCase:
; *********** Register variables ********************
        rdi_pch         EQU     di
        rsi_pdxp        EQU     si
; ***************************************************
                ; **** NOTE: the only way out of this section of code
                ; **** is through a RETURN of function Justify
; Line 1151
        cmp     WORD PTR [rbx_pifi].cBreak_Ifi,0
        jne     $+5
        jmp     $JustifyRet
                ; **** EXIT POINT *****************************
; Line 1154
        mov     rdx_dxp,xpTab
        sub     rdx_dxp,[rbx_pifi].xpReal_Ifi
        or      rdx_dxp,rdx_dxp
        jg      $+5
        jmp     $JustifyRet
                ; **** EXIT POINT *****************************
; Line 1160
        add     [rbx_pifi].xp,rdx_dxp
; Line 1164
        add     WORD PTR VFLI.xpReal_Fli,rdx_dxp
; Line 1165
; Line 1176
                ; register CHAR *pch = &vfli.rgch[vfli.ichReal]
                ; register int *pdxp = &vfli.rgdxp[vfli.ichReal]

        mov     rdi_pch,WORD PTR VFLI.ichReal
        mov     rsi_pdxp,rdi_pch

        add     rdi_pch,OFFSET VFLI.rgch

        shl     rsi_pdxp,1
        add     rsi_pdxp,OFFSET VFLI.rgdxp

   ; ************ dx /(dxp) will be wiped out and restored here !!!!!!!!!!!!!!!
        push    dx              ; save for use as dxpT

        mov     ax,dx          ; ** set up division
        cwd
        mov     cx,[rbx_pifi].cBreak_Ifi
        idiv    cx
        mov     WORD PTR VFLI.dxpExtra,ax
                ; ** at this point:
                ; **  ax = quotient, dx = remainder, cx = cbreak
        inc     ax

; *********** Register variables ********************
        rdx_dxpT        EQU     dx
; ***************************************************

        mov     cxpQuotient,ax
        mov     cWideSpaces,dx

        pop     dx              ; restore for use as dxpT

; Line 1183
        mov     BYTE PTR VFLI.fAdjSpace,c_True
; Line 1185
        ; ***** NOTE: the only way out of this loop is via a RETURN out of
        ; *****       function Justify
        ; * the immediately following loop accomplishes about the same thing as
; ** Loop:
        ;   dec rdi_pch
        ;   sub rsi_pdxp,2
        ;   cmp BYTE PTR [rdi_pch],c_chSpace
        ;   jne Loop
        ; * it should be faster for strings of > 2 characters.

        dec     rdi_pch  ; since predecrement to start pch correctly
        mov     ax,ds
        mov     es,ax   ; set up for string instruction
        std             ; use reverse direction for decrementing di
$JstForLoop:
        mov     cx,-1   ; counter set up 1 below (trick)
        mov     al,c_chSpace    ; comparison value
        repnz   scasb           ; dec di while not = space
        inc     cx              ; restore from original -1
        shl     cx,1            ; si is a word ptr  - double offset
        add     rsi_pdxp,cx
                                ; at this point, pch points 1 below
                                ; the character containing the space,
                                ; pdxp points to the entry for the space char
; Line 1192
        mov     ax,cWideSpaces
        dec     cWideSpaces
        or      ax,ax
        jne     $I1032
; Line 1194
        dec     cxpQuotient
; Line 1195
	push	rsi_pdxp	; find first nonzero ich after pch
	cld
$FindIch1:
	inc	rsi_pdxp
	inc	rsi_pdxp
	cmp	WORD PTR [rsi_pdxp],0
	je	$FindIch1
        mov     ax,rsi_pdxp
        sub     ax,OFFSET VFLI + rgdxp
	shr	ax,1
	std
	pop	rsi_pdxp

        mov     BYTE PTR VFLI.ichFirstWide,al

; Line 1197
$I1032:
        mov     ax,cxpQuotient
        add     [rsi_pdxp],ax
; Line 1198
        sub     rdx_dxpT,ax
        cmp     rdx_dxpT,0
        jg      $I1033
; Line 1200
        cmp     WORD PTR [rbx_pifi].cBreak_Ifi,1
        jle     $JustifyRet
                ; **** EXIT POINT *****************************
; Line 1202
	push	rsi_pdxp	; find first nonzero ich after pch
	cld
$FindIch2:
	inc	rsi_pdxp
	inc	rsi_pdxp
	cmp	WORD PTR [rsi_pdxp],0
	je	$FindIch2
        mov     ax,rsi_pdxp
        sub     ax,OFFSET VFLI + rgdxp
	shr	ax,1
	pop	rsi_pdxp

        mov     BYTE PTR VFLI.ichFirstWide,al
; Line 1204
        jmp     SHORT $JustifyRet
                ; **** EXIT POINT *****************************
$I1033:
        dec     WORD PTR [rbx_pifi].cBreak_Ifi
; Line 1208
        jmp     SHORT $JstForLoop  ; *** end of for loop **********


; *********** Register variables ********************
        rbx_pifi        EQU     bx
        rdx_dxp         EQU     dx
; ****************************************************

$JustCleanup:
        add     [rbx_pifi],rdx_dxp
        mov     ax,rdx_dxp
; Line 1220
        test    flm,1   ;* if (flm & flmPrinting)
        jne     $L20052
; Line 1228
        push    rdx_dxp     ; save - wiped out by multiply

        push    rdx_dxp
        mov     ax,c_czaInch
        push    ax
        push    DXPLOGINCH
        call    FAR PTR MULTDIV
        push    ax
        push    DXPPRPAGE
        push    DXAPRPAGE
        call    FAR PTR MULTDIV

        mov     rbx_pifi,pifi   ; restore in case multdiv wipes out bx
        pop     rdx_dxp     ; restore - wiped out by multdiv
$L20052:
        add     [rbx_pifi].xpPr,ax
; Line 1231
        cmp     WORD PTR [rbx_pifi].ichLeft,0
        jge     $I1038
; Line 1234
        add     WORD PTR VFLI.xpLeft_Fli,rdx_dxp
; Line 1236
        jmp     SHORT $I1039
$I1038:
; Line 1239
        mov     bx,[rbx_pifi].ichLeft ; *** here, bx is no longer pifi ****
        shl     bx,1
        add     WORD PTR VFLI.rgdxp[bx],rdx_dxp
; Line 1240
$I1039:
; Line 1241
        add     WORD PTR VFLI.xpReal_Fli,rdx_dxp
; Line 1242
$JustifyRet:
        cld     ; reset to be nice to later routines
        cEnd Justify


; Line 1247
        subttl FGrowFormatHeap()
        page

; ***
;  Function FGrowFormatHeap
;
;  int near FGrowFormatHeap()
;      /* Grow vhgchpFormat by 20% */
;
; ***

        cProc FGrowFormatHeap,<PUBLIC,NEAR>
        cBegin FGrowFormatHeap

; *********** Register variables ********************
        rsi_cchpIncr    EQU     si
; ****************************************************

; Line 1249
        mov     ax,ICHPMACFORMAT
        cwd
        mov     cx,5
        idiv    cx
        inc     ax
        mov     rsi_cchpIncr,ax
; Line 1255
        push    VHGCHPFORMAT
        add     ax,ICHPMACFORMAT
        imul    cx
        push    ax
        xor     ax,ax
        push    ax
        call    FAR PTR FCHNGSIZEH
        or      ax,ax
        jne     $I1043
; Line 1260
        xor     ax,ax
        jmp     SHORT $EX1040
$I1043:
        add     ICHPMACFORMAT,rsi_cchpIncr
; Line 1263
        mov     ax,1
$EX1040:
        cEnd    FGrowFormatHeap


; Line 1269
        subttl DxpFromCh()
        page

; ***
;  Function DxpFromCh
;
;  int DxpFromCh(ch, fPrinter)
;  int ch;
;  int fPrinter;
;
; ***


        cProc DxpFromCh,<PUBLIC,FAR>
                parmW   chIn
                parmW   fPrinter

                LocalW  dxpDummy
                LocalW  dxp
        cBegin DxpFromCh

; *********** Register variables ********************
        rbx_pdxp        EQU     bx
; ****************************************************

; Line 1276
        cmp     chIn,c_chSpace
        jg      $L20029
	cmp	chIn,c_chNRHFile
	jge	$L20026
	cmp	chIn,c_chTab
	jl	$L2029A
	cmp	chIn,c_chReturn
	jg	$L2029A
$L20026:
        cmp     fPrinter,0
        je      $L20027
        mov     rbx_pdxp,OFFSET VFMIPRINT+2
        jmp     SHORT $I1050
$L20027:
        mov     rbx_pdxp,OFFSET VFMISCREEN+2
        jmp     SHORT $I1050
$L20029:
        cmp     chIn,256    ; prev 128 (chFmiMax)  ..pault 
                            ; We now make sure the whole character set width 
                            ; table is queried initially via GetCharWidth()
        jl      $I1049
; Line 1279
$L2029A:
        lea     rbx_pdxp,dxpDummy
; Line 1280
        mov     WORD PTR [rbx_pdxp],dxpNil
; Line 1282
        jmp     SHORT $I1050
$I1049:
; Line 1285
        cmp     fPrinter,0
        je      $L20030
        mov     rbx_pdxp,WORD PTR VFMIPRINT
        jmp     SHORT $L20031
$L20030:
        mov     rbx_pdxp,WORD PTR VFMISCREEN
$L20031:
        mov     ax,chIn
        shl     ax,1
        add     rbx_pdxp,ax
; Line 1286
$I1050:
; Line 1288
        cmp     WORD PTR [rbx_pdxp],dxpNil
        jne     $I1051
; Line 1295
        push    bx              ; save pdxp

        cmp     fPrinter,0
        je      $L20032
        push    VHDCPRINTER
        lea     ax,chIn
        push    ss
        push    ax
        mov     ax,1
        push    ax
        call    FAR PTR GETTEXTEXTENT
        sub     ax,WORD PTR VFMIPRINT+4
        jmp     SHORT $L20033
$L20032:
        push    VHMDC
        lea     ax,chIn
        push    ss
        push    ax
        mov     ax,1
        push    ax
        call    FAR PTR GETTEXTEXTENT
        sub     ax,WORD PTR VFMISCREEN+4
$L20033:
        pop     bx              ; restore pdxp
; Line 1297
        ;or      ax,ax   ; ax == dxp
        ;jl      $I1053
        ;cmp     ax,dxpNil
        ;jge     $I1053
; Line 1300
        mov     [rbx_pdxp],ax
; Line 1303
$I1053:
        jmp     SHORT $DxpRet
$I1051:
        mov     ax,WORD PTR [rbx_pdxp]
$DxpRet:
        cEnd    DxpFromCh

        subttl FFirstIch()
        page
; Line 1312

; ***
;  Function FFirstIch
;
;  int near FFirstIch(ich)
;  int ich;
;    {
;      /* Returns true iff ich is 0 or preceded only by 0 width characters */
;
;   REGISTER USAGE ******************************
;      uses and restores: di
;      uses and destroys: ax, cx, es
;      ax = temp, return
;      cx = ich
;      di = pdxp
;
;  Note: this implements, in a different manner, the c code:
;
;     for (ichT = 0; ichT < ich; ichT++)
;        {
;          if (*pdxp++)
;             return false
;         }
;    return true;
; ***

        cProc FFirstIch,<PUBLIC,NEAR>,<di>
                parmW   ich

        cBegin FFirstIch

; *********** Register variables ********************
        rdi_pdxp        EQU     di
        rcx_ich EQU     cx
; ****************************************************
; Line 1316
        mov     ax,ds   ; set es=ds for string ops
        mov     es,ax

        mov     rdi_pdxp,OFFSET VFLI.rgdxp
        mov     rcx_ich,ich     ; loop count in cx
        cld

        xor     ax,ax         ; this does 3 things:
                                ;  - sets up the compare value for scasb
                                ;  - sets a 0 (false) default return value
                                ;  - sets the zero flag on. This will allow
                                ; a zero value of ich to correctly return
                                ; true. This instruction MUST immediately
                                ; precede the repz scasw instruction.
        repz    scasw           ; test *pdxp = 0
        jnz     $FFRet          ; non zero char found - return false
        inc     ax              ; return TRUE if all 0 or ich = 0
$FFRet:
        cEnd    FFirstIch


        subttl ValidateMemoryDC()
        page

;       ValidateMemoryDC()

        cProc ValidateMemoryDC,<PUBLIC,FAR>
        cBegin ValidateMemoryDC

; /* Attempt to assure that vhMDC and vhDCPrinter are valid.  If we have not
; already run out of memory, then vhDCPrinter is guaranteed, but vhMDC may
; fail due to out of memory -- it is the callers responsibility to check for
; vhMDC == NULL. */

; /* If we are out of memory, then we shouldn't try to gobble it up by getting
; DC's. */
        cmp     VFOUTOFMEMORY,0
        jne     $I862
        cmp     VHMDC,0
        jne     $I858
        mov     bx,PWWDCUR
        push    WORD PTR [bx+50]
        call    FAR PTR CREATECOMPATIBLEDC
        mov     VHMDC,ax
; /* Callers are responsible for checking for vhMDC == NULL case */
        or      ax,ax
        je      $I858
; /* Put the memory DC in transparent mode. */
        push    ax
        mov     ax,1
        push    ax
        call    FAR PTR SETBKMODE
; /* If the display is a monochrome device, then set the text color for the
; memory DC.  Monochrome bitmaps will not be converted to the foreground and
; background colors in this case, we must do the conversion. */
        mov     bx,PWWDCUR
        push    WORD PTR [bx+50]
        mov     ax,24
        push    ax
        call    FAR PTR GETDEVICECAPS
        cmp     ax,2
        jne     $I854
        mov     ax,1
        jmp     SHORT $I856
$I854:
        xor     ax,ax
$I856:
        mov     VFMONOCHROME,ax
        or      ax,ax
        je      $I858
        push    VHMDC
        push    WORD PTR RGBTEXT+2
        push    WORD PTR RGBTEXT
        call    FAR PTR SETTEXTCOLOR
$I858:
; /* If the printer DC is NULL then we need to restablish it. */
	cmp	VHDCPRINTER,0
	jne	$I862
	xor	ax,ax
	push	ax
	call	FAR PTR GETPRINTERDC
$I862:
        cEnd ValidateMemoryDC

        sEnd FORM1_TEXT
END