summaryrefslogtreecommitdiff
path: root/ddt180.z80
blob: 3e6f95f84a134c877370bc0a06e48551623cd011 (plain)
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
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
; Disassembled ddtz.com, version "DDT/Z    [8101]"
; with modified relocater.
;
; Build steps:
;   - Assemble to a .REL file with M80 or a compatible assembler.
;   - Use Digital Research Link-80 to generate a .PRL file (op switch).
;   - Cut the .PRL header (first 256 byte) end rename the result to DDTZ.COM.

;-------------------------------------------------------------------------------
; Relocation loader
;
TPA	equ	0100h
	cseg
	.phase	TPA

	jp	start
	ds	3

ldr_end:
ldr_size	equ	$ - TPA
current_phase	defl	$

	.dephase
current_cseg	defl	$

;-------------------------------------------------------------------------------
; DDT/Z core
;

; Some greneral definitions

BS		equ	08h
TAB		equ	09h
CR		equ	0dh
LF		equ	0ah
DEL		equ	7fh
CNTRX		equ	'X'-'@'

; CP/M memory layout

BDOS		equ	5
TPA		equ	0100h

; BDOS function calls

BDOS_PSTR	equ	9       ;Print String

; ddtz specific definitions

STACK_SIZE	equ	80	;ddtz internal stack
CONBUF_SIZE	equ	80	;Size of console input buffer
EXPR_BUF_SIZE	equ	128	;expressen buffer for conditional breakpoints
BP_CNT		equ	12	;Number of breakpoints
BP_SIZE		equ	4	;Size of a breakpoint record

;-------------------------------------------------------------------------------

ddtz_base:
	jp ddtz_bdos
l0003h:
	rst 30h
di_or_ei:
	nop
	ret
ddtz_bdos:
	jp	0

current_cseg	defl	$ - current_cseg
	.phase	current_phase + current_cseg
signon:
	db	'DDTZ/180'
	db	' - Version '
	maclib	version.inc
	defvers
	db	CR,LF,'$'
msgz80:
	db	'Z80 or better required!',cr,lf,'$'

current_phase	defl	$
	.dephase
current_cseg	defl	$
	ds	STACK_SIZE - (current_phase - signon)


stack:
reg.l2:	db	000h
reg.h2:	db	000h
reg.e2:	db	000h
reg.d2:	db	000h
reg.c2:	db	000h
reg.b2:	db	000h
reg.f2:	db	000h
reg.a2:	db	000h
	db	000h
reg.i:	db	000h
reg.iy:	dw	0000h
reg.ix:	dw	0000h
reg.f:	db	000h
reg.a:	db	000h
reg.c:	db	000h
reg.b:	db	000h
reg.e:	db	000h
reg.d:	db	000h
reg.l:	db	000h
reg.h:	db	000h
reg_sp:	dw	TPA
reg.iff:
	db	0f3h
	db	0c3h
reg.pc:	dw	TPA

cmd_rpt:dw	mainloop

;-------------------------------------------------------------------------------

conbuf:
	db	CONBUF_SIZE

	ld sp,stack
	exx
	ld de,ddtz_base
	call cp_hl_de
	jr c,l0079h
	ex de,hl
l0079h:
	ld de,TPA
l007ch:
	dec hl
	ld (hl),000h
	ld a,h
	sub d
	ld b,a
	ld a,l
	sub e
	or b
	jr nz,l007ch
	ld a,i
	ld (reg.i),a
	ld a,0f3h
	jp po,l0093h
	ld a,0fbh
l0093h:
	ld (reg.iff),a
	call di_or_ei
	ld hl,ddtz_base
	ld l,000h
	ld (reg_sp),hl

	ld hl,(1)		;wboot addr
	ld de,?const
	ld b,6
vini_l:
	inc	hl
	inc	hl
	inc	hl
	ex	de,hl
	inc	hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
	inc	hl
	ex	de,hl
	djnz	vini_l

	jr mainloop

	ds	CONBUF_SIZE + 3 - ($ - conbuf)

;-------------------------------------------------------------------------------

?const:	jp	0		; return console input status
?conin:	jp	0		; return console input character
?cono:	jp	0		; send console output character
?list:	jp	0		; send list output character
?auxo:	jp      0		; send auxiliary output character
?auxi:	jp      0		; return auxiliary input character

CMDTAB:
	dw	ERROR ;cmd_@	;examine/substitute the displacement register @
	dw	ERROR ;cmd_A	;Assemble
	dw	cmd_B		;Breakpoints display/set/clear
	dw	ERROR ;cmd_C	;trace over Calls
	dw	cmd_D		;Display memory in hex and ascii
	dw	ERROR		;
	dw	ERROR ;cmd_F	;specify Filename and command line
	dw	cmd_G		;Go
	dw	cmd_H		;compute Hex and other expressions
	dw	cmd_I		;Input a byte from port
	dw	ERROR		;
	dw	ERROR		;
	dw	cmd_L		;List disassembled code
	dw	cmd_M		;Move memory [and verify]
	dw	ERROR		;
	dw	cmd_O		;Output a byte to port
	dw	ERROR		;
	dw	cmd_Q		;Qery memory for byte string
	dw	cmd_R		;Read binary or hex file
	dw	cmd_S		;Substitute memory
	dw	cmd_T		;Trace
	dw	ERROR		;
	dw	cmd_V		;Verify (compare) two memory areas
	dw	ERROR ;cmd_W	;Write a file to disk
	dw	cmd_X		;eXamine [and substitute] registers
	dw	ERROR ;cmd_Y	;examine [and substitute] Y variables
	dw	cmd_Z		;Zap (fill) memory with a byte string

ERROR:
	call	pstr_inl
	dc	'?',CR,LF
	;fall thru
mainloop:
	ld sp,stack
	ld hl,(reg.pc)
	call bp_clr_temporary
	ld hl,(cmd_rpt)
	ld de,mainloop
	push de
	call cp_hl_de
	ld a,'>'
	call outchar
	call nz,outchar
	call z,outbl
	call get_line
	call skipbl
	jr z,exe_hl
	pop hl
	push hl
	ld (cmd_rpt),hl
	inc de
	sub '@'
	jr c,ERROR
	cp 'Z'+1-'@'
	jr nc,ERROR
	ld hl,CMDTAB
	call add_hl_a2
	ld a,(hl)
	inc hl
	ld h,(hl)
	ld l,a
exe_hl:
CALL_HL:
	jp (hl)

;-------------------------------------------------------------------------------

crlf:
	call	pstr_inl
	dc	CR,LF
	xor a
	ld (con_col),a
	call inchar
	jr c,mainloop
	ret

sub_01d9h:
	call	pstr_inl
	dc	'-'
	dec hl
	jp cpl.hl

out_hl_dec_neg:
	push hl
	call sub_01d9h
	defb 03eh		;ld a,..  swallow push hl
out.hl.dec:
	push hl
	ld b,006h
	call sub_01f9h
	pop hl
	call	pstr_inl
	dc	'.'
l01f3h:
	call outbl
	djnz l01f3h
	ret

sub_01f9h:
	dec b
	push de
	ld de,10
	call div_hl_de
	ld a,h
	or l
	call nz,sub_01f9h
	ld a,e
	pop de
	jr out_dgt

out_hl_neg:
	push hl
	call sub_01d9h
	call out_hl
	pop hl
	ret

out_hl:
	ld a,h
	call out_hex
	ld a,l

out_hex:
	push af
	rra
	rra
	rra
	rra
	call out_dgt
	pop af

out_dgt:
	or	0f0h
	daa
	add	a,0a0h
	adc	a,040h
	jr outchar

out.bin.w:
	ld a,h
	call out.bin.b
	ld a,l
out.bin.b:
	ld b,8
l01c9h:
	rlca
	push	af
	ld	a,'0'/2
	adc	a,a
	call	outchar
	pop af
	djnz l01c9h
	ld a,'"'
	jr outchar

out.ascii:
	push bc
	ld c,a
	res 7,a
	cp ' '
	push af
	call nc,outbl
	call	pstr_inl
	dc	''''
	pop af
	jr nc,l0242h
	sub 0c0h
	ld b,a
	call	pstr_inl
	dc	'^'
	ld a,b
l0242h:
	call outchar
	cp ''''
	call z,outchar
	call	pstr_inl
	dc	''''
	sla c
	pop bc
	ret nc
	ld a,'.'
	jr outchar

outbl6:
	call outbl2
outbl4:
	call outbl2
outbl2:
	call outbl
outbl:
	ld a,' '
outchar:
	push ix
	push iy
	push hl
	push de
	push bc
	push af
	and 07fh
	ld	c,a
	call	?cono
	ld hl,con_col
	inc (hl)
	pop af
	pop bc
	pop de
	pop hl
	pop iy
	pop ix
	ret

pstr_sel:
	inc b
	jr pstr_sel2
pstr_sel1:
	call sub_0345h
pstr_sel2:
	djnz pstr_sel1
	;fall thru
pstr:
	ld a,(hl)
	inc hl
	and a
	ret z
	call outchar
	ret m
	jr pstr

pstr_inl:
	ex	(sp),hl
	call	pstr
	ex	(sp),hl
	ret

p_goto_col:
	ld	a,(con_col)
	cp	c
	ret	nc
	ret	z
	call	outbl
	jr	p_goto_col

;-------------------------------------------------------------------------------

incharw:
	call inchar
	jr nc,incharw
	ret

;-------------------------------------------------------------------------------

inchar:
	push ix
	push hl
	push de
	push bc
	call	?const
	and a
	jr	z,inch1
	call	?conin
	scf
inch1:
	pop bc
	pop de
	pop hl
	pop ix
	ret

;-------------------------------------------------------------------------------

DELC:
	ld	a,b
	or	a
	ret	z
	call	DELC1
	dec	hl
	dec	b
	inc	c
	ld	a,(hl)
	cp	' '
	ret	nc
DELC1:
	call	pstr_inl
	dc	BS,' ',BS
	ret

DELL:
	ld a,b			;
	or a			;
	ret z			;
	call DELC		;
	jr DELL			;

;-------------------------------------------------------------------------------

get_line:
	push hl			;
	ld hl,conbuf		;
	ld c,(hl)		;
	inc hl			;
	ld b,000h		;
	inc hl			;
inlnxtch:
	ld a,c			;
	or a			;
	jr z,inl_e		;
	call incharw		;
	cp CR			;
	jr z,inl_e		;Accept line
	cp LF			;
	jr z,inl_e		;Accept line

	cp BS			;
	jr z,gl_1		;
	cp DEL			;
	jr nz,gl_2		;
gl_1:
	call DELC		;Delete Char
	jr inlnxtch		;
gl_2:
	cp CNTRX		;
	jr nz,gl_3		;
	call DELL		;Delete Line
	jr inlnxtch		;
gl_3:
	cp TAB			;
	jr nz,gl_4		;
	ld a,' '		;
gl_4:
	ld (hl),a		;
	cp ' '			;
	jr nc,gl_5		;
	ld a,'^'		;Controll characters
	call outchar		;
	ld a,(hl)		;
	add a,'@'		;
gl_5:
	call outchar		;
	inc hl			;
	inc b			;
	dec c			;
	jr inlnxtch		;

inl_e:
	ld (hl),0
	ld hl,conbuf+1		;
	ld (hl),b		;
	call CRLF		;
	inc	hl
	ex	de,hl
	pop hl			;
	ret			;

;-------------------------------------------------------------------------------

get_char_upper:
	ld a,(de)
toupper:
	cp 'a'
	ret c
	cp 'z'+1
	ccf
	ret c
	and 05fh
	ret

;-------------------------------------------------------------------------------

skipbl0:
	inc de
skipbl:
	call get_char_upper
	cp ' '
	jr z,skipbl0
	or a
	ret

;-------------------------------------------------------------------------------

next_arg:
	call skipbl
	cp ','
	ret nz
	call skipbl0
	cp a
	ret

assert_eol:
	call skipbl
	ret z
to_error:
	jp ERROR

;-------------------------------------------------------------------------------

chk_stack:
	push hl
	push de
	ld hl,0
	add hl,sp
	ld de,stack-(STACK_SIZE-28)
	call cp_hl_de
	pop de
	pop hl
	jr c,to_error
	ret

;-------------------------------------------------------------------------------

add_hl_a2:
	add a,a
add_hl_a:
	add a,l
	ld l,a
	ret nc
	inc h
	ret

cp_hl_de:
	and a
	sbc hl,de
	add hl,de
	ret

;-------------------------------------------------------------------------------

lookupch:
	ld b,0
l02f5h:
	ld a,(hl)
	and a
	ret z
	call get_char_upper
	cp (hl)
	jr z,l0300h
	inc hl
	inc b
	jr l02f5h
l0300h:
	scf
	inc de
	ret

sub_0303h:
	ld hl,t_reg_names
	ld b,07fh
l030ch:
	inc b
	ld a,(hl)
	and a
	ret z
	call sub_031ch
	jr nc,l030ch
	res 7,b
	ret

sub_031ch:
	push bc
	push de
l031eh:
	call get_char_upper
	xor (hl)
	and 07fh
	jr nz,l0336h
	bit 7,(hl)
	inc hl
	inc de
	jr z,l031eh
	scf
	bit 7,b
	call z,sub_060ch
	jr nc,l0339h
	pop af
	scf
	pop bc
	ret
l0336h:
	call sub_0345h
l0339h:
	pop de
	and a
	pop bc
	ret

sub_0345h:
	ld a,(hl)
	and a
	ret z
l0348h:
	ld a,(hl)
	inc hl
	and a
	ret m
	jr l0348h

sub_034eh:
	call get_arg_range
	push hl
	push bc
	call next_arg
	call sub_0363h
	ex de,hl
	pop bc
	pop hl
	ret

sub_035dh:
	call expr
	jr c,error0
	ret

sub_0363h:
	call sub_035dh
l0366h:
	jp assert_eol

get_lastarg_def:
	call get_arg_def
	jr l0366h

get_arg_def:
	push hl
	call expr
	jr c,l0375h
	ex (sp),hl
l0375h:
	pop hl
	ret

sub_0377h:
	call b_037c_start
	jr l0366h

b_037c_start:
	defb 0e6h		;and a,..  clear carry
get_arg_range:
	scf
	ex af,af'
	push bc
	push hl
	call expr
	jr nc,l038ch
	ex af,af'
	jr c,error0
	ex af,af'
	pop hl
	defb 03eh		;ld a,..  swallow pop af
l038ch:
	pop af
	call get_range
	jr nc,l0398h
	ex af,af'
	pop bc
	ret nc
error0:
	jp ERROR
l0398h:
	pop af
	ret

get_range:
	call next_arg
	cp 'S'
	jr nz,l03a2h
	inc de
l03a2h:
	push hl
	push af			;'S' flag
	call expr
	jr c,l03b8h
	ld b,h
	ld c,l
	pop af
	pop hl
	jr z,l03b6h		;'S'?
	ld a,c
	sub l
	ld c,a
	ld a,b
	sbc a,h
	ld b,a
	inc bc
l03b6h:
	and a
	ret
l03b8h:
	pop af
	pop hl
	jr z,error0		;'S', but no expression following
	scf
	ret

;-------------------------------------------------------------------------------

expr:
	call skipbl
expr1:
	call do_factor
	ret c
l0433h:
	call do_binary_op
	push hl
	push bc
	call do_factor
	pop bc
	ex de,hl
	ex (sp),hl
	jr nc,l0447h
	pop de
	ld a,b
	or c
	ret z
	jp ERROR

l0447h:
	ld a,b
	or c
	push bc
	ret nz
	pop bc

doop_add:
	add hl,de
l044dh:
	pop de
	jr l0433h

doop_sub:
	and a
	sbc hl,de
	jr l044dh

doop_mlt:
	push bc
	ld b,h
	ld c,l
	ld hl,0
	ld a,010h
l045dh:
	add hl,hl
	ex de,hl
	add hl,hl
	ex de,hl
	jr nc,l0464h
	add hl,bc
l0464h:
	dec a
	jr nz,l045dh
	pop bc
	jr l044dh

doop_div:
	call div_hl_de
	jr l044dh

doop_mod:
	call div_hl_de
	ex de,hl
	jr l044dh

; divide x/y
;     hl: x
;     de: y
;   return:
;     hl: q  (x/y)
;     de: r  (x%y)

div_hl_de:
	push	bc
	ex	de,hl		;de: x
	ld	b,h		;bc: y
	ld	c,l
	ld	hl,0		;hl: r
	ld	a,16

;  de: x   (x shifted out, q shifted in)
;  bc: y
;  hl: r   (initially 0)

div_lp:
	ex	de,hl
	add	hl,hl		;x <<= 1
	ex	de,hl
	adc	hl,hl		;r <<= 1
	inc	de
	or	a
	sbc	hl,bc
	jr 	nc,div_norestore
	dec	de
	add	hl,bc
div_norestore:
	dec	a
	jr	nz,div_lp
	ex	de,hl
	pop	bc
	ret

doop_and:
	ld a,h
	and d
	ld h,a
	ld a,l
	and e
	ld l,a
	jr l044dh

doop_or:
	ld a,h
	or d
	ld h,a
	ld a,l
	or e
	ld l,a
	jr l044dh

doop_xor:
	ld a,h
	xor d
	ld h,a
	ld a,l
	xor e
	ld l,a
	jr l044dh

do_binary_op:
	push hl
	ld hl,tab_op_a
	call lookupch
	ld a,b
	ld hl,tblf_opa
	call add_hl_a2
	ld c,(hl)
	inc hl
	ld b,(hl)
	pop hl
	ret

tab_op_a:
	DB	'+-*/%&!#',0

tblf_opa:
	dw	doop_add
	dw	doop_sub
	dw	doop_mlt
	dw	doop_div
	dw	doop_mod
	dw	doop_and
	dw	doop_or
	dw	doop_xor
	dw	0

;-------------------------------------------------------------------------------

fact_factor:
	call do_factor
	ret nc
	jp ERROR

do_factor:
	call chk_stack
	call get.number
	ret nc
	inc de
	ld hl,ddtz_base-1
	cp 'T'
	ret z
	ld hl,(high_load)
	cp 'H'
	ret z
	ld hl,(max_load)
	cp 'M'
	ret z
	ld hl,TPA
	cp 'L'
	ret z
	cp '-'
	jr z,fact_factneg
	cp '~'
	jr z,fact_factinv
	cp '+'
	jr z,fact_factor
	cp '^'
	jr z,fact_reg.CPU
	cp '('
	jr z,fact_mem
	cp '['
	jr z,expr_brckt
	cp ''''
	jr z,fact_factstring
	dec de
	scf
	ret

;-------------------------------------------------------------------------------

fact_factstring:
	ld hl,0
l054bh:
	ld a,(de)
	cp ''''
	jr z,l0557h
	and a
	ret z
l0552h:
	ld h,l
	ld l,a
	inc de
	jr l054bh
l0557h:
	inc de
	ld a,(de)
	cp ''''
	jr z,l0552h
	sub '.'
	or a
	ret nz
	inc de
	set 7,l
	ret

fact_reg.CPU:
	call sub_0caeh
	jr nc,error1
	ld a,(hl)
	inc hl
	ld h,(hl)
	ld l,a
	and a
	bit 0,c
	ret nz
	ld h,000h
	ret

fact_factneg:
	call fact_factor
	dec hl
cpl.hl:
	ld a,h
	cpl
	ld h,a
	ld a,l
	cpl
	ld l,a
	ret

fact_factinv:
	call fact_factor
	jr cpl.hl

fact_mem:
	call expr1
	jr c,error1
	ld a,(de)
	cp ')'
	jr nz,error1
	inc de
	ld a,(hl)
	inc hl
	ld h,(hl)
	ld l,a
	ld a,(de)
	inc de
	cp '.'
	ret z
	dec de
	xor a
	ld h,a
	ret

expr_brckt:
	call expr1
	jr c,error1
	ld a,(de)
	cp ']'
	inc de
	ret z
error1:
	jp ERROR

;-------------------------------------------------------------------------------

get.number:
	call get.hexdigit
	ret c
	push de
test_number:
	inc de
	call get.hexdigit
	jr nc,test_number
	pop de
	cp '.'
	jr z,get_dec_number
	cp '"'
	jr z,get_bin_number
	ld hl,0
next_hexdigit:
	call get.hexdigit
	jr c,hexnum_done
	add hl,hl
	add hl,hl
	add hl,hl
	add hl,hl
	call add_hl_a
	inc de
	jr next_hexdigit

hexnum_done:
	xor 'H'
	ret nz
	inc de
	ret

get_bin_number:
	ld hl,0
next_bindigit:
	call get.bindigit
l05dbh:
	inc de
	jr c,l05e4h
	add hl,hl
	call add_hl_a
	jr next_bindigit
l05e4h:
	cp '"'
	jr nz,error11
	call get.bindigit
	jr nc,l05dbh
	or a
	ret

get_dec_number:
	ld hl,0
next_decdigit:
	call get.decdigit
	inc de
	jr c,decnum_done
	push bc
	add hl,hl
	ld b,h
	ld c,l
	add hl,hl
	add hl,hl
	add hl,bc
	pop bc
	call add_hl_a
	jr next_decdigit
decnum_done:
	cp '.'
	ret z
error11:
	jp ERROR

sub_060ch:
	call get_char_upper
	cp 'Z'+1
	jr l0614h

get.hexdigit:
	ld a,(de)
hex_digit:
	call toupper
	cp 'F'+1
l0614h:
	ccf
	ret c
	cp 'A'
	jr c,l061eh
	sub 'A'-10
	ret

get.decdigit:
	call get_char_upper
l061eh:
	cp '9'+1
	jr l0625h

get.bindigit:
	call get_char_upper
	cp '1'+1
l0625h:
	ccf
	ret c
	cp '0'
	ret c
	sub '0'
	ret

;-------------------------------------------------------------------------------

p_cpustat0:
	call assert_eol
p_cpustat:
	call p_f
	call outbl2
	ld hl,b_06e9_start
	ld de,b_0709_start
	ld b,6
l063eh:
	call p_regs
	djnz l063eh
	call outbl6
	push hl
	push de
	ld iy,(reg.pc)
	call p_disas_instr
	pop de
	pop hl
	call crlf
	call p_f2
	call outbl2
	ld b,7
l065bh:
	call p_regs
	djnz l065bh
	jp crlf

p_f:
	ld a,(reg.f)
	call p_flags
	ld a,(reg.iff)
	cp 0f3h
	jr z,outbl_1
	ld a,'E'
	jp outchar
p_f2:
	ld a,(reg.f2)
	call p_flags
	jr outbl_1

p_flags:
	push	hl
	ld	hl,t_flag_names+7
	ld	c,a
	ld	b,8
fl_loop:
	ld	a,' '
	cp	(hl)
	ld	a,c
	rlca
	ld	c,a
	jr	z,fl_skip
	ld	a,(hl)
	call	c,outchar
	call	nc,outbl
fl_skip:
	dec	hl
	djnz	fl_loop
	pop	hl
	ret

p_regs:
	push de
	call pstr
	call	pstr_inl
	dc	'='
	ex (sp),hl
	ld e,(hl)
	inc hl
	ld d,(hl)
	inc hl
	ld a,(hl)
	inc hl
	push hl
	and a
	jr z,l06deh
	ex de,hl
	ld e,(hl)
	inc hl
	ld d,(hl)
	ex de,hl
	call out_hl
	jr l06e2h
l06deh:
	ld a,(de)
	call out_hex
l06e2h:
	pop de
	pop hl
outbl_1:
	jp outbl

b_06e9_start:
	DC	'A '
	DC	'BC '
	DC	'DE '
	DC	'HL '
	DC	'SP'
	DC	'PC'
	DC	'a'''
	DC	'bc'''
	DC	'de'''
	DC	'hl'''
	DC	'IX'
	DC	'IY'
	DC	'I'
	DB	0

b_0709_start:
	dw	reg.a
	db	000h
	dw	reg.c
	db	001h
	dw	reg.e
	db	001h
	dw	reg.l
	db	001h
	dw	reg_sp
	db	001h
	dw	reg.pc
	db	002h
	dw	reg.a2
	db	000h
	dw	reg.c2
	db	001h
	dw	reg.e2
	db	001h
	dw	reg.l2
	db	001h
	dw	reg.ix
	db	001h
	dw	reg.iy
	db	001h
	dw	reg.i
	db	000h
	db	000h

;-------------------------------------------------------------------------------
; > G [startaddr] [;breakp..]
;      Go [to start] [with temporary breakpoints]

cmd_G:
	sub a
	ld (bp_p_cpu_flag),a
	call expr
	jr c,l0740h
	ld (reg.pc),hl
l0740h:
	call skipbl
	jr z,user_go0
	cp ';'
	jp nz,ERROR
	inc de
	ld a,002h
	call bp_enter
user_go0:
	jp user_go

;-------------------------------------------------------------------------------

bpl_init:
	ld	b,BP_CNT
	ld	ix,bp_tab
	ex	(sp),hl
	ld	(pbl_loop_adr),hl
	ex	(sp),hl
	ret

bpl_next:
	ld	de,BP_SIZE
	push	af
	add	ix,de
	pop	af
	dec	b
	ret	z

	ex	(sp),hl
	ld	hl,(pbl_loop_adr)
	ex	(sp),hl
	ret

bp_clr_temporary:
	call	bpl_init

	ld a,(ix+000h)
	and 0f1h
	ld (ix+000h),a

	call bpl_next
	ret

;-------------------------------------------------------------------------------
; > B
;      display all breakpoints
; > B breakp [breakp..]
;      set breakpoints
; > BX
;      clear all breakpoints
; > BX breakp [breakp..]
;      clear breakpoints
;
; breakp can be any valid expression

cmd_B:
	call skipbl
	jr z,bp_print
	inc de
	cp 'X'
	jr z,bp_clr0
	dec de
	ld a,001h
	jp bp_enter

bp_clr0:
	call skipbl
	jr z,bp_clr_all
bp_clr_next:
	call expr
	jp c,assert_eol
	push de
	call bp_clr
	pop de
	call next_arg
	jr bp_clr_next

bp_clr_all:
	scf
bp_clr:
	call	bpl_init

	push af
	jr c,l07a7h
	ld e,(ix+002h)
	ld d,(ix+003h)
	call cp_hl_de
	jr nz,l07aeh
l07a7h:
	ld (ix+000h),000h
l07aeh:
	pop af
	call bpl_next
	ret

bp_print:
	ld	c,0
	call	bpl_init

	bit 0,(ix+000h)
	jr z,bp_pr_cont
	ld l,(ix+002h)
	ld h,(ix+003h)
	call out_hl
	call outbl2
	inc	c
bp_pr_cont:
	call bpl_next
	ld	a,c
	or	a
	call 	nz,crlf
	ret

;-------------------------------------------------------------------------------
; Add break points to list
;   A = 1	 Permanent (B command)
;   A = 2	 Temporary (G command)

bp_enter:
	ld b,a
	call skipbl
	ret z

	push bc
	call expr
	jr c,error12
	pop bc
	bit 0,b
	push bc
	push de
	push hl
	call nz,bp_clr
	pop hl
	call bp_get_freeslot
	pop de
	ld (ix+002h),l
	ld (ix+003h),h
	call next_arg
	pop af
	ld (ix+000h),a
	and 00fh
	jr bp_enter

bp_get_freeslot:
	call	bpl_init

	ld a,(ix+000h)
	and 00fh
	ret z

	call	bpl_next
error12
	jp ERROR


;-------------------------------------------------------------------------------
; Breakpoint handling routine.

bpddtz:
	ld (reg.l),hl
	pop hl
	dec hl
	ld (reg.pc),hl
	ld (reg_sp),sp
	ld sp,reg.l
	push de
	push bc
	push af
	push ix
	push iy
	ld a,i
	call di_or_ei
	ld h,a
	ld l,000h
	push hl
	ld a,0f3h		; EI
	jp po,l08dfh
	ld a,0fbh		; DI
l08dfh:
	ld (reg.iff),a
	ex af,af'
	push af
	exx
	push bc
	push de
	push hl
	call bp_restore_mem
	ld a,(b_21e2_start)
	dec a
	jr z,l090bh
	call inchar		;Keyboard hit?
	jr c,do_break		;yes
	call sub_0913h
	and a
	jp z,user_go
	and 083h
	jp z,l2151h
do_break:
	call bp_clr_temporary
	call p_cpustat
	jp mainloop

l090bh:
	ld (b_21e2_start),a
	ld c,007h
	jp l0a41h

sub_0913h:
	ld a,080h
	ex af,af'
	sub a
	ld (bp_p_cpu_flag),a
	call	bpl_init

	ld a,(ix+000h)
	and 007h
	jr z,l0938h
	ld e,(ix+002h)
	ld d,(ix+003h)
	ld hl,(reg.pc)
	call cp_hl_de
	jr nz,l0938h
	ex af,af'
	res 7,a
	or (ix+000h)
	ex af,af'
l0938h:
	call	bpl_next
	ex af,af'
	ret

bp_restore_mem:
	call	bpl_init

	bit 5,(ix+000h)
	res 5,(ix+000h)
	jr z,l099ah
	ld l,(ix+002h)
	ld h,(ix+003h)
	ld a,(l0003h)
	cp (hl)
	jr nz,l099ah
	ld a,(ix+001h)
	ld (hl),a
l099ah:
	res 3,(ix+000h)

	call	bpl_next
	ret

bp_tst_@pc:
	call	bpl_init

	ld a,(ix+000h)
	and 003h
	jr z,bp_tst_e
	ld e,(ix+002h)
	ld d,(ix+003h)
	ld hl,(reg.pc)
	call cp_hl_de
	ret z
bp_tst_e:
	call	bpl_next
	sub a
	inc a
	ret

bp_trace_enter:
	call bp_get_freeslot
	ld (ix+002h),l
	ld (ix+003h),h
	ld a,(b_21e2_start)
	and a
	ld a,008h
	jr nz,bp_t_e
	rra
bp_t_e:
	ld (ix+000h),a
	ret

bp_set_to_mem:
	call	bpl_init

	ld a,(ix+000h)
	and c
	jr z,l0a1dh
	set 5,(ix+000h)
	ld l,(ix+002h)
	ld h,(ix+003h)
	ld a,(hl)
	ld (ix+001h),a
	ld a,(l0003h)
	ld (hl),a
	and 038h
	ld h,000h
	ld l,a
	ld (hl),0c3h
	inc hl
	ld de,bpddtz
	ld (hl),e
	inc hl
	ld (hl),d
l0a1dh:

	call	bpl_next
	ret

;-------------------------------------------------------------------------------

user_go:
	sub a
	ld (b_21e2_start),a
	ld a,(bp_p_cpu_flag)
	and a
	call nz,p_cpustat
	call bp_tst_@pc
	ld c,007h
	jr nz,l0a41h
	ld a,001h
	ld (b_21e2_start),a
	call tc_set_bp
	ld c,008h
l0a41h:
	call bp_set_to_mem
	ld sp,reg.l2
	pop hl
	pop de
	pop bc
	pop af
	exx
	ex af,af'
	pop af
	ld i,a
	pop iy
	pop ix
	pop af
	pop bc
	pop de
	pop hl
	ld sp,(reg_sp)
	jp reg.iff

;-------------------------------------------------------------------------------
; > Y
;      examine all Y variables
; > Y[0..9]
;      examine (and substitute) an Y variable


;-------------------------------------------------------------------------------
; > X
;      eXamine (display) all cpu registers and
;      the instruction at the current program counter
; > X register
;      eXamine (and substitute) a register


cmd_X:
	call skipbl
	call sub_0caeh
	jp nc,p_cpustat0
	call assert_eol
	ld a,b
	cp 25
	jr z,l0c5fh
	cp 26
	jr z,l0c4fh
	ex de,hl
	ld hl,t_reg_names
	call pstr_sel
	call l0c33h

	call outbl
	push de
	push bc
	call get_line
	call skipbl
	jr z,l0c30h
	call sub_0363h
	ex de,hl
	pop bc
	pop hl
	ld (hl),e
	bit 0,c
	ret z
	inc hl
	ld (hl),d
	ret
l0c30h:
	pop af
	pop hl
	ret

l0c33h:
	call	pstr_inl
	dc	'='
	ld a,(de)
	bit 0,c
	jp z,out_hex
	ld l,a
	inc de
	ld a,(de)
	dec de
	ld h,a
	jp out_hl

l0c4fh:
	call p_f
	ld a,0f3h
	ld (reg.iff),a
	scf
	call sub_0c6ah
	ld (reg.f),a
	ret
l0c5fh:
	call p_f2
	and a
	call sub_0c6ah
	ld (reg.f2),a
	ret

sub_0c6ah:
	push af
	call outbl
	call assert_eol
	call get_line
	pop af
	ex af,af'
	ld b,0
l0c76h:
	call skipbl
	ld a,b
	ret z
	push bc
	ld hl,t_flag_names
	call lookupch
	jp nc,ERROR
	inc	b
	xor	a
	scf
nxt_f:
	rla
	djnz	nxt_f
	pop	bc
	jr	c,l0c97h
	or	b
	ld	b,a
	jr l0c76h

l0c97h:
	ex af,af'
	jp nc,ERROR
	ex af,af'
	ld a,0fbh
	ld (reg.iff),a
	jr l0c76h

t_flag_names:
	db	'CNV H ZSE',0

sub_0caeh:
	call sub_0303h
	ret nc
	ld a,b
	add a,b
	add a,b
	ld hl,b_0cfa_start
	call add_hl_a
	ld c,(hl)
	inc hl
	ld a,(hl)
	inc hl
	ld h,(hl)
	ld l,a
	scf
	ret

t_reg_names:
	DC	'BC'''		;0
	DC	'DE'''		;1
	DC	'HL'''		;2
	DC	'BC'		;3
	DC	'DE'		;4
	DC	'HL'		;5
	DC	'A'''		;6
	DC	'B'''		;7
	DC	'C'''		;8
	DC	'D'''		;9
	DC	'E'''		;10
	DC	'H'''		;11
	DC	'L'''		;12
	DC	'A'		;13
	DC	'B'		;14
	DC	'C'		;15
	DC	'D'		;16
	DC	'E'		;17
	DC	'H'		;18
	DC	'L'		;19
	DC	'IX'		;20
	DC	'IY'		;21
	DC	'SP'		;22
	DC	'PC'		;23
	DC	'I'		;24
	DC	'F'''		;25
	DC	'F'		;26
	DB	0

b_0cfa_start:
	db	003h
	dw	reg.c2
	db	003h
	dw	reg.e2
	db	003h
	dw	reg.l2
	db	003h
	dw	reg.c
	db	003h
	dw	reg.e
	db	003h
	dw	reg.l
	db	000h
	dw	reg.a2
	db	000h
	dw	reg.b2
	db	000h
	dw	reg.c2
	db	000h
	dw	reg.d2
	db	000h
	dw	reg.e2
	db	000h
	dw	reg.h2
	db	000h
	dw	reg.l2
	db	000h
	dw	reg.a
	db	000h
	dw	reg.b
	db	000h
	dw	reg.c
	db	000h
	dw	reg.d
	db	000h
	dw	reg.e
	db	000h
	dw	reg.h
	db	000h
	dw	reg.l
	db	003h
	dw	reg.ix
	db	003h
	dw	reg.iy
	db	003h
	dw	reg_sp
	db	003h
	dw	reg.pc
	db	000h
	dw	reg.i
	db	000h
	dw	reg.f2
	db	000h
	dw	reg.f

;-------------------------------------------------------------------------------
; > S [startaddr]
;      Substitute memory

cmd_S:
	ld hl,(last_S)
	call get_lastarg_def
l0d60h:
	ld (last_S),hl
	call out_hl
	call outbl
	ld a,(hl)
	call out_hex
	call outbl2
	call get_line
	call skipbl
	inc hl
	jr z,l0d60h
	dec hl
	inc de
	cp '.'
	jr	nz,cmds_dash
	call get_char_upper
	or	a
	jr	nz,l0d8ah
	ret
cmds_dash:
	jp z,assert_eol
	cp '-'
	jr nz,l0d8ah
	call get_char_upper
	or a
	dec hl
	jr z,l0d60h
	inc hl
l0d8ah:
	dec de
	call sub_0ef8h
	jr l0d60h

;-------------------------------------------------------------------------------
; > @
;      examine (substitute) displacement register @

;cmd_@:

;-------------------------------------------------------------------------------
; >>I [port]
;      Input a byte from port

cmd_I:
	ld (cmd_rpt),hl
	ld hl,(last_I)
	call get_lastarg_def
	ld (last_I),hl
	ld b,h
	ld c,l
	in a,(c)
	push af
	call out_hex
	call outbl4
	pop af
	call out.bin.b
	jp crlf

;-------------------------------------------------------------------------------
; >>O [byte] [port]
;      Output a byte to a port

cmd_O:
	ld (cmd_rpt),hl
	ld hl,(last_O_val)
	call get_arg_def
	ld a,l
	ld (last_O_val),a
	push af
	call next_arg
	ld hl,(last_O_addr)
	call get_lastarg_def
	ld (last_O_addr),hl
	ld b,h
	ld c,l
	pop af
	out (c),a
	ret

;-------------------------------------------------------------------------------
; > Vstartaddr endaddr targetaddr
;      Verify (compare) two memory areas

cmd_V:
	call sub_034eh
l0dedh:
	push bc
	ld a,(de)
	ld b,(hl)
	cp b
	jr z,l0e10h
	ld c,a
	call out_hl
	call outbl
	ld a,b
	call out_hex
	call outbl2
	ld a,c
	call out_hex
	call outbl
	ex de,hl
	call out_hl
	ex de,hl
	call crlf
l0e10h:
	pop bc
	inc de
	cpi
	jp pe,l0dedh
	ret

;-------------------------------------------------------------------------------
; > M startaddr endaddr destaddr
;      Move memory

cmd_M:
	call sub_034eh
	call cp_hl_de
	jr nc,cmdm_up
	add hl,bc
	ex de,hl
	add hl,bc
	ex de,hl
	dec hl
	dec de
	lddr
	db 01h		;swallow ldir instruction (ld bc,...)
cmdm_up:
	ldir
	ret

;-------------------------------------------------------------------------------
; > H
;      display Highest load address of last filed loaded, Maximum "High"
;      off all loaded files, and Top address of available memory
; > H expression
;      evaluate expression and display result in hex, decimal and other formats

cmd_H:
	call expr
	jp c,p_max_high0
	call assert_eol
	call out_hl
	call outbl2
	call out_hl_neg
	call outbl4
	call out.hl.dec
	call outbl2
	call out_hl_dec_neg
	call outbl4
	call out.bin.w
	call outbl2
	ld a,l
	call out.ascii
	jp crlf

;-------------------------------------------------------------------------------
; > Q[J] startaddr endaddr bytes
;      Query memory for a byte string [Justified]

cmd_Q:
	call get_arg_range
	push bc
	push hl
	call sub_0ee6h
	pop hl
l0e96h:
	push	hl
	push	de
	push bc
l0edah:
	ld a,(de)
	cp (hl)
	jr nz,l0ee2h
	inc de
	inc hl
	djnz l0edah
l0ee2h:
	pop bc
	pop de
	pop hl
	jr nz,l0eb0h
	push bc
	ld bc,16
	and a			;clear carry
	call sub_0f58h
	pop bc
l0eb0h:
	inc hl
	ex (sp),hl
	dec hl
	ld a,h
	or l
	ex (sp),hl
	jr nz,l0e96h
	pop bc
	ret

;-------------------------------------------------------------------------------
; > Z startaddr endaddr bytes
;      Zap (fill) memory with a byte string

cmd_Z:
	call get_arg_range
	push bc
	push hl
	call sub_0ee6h
	ld a,b
	pop hl
	pop bc
	push hl
	ex de,hl
l0ec7h:
	ldi
	jp po,l0ed3h
	dec a
	jr nz,l0ec7h
	pop hl
	ldir
	ret
l0ed3h:
	pop hl
	ret

sub_0ee6h:
	ld hl,conbuf+1
	call sub_0ef7h
	ld de,conbuf+1
	and a
	sbc hl,de
	ld b,l
	ret nz
	jp ERROR

sub_0ef7h:			;from cmd_Q, cmd_Z
	db	0e6h		;and 037h (clear carry)
sub_0ef8h:			;from cmd_S
	scf
l0ef9h:
	push af
	call next_arg
	cp ''''
	jr z,l0f1eh
	push hl
	call expr
	ld a,l
	pop hl
	jr c,l0f42h
	ld (hl),a
	inc hl
	jr l0f3ah
l0f1eh:
	inc de
	ld a,(de)
	cp ''''
	jr z,l0f2bh
	or a
	jr z,l0f42h
l0f27h:
	ld (hl),a
	inc hl
	jr l0f1eh
l0f2bh:
	inc de
	ld a,(de)
	cp ''''
	jr z,l0f27h
	cp '.'
	jr nz,l0f3ah
	inc de
	dec hl
	set 7,(hl)
	inc hl
l0f3ah:
	pop af
	jr nc,l0ef9h
	ld (last_S),hl
	jr l0ef9h
l0f42h:
	pop af
	ret nc
	ld (last_S),hl
	ret

;-------------------------------------------------------------------------------
; >>D [startaddr] [endaddr]
;      Display memory in hex and ASCII

cmd_D:
	ld (cmd_rpt),hl
	ld hl,(last_D)
	ld bc,128
	call sub_0377h
	scf
sub_0f58h:
	push bc
	push de
	push hl
	push af
l0f5ch:
	call out_hl
	call outbl2
	ld de,0
l0f68h:
	ld a,(hl)
	inc hl
	call out_hex
	call outbl
	dec bc
	inc e
	ld a,e
	cp 010h
	jr z,l0f80h
	and 003h
	call z,outbl
	ld a,b
	or c
	jr nz,l0f68h
l0f80h:
	call outbl
	and a
	sbc hl,de
l0f86h:
	ld a,(hl)
	call sub_0fa3h
	call outchar
	inc hl
	dec e
	jr nz,l0f86h
	pop af
	push af
	jr nc,l0f97h
	ld (last_D),hl
l0f97h:
	call crlf
	ld a,b
	or c
	jr nz,l0f5ch
	pop af
	pop hl
	pop de
	pop bc
	ret

sub_0fa3h:
	and 07fh
	cp 07fh
	jr z,l0fach
	cp ' '
	ret nc
l0fach:
	ld a,'.'
	ret

;-------------------------------------------------------------------------------
; > Fcommandline
;      specifiy filenames and command line

;cmd_F:

;-------------------------------------------------------------------------------
; > R [displacement]
;	Read Intel Hex File from console [add displacement]

cmd_R:
	ld hl,0
	call get_lastarg_def	;get offset from command line
	push hl
	ld hl,0
	ld (high_load),hl
w_recstart:
	call i.getchar
	jr z,rdhex_done
	cp ':'
	jr nz,w_recstart
	ld c,0			;init checksum
	call i.gethexbyte	;record len
	ld b,a
	call i.gethexbyte	;address high
	ld h,a
	call i.gethexbyte	;address low
	ld l,a
	call i.gethexbyte	;record type (ignored)
	ld a,b
	and a			;record len == 0?
	jr z,rdhex_done
l16c6h:
	call i.gethexbyte
	pop de			;offset
	push de
	push hl
	add hl,de
	call i.storebyte
	pop hl
	inc hl
	djnz l16c6h		;repeat for record len
	call i.gethexbyte	;checksum
	ld a,c
	and a
	jr nz,error2		;exit if checksum error
	jr w_recstart		;next record

rdhex_done:
	pop hl
	call i.gethexbyte
	jp p_max_high

i.gethexbyte:
	call sub_16f6h
	rlca
	rlca
	rlca
	rlca
	ld d,a
	call sub_16f6h
	add a,d
	ld d,a
	add a,c
	ld c,a
	ld a,d
	ret

sub_16f6h:
	call i.getchar
	jr z,error2
	call hex_digit
	ret nc
error2:
	jp ERROR

i.getchar:
	call incharw
	cp 01ah
	ret

i.storebyte:
	push af
	push de
	ld de,TPA		;lowest allowed load address
	call cp_hl_de
	jr c,error2
	ld de,(BDOS+1)		;highest allowed load address
	call cp_hl_de
	jr nc,error2
	ld de,(high_load)
	call cp_hl_de
	jr c,l1157h
	ld (high_load),hl
l1157h:
	ld de,(max_load)
	call cp_hl_de
	jr c,l1163h
	ld (max_load),hl
l1163h:
	pop de
	pop af
	ld (hl),a		;store byte
	ret

;-------------------------------------------------------------------------------

p_max_high0:
	call assert_eol
p_max_high:
	call pstr_inl
	DC	'High = '
	ld hl,(high_load)
	call out_hl
	call pstr_inl
	DC	'  Max = '
	ld hl,(max_load)
	call out_hl
	call pstr_inl
	DC	'  Top = '
	ld hl,ddtz_base-1
	call out_hl
	jp crlf

;-------------------------------------------------------------------------------
; > Wstartaddr endaddr
;      Write a file to disk

;cmd_W:

;-------------------------------------------------------------------------------
; > A [startaddr]
;      Assemble Zilog Z180 mnemonics

;cmd_A:

;-------------------------------------------------------------------------------
; >>L [startaddr] [endaddr]
;      List disassembled code

cmd_L:
	ld (cmd_rpt),hl
	call expr
	jr nc,l18dbh
	ld hl,(last_L)
l18dbh:
	call next_arg
	call get_range
	jr nc,l1905h
	call assert_eol
	ld b,16
l18ebh:
	push bc
	call	cmdl_p_line
	pop bc
	djnz l18ebh
	ret

l1905h:
	call assert_eol
	ld	d,h
	ld	e,l
	add	hl,bc
	ex	de,hl
l190fh:
	push	de
	call	cmdl_p_line
	pop 	de
	call	cp_hl_de
	jr	c,l190fh
	ret

;-------------------------------------------------------------------------------

cmdl_p_line:
	push	hl
	call out_hl
	call outbl2
	sub a
	ld (con_col),a
	push	hl
	pop	iy
	call p_disas_instr
	call	crlf
	pop	hl
	ld	c,b
	ld	b,0
	add	hl,bc
	ld	(last_L),hl
	ret

;-------------------------------------------------------------------------------

p_disas_instr:
	call disas_get_instrlen
	jr nc,l197fh
	push	bc
	ld	a,(con_col)
	add	a,5
	ld	c,a
	call	pstr					;print mnemonic
	call	p_goto_col
	ex de,hl
	call CALL_HL					;print arguments
	pop bc
	scf
	ret

l197fh:
	call pstr_inl
	DC	'???'
	ld b,1
	sub a
	ret

disas_get_instrlen:
	sub a
	ld (isprefix_ixiy),a
	ld a,(iy+000h)
	cp 0edh
	jr z,disas_pfx.ED
	cp 0ddh
	jr z,l19abh
	cp 0fdh
	jr z,l19afh
sub_19a0h:
	ld a,(iy+000h)
	cp 0cbh
	jr z,disas_pfx.CB
	jr disas_nopfx
l19abh:
	ld a,1
	jr l19b1h
l19afh:
	ld a,2
l19b1h:
	ld (isprefix_ixiy),a
	call disas_pfx.DDFD
	ret nc
	push bc
	call sub_19a0h
	pop af
	add a,b
	ld b,a
	scf
	ret

;-------------------------------------------------------------------------------

disas_nopfx:
	ld hl,b_1b54_start		;2 byte opcodes
	call lookup_op_arg
	ld b,2
	ret c
	ld hl,b_1ab6_start		;1 byte opcodes (no parameters)
	call lookup_op
	ld b,1
	ret c
	ld hl,b_1ad1_start		;1 byte opcodes
	call lookup_op_arg
	ld b,1
	ret c
	ld hl,b_1b9b_start		;3 byte opcodes
	call lookup_op_arg
	ld b,3
	ret

;-------------------------------------------------------------------------------

disas_pfx.ED:
	inc iy
	ld hl,b_1bc9_start		;1 byte opcode, no arguments
	call lookup_op
	ld b,2
	ret c
	ld hl,b_1bf4_start
	call lookup_op_arg
	ld b,2
	ret c

	ld hl,l228bh
	call lookup_op_arg
	ld b,3
	ret c
	ld hl,b_1c40_start
	call lookup_op_arg
	ld b,4
	ret

;-------------------------------------------------------------------------------

disas_pfx.CB:
	push iy
	inc iy
	ld a,(isprefix_ixiy)
	and a
	jr z,l1a42h
	inc iy
l1a42h:
	ld hl,b_1c55_start
	call lookup_op_arg
	pop iy
	ld b,2
	ret

;-------------------------------------------------------------------------------

disas_pfx.DDFD:
	inc iy
	ld hl,b_19ef_start
	call test_DDFD
	ld b,002h
	ret c
	ld hl,l1a0ah
	call test_DDFD
	ld b,001h
	ret c
	ld a,(iy+000h)
	cp 0cbh
	jr nz,l19edh
	ld a,(iy+002h)
	cp 036h
	ret z
	and 007h
	cp 006h
	jr nz,l19edh
	ld b,002h
	scf
	ret
l19edh:
	and a
	ret

;-------------------------------------------------------------------------------
; DD/FD 3 byte (ix+d)/(iy+d)
b_19ef_start:
	db	034h
	db	035h
	db	036h
	db	046h
	db	04eh
	db	056h
	db	05eh
	db	066h
	db	06eh
	db	070h
	db	071h
	db	072h
	db	073h
	db	074h
	db	075h
	db	077h
	db	07eh
	db	086h
	db	08eh
	db	096h
	db	09eh
	db	0a6h
	db	0aeh
	db	0b6h
	db	0beh
	db	0

; DD/FD 2 byte
l1a0ah:
	db	009h
	db	019h
	db	021h
	db	022h
	db	023h
	db	029h
	db	02ah
	db	02bh
	db	039h
	db	0e1h
	db	0e3h
	db	0e5h
	db	0e9h
	db	0f9h
	db	0

;-------------------------------------------------------------------------------

lookup_op:
	ld a,(hl)
	cp 0ffh
	ret z
	cp (iy+000h)
	jr z,l1a7fh
	inc hl
	inc hl
	jr lookup_op
l1a7fh:
	ld de,p_arg_none
	inc hl
	ld c,(hl)
	jr get_mnemonic


test_DDFD:
	ld a,(hl)
	and a
	ret z
	inc hl
	cp (iy+000h)
	jr nz,test_DDFD
	scf
	ret

lookup_op_arg:
	ld a,(iy+000h)
	and (hl)
	inc hl
	cp (hl)
	jr z,l1aa8h
	inc hl
	inc hl
	inc hl
	inc hl
	ld a,(hl)
	and a
	jr nz,lookup_op_arg
	ret

l1aa8h:
	inc hl
	ld c,(hl)
	inc c
	ret z
	dec c
	inc hl
	ld e,(hl)
	inc hl
	ld d,(hl)
get_mnemonic:
	ld hl,t_MNEMONICS
	ld b,0
	add hl,bc
	scf
	ret

;-------------------------------------------------------------------------------
; 1 byte opcodes (no parameters)
; Format: db opcode, t_MNEMONICS-index
b_1ab6_start:
	db 076h,o_HALT		;halt
	db 0d9h,o_EXX		;exx
	db 0f3h,o_DI		;di
	db 0fbh,o_EI		;ei
	db 000h,o_NOP		;nop
	db 007h,o_RLCA		;rlca
	db 00fh,o_RRCA		;rrca
	db 017h,o_RLA		;rla
	db 01fh,o_RRA		;rra
	db 027h,o_DAA		;daa
	db 02fh,o_CPL		;cpl
	db 037h,o_SCF		;scf
	db 03fh,o_CCF		;ccf
	db 0c9h,o_RET		;ret
	db 0ffh


; 1 byte opcodes
; Format: db mask, match, t_MNEMONICS-index
;	  dw argument formating function
b_1ad1_start:
	db 0c0h,040h,o_LD	;ld r[y],r[z]
	dw p_arg_ry_rz
	db 0f8h,080h,o_ADD	;add a,r[z]
	dw p_arg_a_r
	db 0f8h,088h,o_ADC	;adc a,r[z]
	dw p_arg_a_r
	db 0f8h,090h,o_SUB	;sub r[z]
	dw p_rz
	db 0f8h,098h,o_SBC	;sbc a,r[z]
	dw p_arg_a_r
	db 0f8h,0a0h,o_AND	;and r[z]
	dw p_rz
	db 0f8h,0a8h,o_XOR	;xor r[z]
	dw p_rz
	db 0f8h,0b0h,o_OR	;or r[z]
	dw p_rz
	db 0f8h,0b8h,o_CP	;cp r[z]
	dw p_rz
	db 0c7h,0c0h,o_RET	;ret cc
	dw p_cc
	db 0c7h,0c7h,o_RST	;rst
	dw p_arg_rst
	db 0cfh,0c1h,o_POP	;pop rr
	dw p_rp2
	db 0cfh,0c5h,o_PUSH	;push rr
	dw p_rp2
	db 0ffh,0e3h,o_EX	;ex (sp),hl
	dw l1ca0h
	db 0ffh,0e9h,o_JP	;jp (hl)
	dw l1caeh
	db 0ffh,0ebh,o_EX	;ex de,hl
	dw p_arg_ex_dehl
	db 0ffh,0f9h,o_LD	;ld sp,hl
	dw l1cc1h
	db 0cfh,003h,o_INC	;inc rr
	dw p_rp
	db 0cfh,00bh,o_DEC	;dec rr
	dw p_rp
	db 0c7h,004h,o_INC	;inc r
	dw p_ry
	db 0c7h,005h,o_DEC	;dec r
	dw p_ry
	db 0ffh,008h,o_EX	;ex af,af'
	dw p_arg_ex_afaf
	db 0cfh,009h,o_ADD	;add hl,rr
	dw l1cd3h
	db 0efh,002h,o_LD	;ld (rr),a ;rr=bc,de
	dw l1cdch
	db 0efh,00ah,o_LD	;ld a,(rr) ;rr=bc,de
	dw l1ce5h
	db 0

; 2 byte opdodes
b_1b54_start:
	db 0c7h,006h,o_LD	;ld r,nn
	dw l1cfah
	db 0ffh,0c6h,o_ADD	;add a,nn
	dw l1cf5h
	db 0ffh,0ceh,o_ADC	;adc a,nn
	dw l1cf5h
	db 0ffh,0d6h,o_SUB	;sub nn
	dw l1d09h
	db 0ffh,0deh,o_SBC	;sbc a,nn
	dw l1cf5h
	db 0ffh,0e6h,o_AND	;and nn
	dw l1d09h
	db 0ffh,0eeh,o_XOR	;xor nn
	dw l1d09h
	db 0ffh,0f6h,o_OR	;or nn
	dw l1d09h
	db 0ffh,0feh,o_CP	;cp nn
	dw l1d09h
	db 0ffh,010h,o_DJNZ	;djnz
	dw p_arg_jrel
	db 0ffh,018h,o_JR	;jr
	dw p_arg_jrel
	db 0e7h,020h,o_JR	;jr cc,
	dw p_arg_cc_jrel
	db 0ffh,0d3h,o_OUT	;out (nn),a
	dw l1d37h
	db 0ffh,0dbh,o_IN	;in a,(nn)
	dw l1d29h
	db 0

; 3 byte opcodes
b_1b9b_start:
	db 0c7h,0c2h,o_JP	;jp cc,mn
	dw p_arg_cc_mn
	db 0c7h,0c4h,o_CALL	;call cc,mn
	dw p_arg_cc_mn
	db 0cfh,001h,o_LD	;ld ww,mn
	dw p_arg_ww_mn
	db 0ffh,0c3h,o_JP	;jp mn
	dw p_arg_mn
	db 0ffh,0cdh,o_CALL	;call mn
	dw p_arg_mn
	db 0ffh,022h,o_LD	;ld (mn),hl
	dw p_arg_addr_hl
	db 0ffh,02ah,o_LD	;ld hl,(mn)
	dw p_arg_hl_addr
	db 0ffh,032h,o_LD	;ld (mn),a
	dw p_arg_addr_a
	db 0ffh,03ah,o_LD	;ld a,(mn)
	dw p_arg_a_addr
	db 0

; Prefix ED + 1 byte opcode, no arguments
; Format: opcode, t_MNEMONICS index
b_1bc9_start:
	db 044h,o_NEG		;neg
	db 045h,o_RETN		;retn
	db 04dh,o_RETI		;reti
	db 067h,o_RRD		;rrd
	db 06fh,o_RLD		;rld
	db 0a0h,o_LDI		;ldi
	db 0a1h,o_CPI		;cpi
	db 0a2h,o_INI		;ini
	db 0a3h,o_OUTI		;outi
	db 0a8h,o_LDD		;ldd
	db 0a9h,o_CPD		;cpd
	db 0aah,o_IND		;ind
	db 0abh,o_OUTD		;outd
	db 0b0h,o_LDIR		;ldir
	db 0b1h,o_CPIR		;cpir
	db 0b2h,o_INIR		;inir
	db 0b3h,o_OTIR		;otir
	db 0b8h,o_LDDR		;lddr
	db 0b9h,o_CPDR		;cpdr
	db 0bah,o_INDR		;indr
	db 0bbh,o_OTDR		;otdr
	db 08bh,o_OTDM		;otdm
	db 09bh,o_OTDMR		;otdmr
	db 083h,o_OTIM		;otim
	db 093h,o_OTIMR		;otimr
	db 076h,o_SLP		;slp
	db 0ffh			;<end mark>

b_1bf4_start:
	db 0ffh,070h,0ffh	;in (c)    ;
	dw p_arg_in_c	   	;
	db 0c7h,040h,o_IN	;in r,(c)  ;r=b,c,d,e,h,l,a
	dw p_arg_in_c	   	;
	db 0ffh,071h,0ffh	;out (c),0 ;
	dw p_arg_out_c	   	;
	db 0c7h,041h,o_OUT	;out (c),r ;r=b,c,d,e,h,l,a
	dw p_arg_out_c	   	;
	db 0cfh,042h,o_SBC	;sbc hl,rr
	dw l1dcah	   	;
	db 0cfh,04ah,o_ADC	;adc hl,rr
	dw l1dcah	   	;
	db 0ffh,046h,o_IM	;im 0
	dw l1d85h	   	;
	db 0ffh,056h,o_IM	;im 1
	dw l1d89h	   	;
	db 0ffh,05eh,o_IM	;im 2
	dw l1d8dh	   	;
	db 0e7h,047h,o_LD	;ld i,a ... ld a,r
	dw p_arg_IR	   	;
	db 0cfh,04ch,o_MLT	;mlt rr
	dw p_rp
	db 0c7h,004h,o_TST	;tst r
	dw p_ry
	db 0

l228bh:
	db 0ffh,030h,0ffh	;in0 (m)
	dw p_arg_r_m
	db 0c7h,000h,o_IN0	;in0 r,(m) ;r=b,c,d,e,h,l,a
	dw p_arg_r_m
	db 0ffh,031h,0ffh	;out0 (m),0
	dw p_arg_m_r
	db 0c7h,001h,o_OUT0	;out0 (m),r ;r=b,c,d,e
	dw p_arg_m_r
	db 0ffh,064h,o_TST	;tst m
	dw l1d09h
	db 0ffh,074h,o_TSTIO	;tstio m
	dw l1d09h
	db 0

; Prefix ED + 1 byte opcode + 2 byte address
; Format: db mask, match, t_MNEMONICS-index
;	  dw argument formating function
b_1c40_start:
	db 0cfh,043h,o_LD	;ld (mn),ww	;ww=bc,de,hl,sp
	dw p_arg_addr_ww
	db 0cfh,04bh,o_LD	;ld ww,(mn)	;ww=bc,de,hl,sp
	dw p_arg_ww_addr
	db 0

; CB
b_1c55_start:
	db 0f8h,000h,o_RLC	;rlc g
	dw p_rz_cb
	db 0f8h,008h,o_RRC	;rrc g
	dw p_rz_cb
	db 0f8h,010h,o_RL	;rl g
	dw p_rz_cb
	db 0f8h,018h,o_RR	;rr g
	dw p_rz_cb
	db 0f8h,020h,o_SLA	;sla g
	dw p_rz_cb
	db 0f8h,028h,o_SRA	;sra g
	dw p_rz_cb
	db 0f8h,038h,o_SRL	;srl g
	dw p_rz_cb
	db 0c0h,040h,o_BIT	;bit b,g
	dw p_arg_bitop
	db 0c0h,080h,o_RES	;res b,g
	dw p_arg_bitop
	db 0c0h,0c0h,o_SET	;set b,g
	dw p_arg_bitop
	db 0

;-------------------------------------------------------------------------------

p_arg_ry_rz:
	call p_ry
	call p_char_comma
	jp p_rz
p_arg_a_r:
	call p_A_comma
	jp p_rz

p_arg_r_m:
	call p_ry
	call p_char_comma
	jp sub_1d2ch

p_arg_m_r:
	call sub_1d2ch
	call p_char_comma
	jp p_ry

p_arg_rst:
	ld a,(iy+000h)
	and 038h
	jp out_hex

l1ca0h:
	call pstr_inl
	DC	'(SP),'
	jp p_arg_hlixiy

l1caeh:
	call p_char_lparen
	call p_arg_hlixiy
	jr out_rparen

p_arg_ex_dehl:
	call pstr_inl
	DC	'DE,HL'
p_arg_none:
	ret

l1cc1h:
	call pstr_inl
	DC	'SP,'
	jp p_arg_hlixiy

p_arg_ex_afaf:
	call pstr_inl
	DC	'AF,AF'''
	ret

l1cd3h:
	call p_arg_hlixiy
	call p_char_comma
	jp p_rp
l1cdch:
	call sub_1ce8h
	call p_char_comma
	jp p_char_A

l1ce5h:
	call p_A_comma
sub_1ce8h:
	call p_char_lparen
	call p_rp
	jr out_rparen

l1cf5h:
	call p_A_comma
	jr l1d09h
l1cfah:
	call p_ry
	call p_char_comma
	ld a,(isprefix_ixiy)
	and a
	ld a,(iy+002h)
	jr nz,l1d0ch
l1d09h:
	ld a,(iy+001h)
l1d0ch:
	jp out_hex

p_arg_cc_jrel:
	ld a,(iy+000h)
	and 018h
	call p_arg_cc0
	call p_char_comma
p_arg_jrel:
	ld c,(iy+001h)
	ld a,c
	rla
	sbc a,a
	ld b,a
	push iy
	pop hl
	add hl,bc
	inc hl
	inc hl
	jr l1d4eh

l1d29h:
	call p_A_comma
sub_1d2ch:
	call p_char_lparen
	ld a,(iy+001h)
p_arg_nn_rp:
	call out_hex
out_rparen:
	jr p_char_rparen

l1d37h:
	call sub_1d2ch
	jr p_char_comma_A

p_arg_cc_mn:
	call p_arg_cc
	call p_char_comma
p_arg_mn:
	ld l,(iy+001h)
	ld h,(iy+002h)
l1d4eh:
	jp out_hl

p_arg_ww_mn:
	call p_rp
	call p_char_comma
	jr p_arg_mn

p_arg_addr_hl:
	call p_arg_addr
	call p_char_comma
	jp p_arg_hlixiy

p_arg_hl_addr:
	call p_arg_hlixiy
	call p_char_comma
	jp p_arg_addr

p_arg_addr_a:
	call p_arg_addr
p_char_comma_A:
	call p_char_comma
	jr p_char_A

p_A_comma:
	call p_char_A
p_char_comma:
	ld a,','
	db 021h
p_char_A:
	ld a,'A'
	db 021h
l1d85h:
	ld a,'0'
	db 021h
l1d89h:
	ld a,'1'
	db 021h
l1d8dh:
	ld a,'2'
	db 021h
p_char_rparen:
	ld a,')'
	db 021h
p_char_lparen:
	ld a,'('
	jp outchar

p_arg_IR:
	ld a,(iy+000h)
	rra
	rra
	rra
	and 03
	ld hl,t_arg_IR
	jp p_arg

t_arg_IR:
	DC	'I,A'
	DC	'R,A'
	DC	'A,I'
	DC	'A,R'
	db	0

p_arg_in_c:
	call p_ry
	call p_char_comma
	ld hl,t__C_
	jp pstr

p_arg_out_c:
	ld hl,t__C_
	call pstr
	call p_char_comma
	jr p_ry

l1dcah:
	call p_arg_hlixiy
	call p_char_comma
	jp p_rp

p_arg_addr_ww:
	call p_arg_addr
	call p_char_comma
	jp p_rp

p_arg_ww_addr:
	call p_rp
	call p_char_comma
	jr p_arg_addr

p_arg_a_addr:
	call p_A_comma
p_arg_addr:
	call p_char_lparen
	call p_arg_mn
	jr p_char_rparen

p_arg_bitop:
	ld a,(isprefix_ixiy)
	and a
	jr nz,l1defh
	ld a,(iy+001h)
	jr l1df2h
l1defh:
	ld a,(iy+002h)
l1df2h:
	push af
	rra
	rra
	rra
	and 007h
	add a,'0'
	call outchar
	call p_char_comma
	pop af
	jr p_r0

p_rz_cb:
	ld a,(isprefix_ixiy)
	and a
	jr nz,l1e0eh
	ld a,(iy+001h)
	jr l1e11h
l1e0eh:
	ld a,(iy+002h)
l1e11h:
	jr p_r0

p_ry:
	ld a,(iy+000h)
	rra
	rra
	rra
	jr p_r0
p_rz:
	ld a,(iy+000h)
p_r0:
	and 007h
	cp 006h
	ld b,a
	ld hl,t_arg_r
	jr nz,p_arg0
	ld a,(isprefix_ixiy)
	and a
	jr z,p_arg0
	ld hl,t_lp_IXIY
	dec a
	call p_arg
	ld a,(iy+001h)
	push af
	rlca
	ld a,'+'
	jr nc,l1e61h
	pop af
	neg
	push af
	ld a,'-'
l1e61h:
	call outchar
	pop af
	jp p_arg_nn_rp

t_lp_IXIY:
	DC	'(IX'
	DC	'(IY'

p_arg_hlixiy:
	ld a,(isprefix_ixiy)
	ld hl,t_HL.IX.IY
	jr p_arg

p_rp2:
p_arg_zz:
	ld hl,t_arg_rp2
	jr l1e8eh
p_rp:
p_arg_ww:
	ld hl,t_arg_rp
l1e8eh:
	ld a,(iy+000h)
	rra
	rra
	rra
	rra
	and 003h
	cp 002h
	jr z,p_arg_hlixiy
	jr p_arg

p_cc:
p_arg_cc:
	ld a,(iy+000h)
p_arg_cc0:
	rra
	rra
	rra
	and 007h
	ld hl,t_arg_cc
p_arg:
	ld b,a
p_arg0:
	jp pstr_sel

;-------------------------------------------------------------------------------

if 0
p_bli:
	ld a,(iy+000h)
	rra
	and 00ch
	ld b,a
	ld a,(iy+000h)
	and 003h
	or b
	ld hl,t_mn_bli
	jr p_arg
endif

;-------------------------------------------------------------------------------

opc	macro	x

i_&x	equ	opc_index
o_&x	equ	$-opc_tabstart
	dc	'&x'
opc_index	defl	opc_index+1
	endm

opc1	macro	x,y

i_&x&y	equ	opc_index
o_&x&y	equ	$-opc_tabstart
	db	'&x'
i_&y	equ	opc_index+1
o_&y	equ	$-opc_tabstart
	dc	'&y'
opc_index	defl	opc_index+2
	endm


t_MNEMONICS:
opc_tabstart	defl	$
opc_index	defl	0
; 1-byte other
	opc NOP
	opc1 R,LD
	opc INC
	opc DEC
	opc DJNZ
	opc JR
	opc HALT

	opc RLCA
	opc RRCA
	opc RLA
	opc RRA
	opc DAA
	opc CPL
	opc SCF
	opc CCF

; 1-byte "alu"
	opc ADD
	opc ADC
	opc SUB
	opc SBC
	opc AND
;	opc XOR
	opc1 X,OR
	opc CP

	opc RET
	opc POP
	opc JP
	opc CALL
	opc PUSH
	opc RST
	opc OUT
	opc EXX
	opc IN
	opc EX
	opc1 L,DI
	opc EI
; CB
	opc RLC
	opc RRC
	opc1 S,RL
	opc RR
	opc SLA
	opc SRA
;	    SLL
;	opc SRL
	opc BIT
	opc RES
	opc SET

; ED
	opc NEG
	opc RETN
	opc RETI
	opc1 OT,IM
	opc RRD
;	opc RLD

;Block instructions
t_mn_bli:
;	opc LDI
	opc CPI
	opc INI
	opc OUTI
	opc LDD
	opc CPD
	opc IND
	opc OUTD
	opc LDIR
	opc CPIR
	opc INIR
	opc OTIR
	opc LDDR
	opc CPDR
	opc INDR
	opc OTDR

;Z180
	opc IN0
	opc OUT0
	opc TST
	opc MLT
	opc TSTIO
	opc SLP
;	opc OTIM
	opc OTDM
	opc OTIMR
	opc OTDMR

	DB	0

t_arg_r:
	DC	'B'
	DC	'C'
	DC	'D'
	DC	'E'
	DC	'H'
	DC	'L'
	DC	'(HL)'
	DC	'A'
	DB	0
t_arg_rp:
	DC	'BC'
	DC	'DE'
	DC	'HL'
	DC	'SP'
	DB	0
t_arg_rp2:
	DC	'BC'
	DC	'DE'
	DC	'HL'
	DC	'AF'
	DB	0
t_HL.IX.IY:
	DC	'HL'
	DC	'IX'
	DC	'IY'
	DB	0
t_arg_cc:
	DC	'NZ'
	DC	'Z'
	DC	'NC'
	DC	'C'
	DC	'PO'
	DC	'PE'
	DC	'P'
	DC	'M'
	DB	0
t__C_:
	DC	'(C)'
	DB	0

;-------------------------------------------------------------------------------
;-------------------------------------------------------------------------------
if 0

lookup_argstr:
	;todo
	ret


pr_instr_args:
	ld	hl,t_argf
	call	lookup_argstr

	ret	z

pria_l:
	ld	a,(hl)		;get next token
	inc	hl
	or	a
	ret	z		;
	jp	m,pria_1
	call	outchar		;print as normal character
	jr	pria_l

pria_1:				;
	push	hl
	ld	hl,do_arg_n
	and	07fh
	call	add_hl_a2
	ld	a,(hl)
	inc	hl
	ld	h,(hl)
	ld	l,a
	call	CALL_HL
	pop	hl
	jr	pria_l

;
;	http://www.z80.info/decoding.htm
;
;	| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
;	|   x   |     y     |     z     |
;	        |   p   | q |
;

t_argf:
	db	fi_ry,',',fi_rz,0	;ld r[y],r[z]
	db	'A,',fi_rz,0		;op A,r[z]
	db	fi_ry,',(',fi_m8,')',0	;in a,(m8)
	db	'(',fi_m8,'),',fi_ry,0	;out (m8),a
	db	fi_rst,0
	db	'(SP),',fi_hlixiy,0	;
	db	'DE,HL',0
	db	'AF,AF''',0
	db	fi_hlixiy,0
	db	fi_rp			;rp[p]
	db	fi_rp2			;rp2[p]

;-------------------------------------------------------------------------------

argpf_index	defl	0

argpf	macro	x
fi_&x	equ	80h+argpf_index
	dw	p_&x
argpf_index	defl	argpf_index+1
	endm

do_arg_n:
	argpf	ry
	argpf	rz
	argpf	m8
	argpf	rst
	argpf	hlixiy
	argpf	rp
	argpf	rp2

p_ry:
p_rz:
p_m8:
p_rst:
p_hlixiy:
p_rp:
p_rp2:


endif
;-------------------------------------------------------------------------------
;-------------------------------------------------------------------------------

tc_set_bp:
	ld hl,(reg.pc)
	ld a,h
	or l
	jr z,l2037h
	ld de,BDOS
	and a
	sbc hl,de
	ld hl,l20edh		;set break after BDOS call
	jr z,l2031h
	ld iy,(reg.pc)
	call disas_get_instrlen
	jp nc,ERROR
	ld c,b
	ld b,0
	ld hl,(reg.pc)
	add hl,bc
	call bp_trace_enter
	ld iy,(reg.pc)
	ld hl,t_op_branch
	call lookup_op_arg
	ccf
	ret c
	ex de,hl
l2031h:
	call CALL_HL
	call c,bp_trace_enter
l2037h:
	scf
	ret

;-------------------------------------------------------------------------------

t_op_branch:
	db 0ffh,0ddh,0		;Prefix DD
	dw l20a7h
	db 0ffh,0fdh,0		;Prefix FD
	dw l20ach
	db 0ffh,0edh,0		;Prefix ED
	dw l20b8h
t_op_branch0:
	db 0ffh,0cdh,0		;call mn
	dw l2080h
	db 0ffh,0c3h,0		;jp mn
	dw l208bh
	db 0ffh,0e9h,0		;jp ()
	dw l20a2h
	db 0ffh,0c9h,0		;ret
	dw l20dch
	db 0ffh,0cfh,0		;rst 8
	dw l2115h
	db 0c7h,0c7h,0		;rst n
	dw l20f9h
	db 0c7h,0c4h,0		;call cc,mn
	dw l2080h
	db 0f7h,010h,0		;djnz d; jr d
	dw l2093h
	db 0e7h,020h,0		;jr cc,d
	dw l2093h
	db 0c7h,0c2h,0		;jp cc,mn
	dw l208bh
	db 0c7h,0c0h,0		;ret cc
	dw l20c5h
	db 0

;-------------------------------------------------------------------------------
; call mn	call cc,mn
l2080h:

; jp mn		jp cc,mn
l208bh:
	ld l,(iy+001h)
	ld h,(iy+002h)
	scf
	ret

l2093h:
	ld c,(iy+001h)
	ld a,c
	rla
	sbc a,a
	ld b,a
	ld hl,(reg.pc)
	add hl,bc
	inc hl
	inc hl
	scf
	ret

; jp (hl)
l20a2h:
	ld hl,(reg.l)
	scf
	ret

; Prefix DD
l20a7h:
	ld hl,(reg.ix)
	jr l20afh
; Prefix FD
l20ach:
	ld hl,(reg.iy)
l20afh:
	ld a,(iy+001h)
	cp 0e9h			; jp (ix); jp (iy)
	scf
	ret z
	and a
	ret

; Prefix ED
l20b8h:
	ld a,(iy+001h)
	cp 04dh			; reti
	jr z,l20dch
	cp 045h			; retn
	jr z,l20dch
	and a
	ret
l20c5h:
	ld a,(iy+000h)
	ld (l20d7h),a
	ld hl,(reg.f)
	push hl
	pop af
	call l20d7h
	scf
	jr c,l20dch
	ret
l20d7h:
	nop
	and a
	pop hl
	inc hl
	jp (hl)

l20dch:
l20edh:
	ld hl,(reg_sp)		;break on return address
	ld e,(hl)
	inc hl
	ld d,(hl)
	ex de,hl
	call bp_trace_enter
l2115h:
	and a
	ret

l20f9h:
	ld a,(l0003h)
	cp (iy+000h)
	ret z
	ld a,(iy+000h)
	and 038h
	ld l,a
	ld h,000h
	ld a,(b_21e2_start)
	and a
	ret z
	scf
	ret

;-------------------------------------------------------------------------------
; >>C[N][J] [steps]
; >>C[N][J] W expression
; >>C[N][J] U expression
;     trace over Calls [No list] [Jumps only] /.While./.Until.


;-------------------------------------------------------------------------------
; >>T[N][J] [steps]
; >>T[N][J] W expression
; >>T[N][J] U expression
;      Trace [no List] [Jumps only] / .While. / .Until.

cmd_T:
	ld (cmd_rpt),hl
	ld hl,1				;default: 1 step
	call get_lastarg_def
	ld (trace_cnt_or_ptr),hl
	sub a
	ld (bp_p_cpu_flag),a
	call tc_set_bp
	jr user_go1

l2151h:
	call bp_clr_temporary
	ld hl,(trace_cnt_or_ptr)
	dec hl
	ld (trace_cnt_or_ptr),hl
	ld a,h
	or l
	jp z,do_break

	call tc_set_bp
	jp nc,do_break
	sbc a,a
	ld (bp_p_cpu_flag),a
user_go1:
	jp user_go

;-------------------------------------------------------------------------------

con_col:
	db	0

;-------------------------------------------------------------------------------

b_21e2_start:
	db	0
trace_cnt_or_ptr:
	dw	0

bp_p_cpu_flag:
	db	0

bp_tab:
	rept BP_CNT
	 rept BP_SIZE
	  db	0
	 endm
	endm

expr_buf:
current_cseg	defl	$ - current_cseg
	.phase	current_phase + current_cseg

start:
	LD	SP,ldr_end+(stack-ddtz_base)
	LD	DE,signon		;ldr_end+(expr_buf-ddtz_base)
	LD	C,BDOS_PSTR
	CALL	BDOS

	xor	a
	dec	a
	jp	po,reloc
	ld	de,msgz80
	LD	C,BDOS_PSTR
	CALL	BDOS
	jp	0

reloc:
	LD	HL,ldr_end+ddtz_size	;start of reloc bitmap
	ld	bc,0108h		;init bit counter

	EXX
	LD	HL,(BDOS+1)
	LD	(ldr_end+(ddtz_bdos+1-ddtz_base)),HL
	LD	BC,ddtz_size-1
	LD	D,B
	LD	E,0FFH
	INC	DE			;size rounded up to next page boundary
	INC	BC			;ddtz_size
	OR	A
	SBC	HL,DE			;BDOS - size
	LD	(BDOS+1),HL		;-> new BDOS entry

	push	hl
	PUSH	BC
	ld	de,ldr_end
	sbc	hl,de
	EX	DE,HL			;-> DE
	LD	HL,ldr_size
	add	hl,bc
	ld	b,h
	ld	c,l
	LD	HL,TPA
reloc_lp:
	EXX
	djnz	reloc_nl
	ld	b,c			;reload bit counter
	LD	e,(HL)			;get next 8 relocation bits
	INC	HL
reloc_nl:
	sla	e
	EXX
	JR	NC,reloc_next
	DEC	HL
	LD	A,(HL)
	ADD	A,E
	LD	(HL),A
	INC	HL
	LD	A,(HL)
	ADC	A,D
	LD	(HL),A
reloc_next:
	cpi
	jp	pe,reloc_lp
	dec	hl

	POP	BC
	pop	de
	EX	DE,HL
	ADD	HL,BC
	EX	DE,HL
	DEC	DE
	LDDR
	LD	HL,conbuf+2-ddtz_base
	ADD	HL,DE
	JP	(HL)

current_phase	defl	$
	.dephase
current_cseg	defl	$

	ds	EXPR_BUF_SIZE - ($ - expr_buf)
expr_bufe:

;-------------------------------------------------------------------------------

last_S:
	dw	TPA

last_I:
	dw	0

last_O_addr:
	dw	0
last_O_val:
	db	0

last_D:
	dw	TPA

high_load:
	dw	TPA
max_load:
	dw	TPA

isprefix_ixiy:
	db	0
last_L:
	dw	TPA

pbl_loop_adr:
	dw	0

ddtz_size	equ	$-ddtz_base
ddtz_end:

;-------------------------------------------------------------------------------

	end