summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/cpu/dsp56k/dsp56ops.c
blob: cb0fd76c13a189340fb04d8858afe2fea2417375 (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
/***************************************************************************

    dsp56ops.c
    Core implementation for the portable Motorola/Freescale DSP56k emulator.
    Written by Andrew Gardner

***************************************************************************/

// NOTES For register setting:
// FM.3-4 : When A2 or B2 is read, the register contents occupy the low-order portion
//          (bits 7-0) of the word; the high-order portion (bits 16-8) is sign-extended. When A2 or B2
//          is written, the register receives the low-order portion of the word; the high-order portion is not used
//        : ...much more!
//        : ...shifter/limiter/overflow notes too.
//
//

// Helper functions and macros
#define BITS(CUR,MASK) (Dsp56kOpMask(CUR,MASK))
static UINT16 Dsp56kOpMask(UINT16 op, UINT16 mask) ;

enum dataType { DT_BYTE, DT_WORD, DT_DOUBLE_WORD, DT_LONG_WORD } ;

// This function's areguments are written source->destination to fall in line with the processor's paradigm...
static void SetDestinationValue(void *sourcePointer, unsigned char sourceType,
								void *destinationPointer, unsigned char destinationType) ;

static void SetDataMemoryValue   (void *sourcePointer, unsigned char sourceType, UINT32 destinationAddr) ;
static void SetProgramMemoryValue(void *sourcePointer, unsigned char sourceType, UINT32 destinationAddr) ;


// Main opcode categories
static unsigned ExecuteDataALUOpcode(int parallelType) ;
static unsigned ExecuteDXMDROpcode(void) ;
static unsigned ExecuteNPMOpcode(void) ;
static unsigned ExecuteMisfitOpcode(void) ;
static unsigned ExecuteSpecialOpcode(void) ;


// Actual opcode implementations

// Data ALU Ops
static int ClrOperation(void **wd, UINT64 *pa) ;
static int AddOperation(void **wd, UINT64 *pa) ;
static int NotOperation(void **wd, UINT64 *pa) ;
static int LsrOperation(void **wd, UINT64 *pa) ;
static int AsrOperation(void **wd, UINT64 *pa) ;
static int TfrDataALUOperation(void **wd, UINT64 *pa) ;
static int EorOperation(void **wd, UINT64 *pa) ;
static int CmpOperation(void **wd, UINT64 *pa) ;
static int Dec24Operation(void **wd, UINT64 *pa) ;
static int AndOperation(void **wd, UINT64 *pa) ;
static int OrOperation(void **wd, UINT64 *pa) ;
static int TstOperation(void **wd, UINT64 *pa) ;

static int MoveCOperation(void) ;
static int MoveMOperation(void) ;
static int MoveIOperation(void) ;
static int MovePOperation(void) ;

static int AndiOperation(void) ;
//static int OriOperation(void) ;

static int BitfieldOperation(void) ;
static int JmpOperation(void) ;
static int BsrOperation(void) ;
static int JsrOperation(void) ;
static int DoOperation(void) ;
static int TccOperation(void) ;
static int BraOperation(void) ;
static int BsccOperation(void) ;
static int BccOperation(void) ;
static int Tst2Operation(void) ;
static int MACsuuuOperation(void) ;
static int RepOperation(void) ;

static void EndOfLoopProcessing(void) ;
static void EndOfRepProcessing(void) ;

// Parallel memory data moves
static void XMDMOperation(UINT16 parameters, void *working, UINT64 *pa) ;
static void XMDMSpecialOperation(UINT16 parameters, void *working) ;
static void ARUOperation(UINT16 parameters) ;
static void RRDMOperation(UINT16 parameters, void *working,  UINT64 *pa) ;

// For decoding the different types of tables...
static void *DecodeDDDDDTable(UINT16 DDDDD, unsigned char *dt) ;
static void *DecodeRRTable(UINT16 RR, unsigned char *dt) ;
static void *DecodeDDTable(UINT16 DD, unsigned char *dt) ;
static void *DecodeHHHTable(UINT16 HHH, unsigned char *dt) ;
static void *DecodeHHTable(UINT16 HH, unsigned char *dt) ;
static void *DecodeZTable(UINT16 Z, unsigned char *dt) ;
static UINT16 DecodeBBBBitMask(UINT16 BBB, UINT16 *iVal) ;
static int DecodeccccTable(UINT16 cccc) ;
static void Decodeh0hFTable(UINT16 h0h, UINT16 F, void **source, unsigned char *st, void **dest, unsigned char *dt) ;
static void *DecodeFTable(UINT16 F, unsigned char *dt) ;
static void DecodeJJJFTable(UINT16 JJJ, UINT16 F, void **source, unsigned char *st, void **dest, unsigned char *dt) ;
static void DecodeJJFTable(UINT16 JJ, UINT16 F, void **source, unsigned char *st, void **dest, unsigned char *dt) ;
static void DecodeQQFTableSp(UINT16 QQ, UINT16 F, void **S1, void **S2, void **D) ;
static void DecodeIIIITable(UINT16 IIII, void **source, unsigned char *st, void **dest, unsigned char *dt, void *working) ;

static void ExecuteMMTable(int x, UINT16 MM) ;
static void ExecutemTable(int x, UINT16 m) ;
static void ExecutezTable(int x, UINT16 z) ;
static UINT16 ExecuteqTable(int x, UINT16 q) ;

static UINT16 AssembleDFromPTable(UINT16 P, UINT16 ppppp) ;

static UINT16 AssembleAddressFromIOShortAddress(UINT16 pp) ;
static UINT16 AssembleAddressFrom6BitSignedRelativeShortAddress(UINT16 srs) ;


/***************************************************************************
    IMPLEMENTATION
***************************************************************************/

#ifdef UNUSED_FUNCTION
static void unimplemented(void)
{
	fatalerror("Unimplemented OP @ %04X: %04X", PC-2, OP) ;
}
#endif


static void execute_one(void)
{
	unsigned size = 666 ;

	debugger_instruction_hook(Machine, PC);
	OP = ROPCODE(PC<<1);

	if (BITS(OP,0x8000))											// First, the parallel data move instructions
	{
		size = ExecuteDataALUOpcode(PARALLEL_TYPE_XMDM) ;
	}
	else if (BITS(OP,0xf000) == 0x5)
	{
		size = ExecuteDataALUOpcode(PARALLEL_TYPE_XMDM_SPECIAL) ;
	}
	else if (BITS(OP,0xff00) == 0x4a)
	{
		size = ExecuteDataALUOpcode(PARALLEL_TYPE_NODM) ;
	}
	else if (BITS(OP,0xf000) == 0x04)
	{
		size = ExecuteDataALUOpcode(PARALLEL_TYPE_RRDM) ;
	}
	else if (BITS(OP,0xf800) == 0x06)
	{
		size = ExecuteDataALUOpcode(PARALLEL_TYPE_ARU) ;
	}


	else if (BITS(OP,0x4000))
	{
		size = ExecuteDXMDROpcode() ;
	}
	else if (BITS(OP,0xf000) == 0x1)
	{
		size = ExecuteNPMOpcode() ;
	}
	else if (BITS(OP,0x2000))
	{
		size = ExecuteMisfitOpcode() ;
	}
	else if (BITS(OP,0xf000) == 0x0)
	{
		size = ExecuteSpecialOpcode();
	}

	if (size == 666)
	{
		mame_printf_debug("unimplemented at %04x\n", PC) ;
		size = 1 ;						// Just to get the debugger past the bad opcode
	}


	PC += size ;
	change_pc(PC) ;

	// Loop processing
	if (LF_bit())
	{
		if (PC == LA)
		{
			// You're on the last instruction of the loop...
			if (LC != 1)								// Strange, the == 1 thing...
			{
				LC-- ;
				PC = SSH ;
				change_pc(PC) ;
			}
			else
			{
				EndOfLoopProcessing() ;
			}
		}
	}

	// Rep processing
	if (core.repFlag)
	{
		if (PC == core.repAddr)
		{
			if (LC != 1)
			{
				LC-- ;
				PC -= size ;								// Eh, seems reasonable :)
				change_pc(PC) ;
			}
			else
			{
				EndOfRepProcessing() ;
			}
		}
	}

	dsp56k_icount -= 4;					/* Temporarily hard-coded at 4 clocks per opcode */
}


static unsigned ExecuteDataALUOpcode(int parallelType)
{
	unsigned retSize = 666 ;

	void *workingDest = 0x00 ;

	// Whenever an instruction uses an accumulator as both a destination operand for a Data ALU operation and
	//   as a source for a parallel move operation, the parallel move operation will use the value in the accumulator
	//   prior to execution of any Data ALU operation.
	UINT64 previousAccum = 0 ;

	switch(BITS(OP,0x0070))
	{

		case 0x0:
			if (BITS(OP,0x0007) == 0x1)
			{
				// CLR - 1mRR HHHW 0000 F001
                retSize = ClrOperation(&workingDest, &previousAccum) ;
			}
			else
			{
				// ADD - 1mRR HHHW 0000 FJJJ
				retSize = AddOperation(&workingDest, &previousAccum) ;
			}
			break ;

		case 0x1:
			if (BITS(OP,0x000f) == 0x1)
			{
				// MOVE - 1mRR HHHW 0001 0001
				retSize = 1 ;
			}
			else
			{
				// TFR - 1mRR HHHW 0001 FJJJ
				retSize = TfrDataALUOperation(&workingDest, &previousAccum) ;
			}
			break ;

		case 0x2:
			if (BITS(OP,0x0007) == 0x0)
			{
				// RND - 1mRR HHHW 0010 F000
			}
			else if (BITS(OP,0x0007) == 0x1)
			{
				// TST - 1mRR HHHW 0010 F001
				retSize = TstOperation(&workingDest, &previousAccum);
			}
			else if (BITS(OP,0x0007) == 0x2)
			{
				// INC - 1mRR HHHW 0010 F010
			}
			else if (BITS(OP,0x0007) == 0x3)
			{
				// INC24 - 1mRR HHHW 0010 F011
			}
			else
			{
				// OR - 1mRR HHHW 0010 F1JJ
				retSize = OrOperation(&workingDest, &previousAccum) ;
			}
			break ;

		case 0x3:
			if (BITS(OP,0x0007) == 0x0)
			{
				// ASR - 1mRR HHHW 0011 F000
				retSize = AsrOperation(&workingDest, &previousAccum) ;
			}
			else if (BITS(OP,0x0007) == 0x1)
			{
				// ASL - 1mRR HHHW 0011 F001
			}
			else if (BITS(OP,0x0007) == 0x2)
			{
				// LSR - 1mRR HHHW 0011 F010
				retSize = LsrOperation(&workingDest, &previousAccum) ;
			}
			else if (BITS(OP,0x0007) == 0x3)
			{
				// LSL - 1mRR HHHW 0011 F011
			}
			else
			{
				// EOR - 1mRR HHHW 0011 F1JJ
				retSize = EorOperation(&workingDest, &previousAccum) ;
			}
			break ;
/*
        case 0x4:
            if (BITS(op,0x0007) == 0x1)
            {
                // SUBL - 1mRR HHHW 0100 F001
            }
            else
            {
                // SUB - 1mRR HHHW 0100 FJJJ
            }
            break ;
*/
		case 0x5:
			if (BITS(OP,0x0007) == 0x1)
			{
				// CLR24 - 1mRR HHHW 0101 F001
			}
			else if (BITS(OP,0x0006) == 0x1)
			{
				// SBC - 1mRR HHHW 0101 F01J
			}
			else
			{
				// CMP - 1mRR HHHW 0101 FJJJ
				retSize = CmpOperation(&workingDest, &previousAccum) ;
			}
			break ;

		case 0x6:
			if (BITS(OP,0x0007) == 0x0)
			{
				// NEG - 1mRR HHHW 0110 F000
			}
			else if (BITS(OP,0x0007) == 0x1)
			{
				// NOT - 1mRR HHHW 0110 F001
				retSize = NotOperation(&workingDest, &previousAccum) ;
			}
			else if (BITS(OP,0x0007) == 0x2)
			{
				// DEC - 1mRR HHHW 0110 F010
			}
			else if (BITS(OP,0x0007) == 0x3)
			{
				// DEC24 - 1mRR HHHW 0110 F011
				retSize = Dec24Operation(&workingDest, &previousAccum) ;
			}
			else
			{
				// AND - 1mRR HHHW 0110 F1JJ
				retSize = AndOperation(&workingDest, &previousAccum) ;
			}
			break ;
/*
        case 0x7:
            if (BITS(op,0x0007) == 0x1)
            {
                // ABS - 1mRR HHHW 0111 F001
            }
            if (BITS(op,0x0007) == 0x2)
            {
                // ROR - 1mRR HHHW 0111 F010
            }
            if (BITS(op,0x0007) == 0x3)
            {
                // ROL - 1mRR HHHW 0111 F011
            }
            else
            {
                // CMPM - 1mRR HHHW 0111 FJJJ
            }

            break ;
*/
	}

/*
    // Otherwise you're looking at a MPY/MAC operation...
    if (BITS(op,0x0080))                                                                    // Maybe i should un-consolidate here?
    {
        DecodeQQQFTable(BITS(op,0x0007), BITS(op,0x0008), S1, S2, D) ;
        DecodekSignTable(BITS(op,0x0040), sign) ;

        switch(BITS(op,0x00b0))
        {
            // MPY - 1mRR HHHH 1k00 FQQQ
            case 0x4: sprintf(buffer, "mpy       (%s)%s,%s,%s", sign, S2, S1, D)  ; break ;

            // MPYR - 1mRR HHHH 1k01 FQQQ
            case 0x5: sprintf(buffer, "mpyr      (%s)%s,%s,%s", sign, S2, S1, D) ; break ;

            // MAC - 1mRR HHHH 1k10 FQQQ
            case 0x6: sprintf(buffer, "mac       (%s)%s,%s,%s", sign, S2, S1, D)  ; break ;

            // MACR - 1mRR HHHH 1k11 FQQQ
            case 0x7: sprintf(buffer, "macr      (%s)%s,%s,%s", sign, S1, S2, D) ; break ;
            // !! It's a little odd that macr is S1,S2 while everyone else is S2,S1 !!
        }

        retSize = 1 ;
    }
*/

	// Do the parallel move parallel'y :)
    // Someday we may have to check against the special cases to throw exceptions !!
	switch (parallelType)
	{
		case PARALLEL_TYPE_XMDM:
			XMDMOperation(BITS(OP,0xff00), workingDest, &previousAccum) ;
			break ;

		case PARALLEL_TYPE_RRDM:
			RRDMOperation(BITS(OP,0xff00), workingDest, &previousAccum) ;
			break ;

		case PARALLEL_TYPE_XMDM_SPECIAL:
			// pa is not needed because the XMDM dest is always the .opposite. of the regular dest.
			XMDMSpecialOperation(BITS(OP,0xff00), workingDest) ;
			break ;

		case PARALLEL_TYPE_NODM:
			// do nothing
			break ;

		case PARALLEL_TYPE_ARU:
			ARUOperation(BITS(OP,0xff00)) ;
			break ;
	}

	return retSize ;
}

static unsigned ExecuteDXMDROpcode(void)
{
	unsigned retSize = 666 ;

	return retSize ;
}

static unsigned ExecuteNPMOpcode(void)
{
	unsigned retSize = 666 ;

	if (BITS(OP,0x0f00) == 0x4)
	{
		retSize = BitfieldOperation() ;
	}
	else if (BITS(OP,0x0f00) == 0x5)
	{
		switch(BITS(OP,0x0074))
		{
			case 0x0:
				if (BITS(OP,0x0006) == 0x0)
				{
					// TFR(2) - 0001 0101 0000 F00J
					retSize = 1 ;
				}
				else if (BITS(OP,0x0006) == 0x1)
				{
					// ADC - 0001 0101 0000 F01J
					retSize = 1 ;
				}
				break ;

			case 0x3:
					// TST(2) - 0001 0101 0001 -1DD
					retSize = Tst2Operation() ; break ;

			case 0x4:
					// NORM - 0001 0101 0010 F0RR
					retSize = 1 ; break ;

			case 0x6:
				if (BITS(OP,0x0003) == 0x0)
				{
					// ASR4 - 0001 0101 0011 F000
					retSize = 1 ;
				}
				else if (BITS(OP,0x0003) == 0x1)
				{
					// ASL4 - 0001 0101 0011 F001
					retSize = 1 ;
				}
				break ;

			case 0x1: case 0x5: case 0x9: case 0xd:
					// DIV - 0001 0101 0--0 F1DD
					retSize = 1 ; break ;

			case 0xa:
				if (BITS(OP,0x0003) == 0x0)
				{
					// ZERO - 0001 0101 0101 F000
					retSize = 1 ;
				}
				else if (BITS(OP,0x0003) == 0x2)
				{
					// EXT - 0001 0101 0101 F010
					retSize = 1 ;
				}
				break ;

			case 0xc:
				if (BITS(OP,0x0003) == 0x0)
				{
					// NEGC - 0001 0101 0110 F000
					retSize = 1 ;
				}
				break ;

			case 0xe:
				if (BITS(OP,0x0003) == 0x0)
				{
					// ASR16 - 0001 0101 0111 F000
					retSize = 1 ;
				}
				else if (BITS(OP,0x0003) == 0x1)
				{
					// SWAP - 0001 0101 0111 F001
					retSize = 1 ;
				}
				break ;
		}

		switch(BITS(OP,0x00f0))
		{
			case 0x8:
				// IMPY - 0001 0101 1000 FQQQ
				retSize = 1 ; break ;
			case 0xa:
				// IMAC - 0001 0101 1010 FQQQ
				retSize = 1 ; break ;
			case 0x9: case 0xb:
				// DMAC(ss,su,uu) - 0001 0101 10s1 FsQQ
				retSize = 1 ; break ;
			case 0xc:
				// MPY(su,uu) - 0001 0101 1100 FsQQ
				retSize = 1 ; break ;
			case 0xe:
				// MAC(su,uu) - 0001 0101 1110 FsQQ
				retSize = MACsuuuOperation() ; break ;
		}
	}
	else if ((BITS(OP,0x0f00) == 0x6))
	{
		retSize = 1 ;
	}
	else if ((BITS(OP,0x0f00) == 0x7))
	{
		retSize = 1 ;
	}
	else if ((BITS(OP,0x0800) == 0x1))
	{
		if (BITS(OP,0x0600))
		{
			if (!BITS(OP,0x0100))
			{
				// ANDI - 0001 1EE0 iiii iiii
				retSize = AndiOperation() ;
			}
			else
			{
				// ORI - 0001 1EE1 iiii iiii
			}
		}
		else
		{
			if (!BITS(OP,0x0020))
			{
				// MOVE(S) - 0001 100W HH0a aaaa
			}
			else
			{
				// MOVE(P) - 0001 100W HH1p pppp
				retSize = MovePOperation() ;
			}
		}
	}
	else if ((BITS(OP,0x0c00) == 0x0))
	{
		retSize = TccOperation() ;
	}

	return retSize ;
}

static unsigned ExecuteMisfitOpcode(void)
{
	unsigned retSize = 666 ;

	if (BITS(OP,0x1000)== 0x0)
	{
		switch(BITS(OP,0x0c00))
		{
			// MOVE(I) - 0010 00DD BBBB BBBB
			case 0x0:
				retSize = MoveIOperation() ;
				break ;

/*
            case 0x1:
                // TFR(3) - 0010 01mW RRDD FHHH
                break ;
*/
			case 0x2:
				// MOVE(C) - 0010 10dd dddD DDDD
				retSize = MoveCOperation() ;
				break ;

			case 0x3:
				// B.cc - 0010 11cc ccee eeee
				retSize = BccOperation() ;
				break ;
		}
	}
	else
	{
		// MOVE(C) - 0011 1WDD DDD0 MMRR
		// MOVE(C) - 0011 1WDD DDD1 q0RR
		// MOVE(C) - 0011 1WDD DDD1 t10- xxxx xxxx xxxx xxxx
		// MOVE(C) - 0011 1WDD DDD1 Z11-
		retSize = MoveCOperation() ;
	}

	return retSize ;
}

static unsigned ExecuteSpecialOpcode(void)
{
	unsigned retSize = 666 ;

	if (BITS(OP,0x0ff0) == 0x0)
	{
		switch (BITS(OP,0x000f))
		{
			// NOP - 0000 0000 0000 0000
			case 0x0:
				retSize = 1 ;
				break ;

			// DO FOREVER - 0000 0000 0000 0010 xxxx xxxx xxxx xxxx
			case 0x2:
				// !!! IMPLEMENT ME NEXT;
				retSize = 0;
				break;

			// RTS - 0000 0000 0000 0110
			case 0x6:
				PC = SSH ;
				SR = SSL ;
				SP-- ;
				retSize = 0 ;
				change_pc(PC) ;
				break ;

			// RTI - 0000 0000 0000 0111
			case 0x7:
				PC = SSH;
				SR = SSL;
				SP--;
				retSize = 0;
				change_pc(PC);
				break;
		}
	}
	else if (BITS(OP,0x0f00) == 0x0)
	{
		retSize = 1 ;
	}
	else if (BITS(OP,0x0f00) == 0x1)
	{
		if (BITS(OP,0x00f0) == 0x1)
		{
			retSize = 1 ;
		}
		else if (BITS(OP,0x00f0) == 0x2)
		{
			switch(BITS(OP,0x000c))								// Consolidation can happen here
			{
				// JSR - 0000 0001 0010 00RR
				// JMP - 0000 0001 0010 01RR
				case 0x1: retSize = JmpOperation(); break;
				// BSR - 0000 0001 0010 10RR
				// BRA - 0000 0001 0010 11RR
				default:  retSize = 1;
			}
		}
		else if (BITS(OP,0x00f0) == 0x3)
		{
			switch(BITS(OP,0x000c))
			{
				// JSR - 0000 0001 0011 00-- xxxx xxxx xxxx xxxx
				case 0x0: retSize = JsrOperation() ; break ;
				// JMP - 0000 0001 0011 01-- xxxx xxxx xxxx xxxx
				case 0x1: retSize = JmpOperation() ; break ;
				// BSR - 0000 0001 0011 10-- xxxx xxxx xxxx xxxx
				case 0x2: retSize = BsrOperation() ; break ;
			}
		}
		else if (BITS(OP,0x00f0) == 0x5)
		{
			retSize = 1 ;
		}
		else if (BITS(OP,0x0080) == 0x1)
		{
			retSize = 1 ;
		}
	}
	else if (BITS(OP,0x0e00) == 0x1)
	{
		if (BITS(OP,0x0020) == 0x0)
		{
			// MOVE(M) - 0000 001W RR0M MHHH
			retSize = MoveMOperation() ;
		}
	}
	else if (BITS(OP,0x0f00) == 0x4)
	{
		if (BITS(OP,0x0020) == 0x0)
		{
			// DO - 0000 0100 000D DDDD xxxx xxxx xxxx xxxx
			retSize = DoOperation() ;
		}
		else
		{
			// REP - 0000 0100 001D DDDD
			retSize = RepOperation() ;
		}
	}
	else if (BITS(OP,0x0f00) == 0x5)
	{
	    UINT16 op2 = ROPCODE((PC<<1)+2) ;

		if (BITS(op2,0xfe20) == 0x02)
		{
			// MOVE(M) - 0000 0101 BBBB BBBB | 0000 001W --0- -HHH
			retSize = MoveMOperation() ;
		}
		else if (BITS(op2,0xf810) == 0x0e)
		{
			// MOVE(C) - 0000 0101 BBBB BBBB | 0011 1WDD DDD0 ----
		}
		else if (BITS(op2,0x00ff) == 0x11)
		{
			// MOVE - 0000 0101 BBBB BBBB | ---- HHHW 0001 0001
		}
	}
	else if (BITS(OP,0x0f00) == 0x6)
	{
		retSize = 1 ;
	}
	else if (BITS(OP,0x0f00) == 0x7)
	{
		switch(BITS(OP,0x0030))
		{
			// BS.cc - 0000 0111 RR00 cccc
			case 0x0: retSize = 1 ; break ;

			// BS.cc - 0000 0111 --01 cccc xxxx xxxx xxxx xxxx
			case 0x1: retSize = BsccOperation() ; break ;

			// B.cc - 0000 0111 RR10 cccc
			case 0x2: retSize = 1 ; break ;

			// B.cc - 0000 0111 --11 cccc xxxx xxxx xxxx xxxx
			case 0x3: retSize = BccOperation() ; break ;
		}
	}
	else if (BITS(OP,0x0800))
	{
		switch (BITS(OP,0x0700))
		{
			// BRA - 0000 1011 aaaa aaaa
			case 0x3: retSize = BraOperation() ; break ;

			// MOVE(P) - 0000 110W RRmp pppp
			case 0x4: case 0x5: retSize = MovePOperation() ; break ;

			// DO - 0000 1110 iiii iiii xxxx xxxx xxxx xxxx
			case 0x6: retSize = DoOperation() ;  break ;

			// REP - 0000 1111 iiii iiii
			case 0x7: retSize = RepOperation() ; break ;
		}
	}

	return retSize ;
}

/*
IMPLEMENTATIONS
*/

static int BitfieldOperation(void)
{
	int retSize = 0 ;

	// BITFIELD OPERATIONS
	// ONLY PARTIALLY IMPLEMENTED !!!

	// Get the next part of the opcode...
	UINT16 op2 = ROPCODE((PC<<1)+2) ;

	unsigned char dt = 0x00 ;
	void *destinationReg = 0x00 ;
	void *rReg = 0x00 ;

	UINT16 destAddr = 0x00 ;

    UINT16 opVal ;

	// Get the universal immediate value and its proper mask...
	UINT16 iVal    = op2 & 0x00ff ;
	DecodeBBBBitMask(BITS(op2,0xe000), &iVal) ;

	// Figure out where data you'll be dealing with comes from...
	switch(BITS(OP,0x00e0))
	{
		case 0x6: case 0x7: case 0x2: case 0x3:
			destAddr = AssembleDFromPTable(BITS(OP,0x0020), BITS(OP,0x001f)) ;
			break ;

		case 0x5:             case 0x1:
			rReg = DecodeRRTable(BITS(OP,0x0003), &dt) ;
			destAddr = *((UINT16*)rReg) ;
			break ;

		case 0x4: case 0x0:
			destinationReg = DecodeDDDDDTable(BITS(OP,0x001f), &dt) ;
			break ;
	}

	// Grab the value to operate on...
	if (destinationReg)
	{
		if (dt == DT_LONG_WORD)
			opVal = (*((PAIR64*)destinationReg)).w.h ;
		else
			opVal = *((UINT16*)destinationReg) ;
	}
	else
		opVal = data_read_word_16le(destAddr<<1) ;

	// Do the necessary bitfield operation...
	switch(BITS(op2,0x1f00))
	{
		// bfchg
		case 0x12:
			if ((iVal & opVal) == iVal)   C_bit_set(1);		// test
			else					      C_bit_set(0) ;

			opVal ^= iVal ;									// and change
			break ;

		// bfclr
		case 0x04:
			opVal &= (~iVal) ;
			break ;

		// bfset
		case 0x18:
			opVal |= iVal ;
			break ;

		// bfsth
		case 0x10:
			mame_printf_debug("BFSTH - not here yet") ;
			break ;

		// bftstl
		case 0x00:
			if ((iVal & opVal) == 0)   C_bit_set(1);
			else				       C_bit_set(0);
			retSize = 2; return retSize;				/* It's just a test - no need to go on */
			break ;
	}

	// Put the data back where it belongs
	// !!! When setting A and B, I'm pretty sure if it's supposed to pass through the normal 'setDestValue' pipe but not entirely !!!
	//     (in other words, does clearing ff.ffff.ffff with 001c really result in ff.ffe3.0000 or ff.ffe3.ffff) ???
	if (destinationReg)
		SetDestinationValue(&opVal, DT_WORD, destinationReg, dt) ;
	else
		SetDataMemoryValue(&opVal, DT_WORD, destAddr<<1) ;

	retSize = 2 ;
	return retSize ;
}

static int MoveCOperation(void)
{
	int retSize = 0 ;

	unsigned char W = 0x00 ;

	unsigned char sdt = 0x00 ;
	void *SD ;

	// ONLY PARTIALLY IMPLEMENTED !!!

	SD = DecodeDDDDDTable(BITS(OP,0x03e0), &sdt) ;
	W  = BITS(OP,0x0400) ;

	if (BITS(OP,0x1000))
	{
		// Single source/destination move(c)
		if (!BITS(OP,0x0010))
		{
			// MM in move(c)

			// Get the r register...
			unsigned char rt = 0x00 ;
			void *R ;

			R = DecodeRRTable(BITS(OP,0x0003), &rt) ;

			if (W)
			{
				// !!! does this work ???
				UINT16 data = data_read_word_16le((*((UINT16*)R))<<1) ;
				SetDestinationValue(&data, DT_WORD, SD, sdt) ;
			}
			else
			{
				SetDataMemoryValue(SD, sdt, (*((UINT16*)R))<<1) ;
			}

			ExecuteMMTable(BITS(OP,0x0003), BITS(OP,0x000c)) ;
			retSize = 1 ;
		}
		else
		{
			if (!BITS(OP,0x0004))
			{
				// q in move(c)

				// Figure out the true addr...
				UINT16 addr = ExecuteqTable(BITS(OP,0x0003), BITS(OP,0x0008));

				if (W)
				{
					// !!! does this work ???
					UINT16 data = data_read_word_16le(addr<<1) ;
					SetDestinationValue(&data, DT_WORD, SD, sdt) ;
				}
				else
				{
					SetDataMemoryValue(SD, sdt, addr<<1);
				}

				retSize = 1 ;
			}
			else
			{
				if (BITS(OP,0x0002))
				{
					// Z in move(c)
					unsigned char rt = 0x00;
					void *Z;

					Z = DecodeZTable(BITS(OP,0x0008), &rt);

					if (W)
					{
						// Unimplemented
						retSize = 666 ;
					}
					else
					{
						SetDataMemoryValue(SD, sdt, (*((UINT16*)Z))<<1);
						retSize = 1;
					}
				}
				else
				{
					// 2-word move(c)
				    UINT16 nextWord = ROPCODE((PC<<1)+2) ;

					if (BITS(OP,0x0008))
					{
						// #xxxx - value read directly out of the opcode
						SetDestinationValue(&nextWord, DT_WORD, SD, sdt) ;
					}
					else
					{
						// X:xxxx = value resides in X memory...
						if (W)
						{
							// Read from X-data memory...
							// !!! Does this work ???
							UINT16 data = data_read_word_16le(nextWord<<1) ;
							SetDestinationValue(&data, DT_WORD, SD, sdt) ;
						}
						else
						{
							// Write to X-data memory...
							SetDataMemoryValue(SD, sdt, nextWord<<1) ;
						}
					}

					retSize = 2 ;
				}
			}
		}
	}
	else if (BITS(OP,0x2000))
	{
		// Source and Destination explicit
		unsigned char dt = 0x00 ;
		void *D ;

		D = DecodeDDDDDTable(BITS(OP,0x001f), &dt) ;
		SetDestinationValue(SD, sdt, D, dt) ;

		retSize = 1 ;
	}
	else
	{
		// Double source/destination move(c)

		retSize = 666 ;
	}

	return retSize ;
}

static int MoveMOperation(void)
{
	int retSize = 0 ;

	// ONLY PARTIALLY IMPLEMENTED !!!

	if (BITS(OP,0x0400))
	{
		// The double word MoveM operation...
	    UINT16 nextWord = ROPCODE((PC<<1)+2) ;

		UINT8 increment = BITS(OP,0x00ff) ;

		int W = BITS(nextWord, 0x0100) ;

		unsigned char sdt = 0x00 ;
		void *sdReg = 0x00 ;
		sdReg = DecodeHHHTable(BITS(nextWord,0x0007), &sdt) ;

		if (W)
		{
			// Read from Program Memory...
			UINT16 data = program_read_word_16le((R2<<1)+(increment<<1)) ;
			SetDestinationValue(&data, DT_WORD, sdReg, sdt) ;
		}
		else
		{
			// Write to Program Memory...
			// !!! Does this work ???
			// SetMemoryValue(sdReg, sdt, ((R2<<1)+(increment<<1))) ;
		}

		retSize = 2 ;
	}
	else
	{
		// The single word MoveM operation...

		// Decode which way the data is going...
		int W = BITS(OP,0x0100) ;

		// Decode which R Register we're working with...
		unsigned char rt = 0x00 ;
		void *rReg = 0x00 ;
		rReg = DecodeRRTable(BITS(OP,0x00c0), &rt) ;

		if (BITS(OP,0x0020))
		{
			// R and R operation
			retSize = 666 ;
		}
		else
		{
			// R and SD operation
			// Decode the SD register...
			unsigned char sdt = 0x00 ;
			void *sdReg = 0x00 ;
			sdReg = DecodeHHHTable(BITS(OP,0x0007), &sdt) ;

			if (W)
			{
				// Read from Program Memory...
				UINT16 data = program_read_word_16le( (*((UINT16*)rReg)) << 1 ) ;
				SetDestinationValue(&data, DT_WORD, sdReg, sdt) ;
			}
			else
			{
				// Write to Program Memory...
				SetProgramMemoryValue(sdReg, sdt, (*((UINT16*)rReg)) << 1 ) ;
			}

			// Execute the increment part of the opcode...
			ExecuteMMTable(BITS(OP,0x00c0), BITS(OP,0x0018)) ;

			retSize = 1 ;
		}
	}

	return retSize ;
}

static int MoveIOperation(void)
{
	int retSize = 1 ;

	// The 8-bit signed immediate operand is stored in the low byte of destination
	//   register D after having been sign extended.

	INT8 immediateVal = OP & 0x00ff ;
	UINT16 immediateWord ;

	unsigned char dt = 0x00 ;
	void *destinationReg = 0x00 ;

	destinationReg = DecodeDDTable(BITS(OP,0x0300), &dt) ;

	// Sign extend the immediate value...
	// !!! On Intel architecture this works correctly, does it work everywhere ???
	immediateWord = (INT16)immediateVal ;

	SetDestinationValue(&immediateWord, DT_WORD, destinationReg, dt) ;

	return retSize ;
}

static int MovePOperation(void)
{
	int retSize = 1 ;

	if (BITS(OP,0x1000))
	{
		// X:<pp> and SD
		UINT16 pp ;
		UINT16 W  ;

		unsigned char sdt = 0x00 ;
		void *SD = 0x00 ;

		SD = DecodeHHTable(BITS(OP,0x00c0), &sdt) ;

		pp = BITS(OP,0x001f) ;
		pp = AssembleAddressFromIOShortAddress(pp) ;

		W = BITS(OP,0x0100) ;

		if (W)
		{
			UINT16 data = data_read_word_16le(pp<<1) ;
			SetDestinationValue(&data, DT_WORD, SD, sdt) ;
		}
		else
		{
			SetDataMemoryValue(SD, sdt, pp<<1) ;
		}
	}
	else
	{
		// X:<Rx> and X:<pp>
		UINT16 pp ;
		UINT16 W  ;

		unsigned char sdrt = 0x00 ;
		void *sdrReg       = 0x00 ;
		sdrReg = DecodeRRTable(BITS(OP,0x00c0), &sdrt) ;

		pp = BITS(OP,0x001f) ;
		pp = AssembleAddressFromIOShortAddress(pp) ;

		W = BITS(OP,0x0100) ;

		// A little different than most W if's - opposite read and write thingies...
		if (W)
		{
			UINT16 data = data_read_word_16le( (*((UINT16*)sdrReg))<<1 ) ;		// read the word out
			SetDataMemoryValue(&data, DT_WORD, pp<<1) ;
		}
		else
		{
			mame_printf_debug("NOTHING HERE (yet)\n") ;
		}

		// Postincrement
		ExecutemTable(BITS(OP,0x00c0), BITS(OP,0x0020)) ;
	}

	return retSize ;
}


static int JmpOperation(void)
{
	int retSize = 0 ;

	core.ppc = PC;

	if (BITS(OP,0x0010))
	{
		PC = (ROPCODE((PC<<1)+2)) ;		// Can this offset by 2 bytes be handled better?  Say, for example, by moving "1 word"?
		change_pc(PC) ;
	}
	else
	{
		unsigned char rt = 0x00 ;
		void *R = 0x00 ;

		R = DecodeRRTable(BITS(OP,0x0003), &rt);

		PC = *((UINT16*)R);
		change_pc(PC);
	}

	retSize = 0 ;					// Jump with no offset.

	return retSize ;
}

static int BsrOperation(void)
{
	int retSize = 0 ;

	INT16 branchOffset = (ROPCODE((PC<<1)+2)) ;	// Can this offset by 2 bytes be handled better?  Say, for example, by moving "1 word"?

	// "The PC Contains the address of the next instruction"
	PC += 2 ;
	core.ppc = PC ;

	// Push the PC to the stack...
	SP++ ;					// !!! I'm not so sure about this 'pre-increment'
							//     The reason it might be there is that SSH and SSL are supposed to point to the top of the
							//     stack (and the docs seem to imply this behaviour).  But it wastes the first stack entry ???
							//     !!! I think i've read somewhere that PC == 1 when the stack is empty ???
							//     !!! I also .know. there are only 15 stack entries - could this be why ???
	SSH = PC ;
	SSL = SR ;

	PC += branchOffset ;

	retSize = 0 ;									// Branch and then no offset.

	change_pc(PC) ;

	return retSize ;
}

static int JsrOperation(void)
{
	int retSize = 0;

	// Handle other JSR types!
	INT16 branchOffset = (ROPCODE((PC<<1)+2)) ;	// Can this offset by 2 bytes be handled better?  Say, for example, by moving "1 word"?

	// The docs say nothing of this, but I swear it *must* be true
	PC += 2 ;
	core.ppc = PC ;

	// See bsr operation
	SP++;
	SSH = PC;
	SSL = SR;

	PC = branchOffset;

	return retSize;
}

static int BraOperation(void)
{
	int retSize = 0 ;

	// Branch to the location in program memory at location PC+displacement.
	INT16 branchOffset = 0x00;

	if (BITS(OP,0x0800))
	{
		// 8 bit immediate (relative) offset
		branchOffset = (INT8)BITS(OP,0x00ff) ;

		// "The PC Contains the address of the next instruction"
		PC += 1 ;
	}
	else if (BITS(OP,0x0010))
	{
		// 16 bit immediate (relative) offset
		retSize = 666 ;
	}
	else if (!BITS(OP,0x0010))
	{
		// 16 bit Rx offset
		retSize = 666 ;
	}

	core.ppc = PC ;
	PC += branchOffset ;

	change_pc(PC) ;

	return retSize ;
}


static int DoOperation(void)
{
	int retSize = 0 ;

	UINT16 offset ;

	// First instruction cycle
	SP++ ;
	SSH = LA ;
	SSL = LC ;

	if (BITS(OP,0x0800))
	{
		// #xx,expr
		LC = BITS(OP,0x00ff) ;
		retSize = 2 ;
	}
	else if (BITS(OP,0x0400))
	{
		// S,expr
		unsigned char sdt = 0x00 ;
		void *SD ;

		// !!! Watch out for the special cases (FamilyManual page 276) !!!
		SD = DecodeDDDDDTable(BITS(OP,0x001f), &sdt) ;
		SetDestinationValue(SD, sdt, &LC, DT_WORD) ;
		retSize = 2 ;
	}
	else
	{
		// X:(Rn),expr
		retSize = 666 ;
	}


	// Second instruction cycle
	SP++ ;
	SSH = PC+2 ;			// The value in the Program Counter (PC) register pushed onto the system stack is the address of the first instruction following the DO instruction
	SSL = SR ;

	offset = 0x00 ;			// The offset is the same for all DO instructions...
	offset = (ROPCODE((PC<<1)+2)) ;
	offset += PC+2 ;
	LA = offset ;


	// Third instruction cycle
	LF_bit_set(1);

	return retSize ;
}

static void EndOfLoopProcessing(void)
{
	SR = SSL ;
	SP-- ;
	LA = SSH ;
	LC = SSL ;
	SP-- ;
}

static int Dec24Operation(void **wd, UINT64 *pa)
{
	int retSize = 1 ;

	UINT64 decMe ;

	unsigned char drt = 0x00 ;
	void *D = 0x00 ;
	D = DecodeFTable(BITS(OP,0x0008), &drt) ;

	*pa = *((UINT64*)D) ;	// backup the previous value

	// !! I wonder if this should be a signed int instead !!
	decMe = (*((UINT64*)D) & (UINT64)U64(0xffffff0000)) >> 16 ;
	decMe-- ;
	decMe &= (UINT64)U64(0x0000000000ffffff) ;						// For wraparound - Make sure no bits get set improperly in A/B

//  UINT8 carryBit = (*((UINT64*)D) & 0x0000008000000000) >> 39 ;   // For determinating carry status...

	*((UINT64*)D) &= (UINT64)U64(0x000000000000ffff) ;				// Prepare the destination to be set...
	*((UINT64*)D) |= (decMe << 16) ;						// Set the top 24 bits accordingly...

	// Carry flag (C) - HACK
//  if (decMe == 0x0000000000ff7fff)
//      SET_cBIT() ;
//  else
//      CLEAR_cBIT() ;

	// Carry flag (C)
//  UINT8 postCarryBit = (*((UINT64*)D) & 0x0000008000000000) >> 39 ;
//  if (postCarryBit != carryBit)   SET_cBIT() ;
//  else                          CLEAR_cBIT() ;

    *wd = D ;

/*
    UINT32 decMe = ((*((PAIR64*)D)).b.h4 << 16) | (*((PAIR64*)D)).w.h ;

    int fflag = 0 ;
    if (decMe == 0x00007fff) fflag = 1 ;

    if (fflag) mame_printf_debug("%08x\n", decMe) ;

    decMe-- ;

    if (fflag) mame_printf_debug("%08x\n", decMe) ;

    decMe &= 0x00ffffff ;

    if (fflag) mame_printf_debug("%08x\n", decMe) ;

    UINT8 carryBit = ((*((PAIR64*)D)).b.h4 & 0x80) >> 7 ;

    (*((PAIR64*)D)).b.h4 = (decMe & 0x00ff0000) >> 16 ;
    (*((PAIR64*)D)).w.h  = (decMe & 0x0000ffff) ;

    if (fflag) mame_printf_debug("%2x\n", (*((PAIR64*)D)).b.h4) ;
    if (fflag) mame_printf_debug("%4x\n", (*((PAIR64*)D)).w.h) ;

    // Carry flag (C)
    UINT8 postCarryBit = ((*((PAIR64*)D)).b.h4 & 0x80) >> 7 ;
    if (postCarryBit != carryBit)   SET_cBIT() ;
    else                          CLEAR_cBIT() ;

    *wd = D ;
*/
	return retSize ;
}

static int AddOperation(void **wd, UINT64 *pa)
{
	UINT64 addVal = 0x00;

	unsigned char st = 0x00, dt = 0x00 ;
	void *S = 0x00, *D = 0x00;

	DecodeJJJFTable(BITS(OP,0x0007),BITS(OP,0x0008), &S, &st, &D, &dt) ;

	*pa = *((UINT64*)D) ;	// backup the previous value

	switch(st)
	{
		case DT_WORD:        addVal = (UINT64)*((UINT16*)S) << 16 ; break ;
		case DT_DOUBLE_WORD: addVal = (UINT64)*((UINT32*)S) ;       break ;
		case DT_LONG_WORD:   addVal = (UINT64)*((UINT64*)S) ;       break ;
	}

	*((UINT64*)D) += addVal ;

	*wd = D ;

    return 1 ;
}

static int LsrOperation(void **wd, UINT64 *pa)
{
	int retSize = 1 ;

	UINT16 result ;

	unsigned char dt = 0x00 ;
	void *D = 0x00 ;

	D = DecodeFTable(BITS(OP,0x0008), &dt) ;

	*pa = *((UINT64*)D) ;	// backup the previous value

    // !!! Make sure to hold the MS bit and shift the LS bit properly !!!

	result = (*((PAIR64*)D)).w.h >> 1 ;
	(*((PAIR64*)D)).w.h = result ;

	*wd = D ;
	return retSize ;
}

static int AsrOperation(void **wd, UINT64 *pa)
{
	int retSize = 1 ;

	unsigned char dt = 0x00 ;
	void *D = 0x00 ;

	D = DecodeFTable(BITS(OP,0x0008), &dt) ;

	*pa = *((UINT64*)D) ;	// backup the previous value

    // !!! Make sure to hold the MS bit and shift the LS bit properly !!!

	*((UINT64*)D) = (*((UINT64*)D)) >> 1 ;

	*wd = D ;
	return retSize ;
}

static int NotOperation(void **wd, UINT64 *pa)
{
	int retSize = 1 ;

	unsigned char dt = 0x00 ;
	void *D = 0x00 ;

	D = DecodeFTable(BITS(OP,0x0008), &dt) ;

	*pa = *((UINT64*)D) ;	// backup the previous value

	(*((PAIR64*)D)).w.h ^= 0xffff ;

	*wd = D ;
	return retSize ;
}


static int EorOperation(void **wd, UINT64 *pa)
{
	int retSize = 1 ;

	UINT16 result ;

	unsigned char st = 0x00, dt = 0x00 ;
	void *S = 0x00, *D = 0x00;

	DecodeJJFTable(BITS(OP,0x0003),BITS(OP,0x0008), &S, &st, &D, &dt) ;

	*pa = *((UINT64*)D) ;	// backup the previous value

	// This operation does an XOR of a word of S with A1/B1...
	result = *((UINT16*)S) ^ (*((PAIR64*)D)).w.h ;
	(*((PAIR64*)D)).w.h = result ;

	*wd = D ;
	return retSize ;
}

static int TfrDataALUOperation(void **wd, UINT64 *pa)
{
	int retSize = 1 ;

	unsigned char st = 0x00, dt = 0x00 ;
	void *S = 0x00, *D = 0x00;

	DecodeJJJFTable(BITS(OP,0x0007),BITS(OP,0x0008), &S, &st, &D, &dt) ;

	*pa = *((UINT64*)D) ;	// backup the previous value

	SetDestinationValue(S, st, D, dt) ;

	*wd = D ;
	return retSize ;
}

static int AndOperation(void **wd, UINT64 *pa)
{
	int retSize = 1 ;

	UINT16 result ;

	unsigned char st = 0x00, dt = 0x00 ;
	void *S = 0x00, *D = 0x00;

	DecodeJJFTable(BITS(OP,0x0003),BITS(OP,0x0008), &S, &st, &D, &dt) ;

	*pa = *((UINT64*)D) ;	// backup the previous value

	// This operation does an AND of a word of S with A1/B1...
	result = *((UINT16*)S) & (*((PAIR64*)D)).w.h ;
	(*((PAIR64*)D)).w.h = result ;

	*wd = D ;
	return retSize ;
}

static int OrOperation(void **wd, UINT64 *pa)
{
	int retSize = 1 ;

	UINT16 result ;

	unsigned char st = 0x00, dt = 0x00 ;
	void *S = 0x00, *D = 0x00;

	DecodeJJFTable(BITS(OP,0x0003),BITS(OP,0x0008), &S, &st, &D, &dt) ;

	*pa = *((UINT64*)D) ;	// backup the previous value

	// This operation does an OR of a word of S with A1/B1...
	result = *((UINT16*)S) | (*((PAIR64*)D)).w.h ;
	(*((PAIR64*)D)).w.h = result ;

	*wd = D ;
	return retSize ;
}


static int TccOperation(void)
{
	int retSize = 1 ;

	int transfer = DecodeccccTable(BITS(OP,0x03c0)) ;

    // !!! WARNING === TESTING !!!
	// transfer = 1 ;

	if (transfer)
	{
		unsigned char st = 0x00, dt = 0x00 ;
		void *S = 0x00, *D = 0x00;

		unsigned char drt    = 0x00 ;
		void *destinationReg = 0x00 ;

		Decodeh0hFTable(BITS(OP,0x0007),BITS(OP,0x0008), &S, &st, &D, &dt) ;

		SetDestinationValue(S, st, D, dt) ;

		// !!! What's up with that A,A* thing in the docs?  Does that mean "do not transfer R0 to Rn ???
		destinationReg = DecodeRRTable(BITS(OP,0x0030), &drt) ; // Actually a TT table, but it's the same

		SetDestinationValue(&R0, DT_WORD, destinationReg, drt) ;
	}

	// Otherwise it's a NOP

	return retSize ;
}

static int ClrOperation(void **wd, UINT64 *pa)
{
	int retSize = 1 ;

	UINT64 clearValue = 0 ;

	unsigned char drt    = 0x00 ;
	void *destinationReg = 0x00 ;

	destinationReg = DecodeFTable(BITS(OP,0x0008), &drt) ;

	*pa = *((UINT64*)destinationReg) ;	// backup the previous value

	SetDestinationValue(&clearValue, DT_LONG_WORD, destinationReg, drt) ;

    *wd = destinationReg ;
	return retSize ;
}

static int TstOperation(void **wd, UINT64 *pa)
{
	int retSize = 1 ;

	unsigned char drt    = 0x00 ;
	void *destinationReg = 0x00 ;
	destinationReg = DecodeFTable(BITS(OP,0x0008), &drt) ;

	// S - "computed according to the standard definition (section A.4)"
	// L - can't be done until after data move
	// E - set if signed integer portion is in use
	// U - set according to the standard definition of the U bit
	// N - set if bit 39 is set
	if (*((UINT64*)destinationReg) & (UINT64)U64(0x8000000000)) N_bit_set(1);
	else										                N_bit_set(0);

	// Z - set if == 0
	if (*((UINT64*)destinationReg) == 0) Z_bit_set(1);
	else								 Z_bit_set(0);

	// V&C - always cleared
	V_bit_set(0);
	C_bit_set(0);

	*pa = *((UINT64*)destinationReg) ;	// backup the previous value (no change here)
	*wd = destinationReg;

	return retSize ;
}

static int AndiOperation(void)
{
	int retSize = 1 ;

	UINT16 andMe = BITS(OP,0x00ff) ;

	// Because I don't have a good way to access MR and CCR right now, i'm going to
	//   hard-code decoding EE here and in the OriOperation as well...
	switch(BITS(OP,0x0600))
	{
		// MR
		case 0x01:
			SR  &= ((andMe << 8) | 0x00ff) ;
			break ;

		// CCR
		case 0x03:
			SR  &= ((andMe)      | 0xff00) ;
			break ;

		// OMR
		case 0x02:
			OMR &= (UINT8)(andMe) ;
			break ;

		default:
			fatalerror("DSP56k - BAD EE value in andi operation") ;
	}


	return retSize ;
}

#ifdef UNUSED_FUNCTION
// !!! NOT IMPLEMENTED YET - JUST PUT HERE TO BE NEXT TO ANDI SOMEDAY !!!
static int OriOperation(void)
{
	int retSize = 1 ;

	return retSize ;
}
#endif

static int CmpOperation(void **wd, UINT64 *pa)
{
	int retSize = 1 ;

	UINT64 cmpVal ;
	UINT64 result ;

	unsigned char st = 0x00, dt = 0x00 ;
	void *S = 0x00, *D = 0x00;

	DecodeJJJFTable(BITS(OP,0x0007),BITS(OP,0x0008), &S, &st, &D, &dt) ;

	*pa = *((UINT64*)D) ;	// backup the previous value - not necessary for cmp :)

	switch(st)
	{
		default:
		case DT_WORD:        cmpVal = (UINT64)*((UINT16*)S) ; break ;
		case DT_DOUBLE_WORD: cmpVal = (UINT64)*((UINT32*)S) ; break ;
		case DT_LONG_WORD:   cmpVal = (UINT64)*((UINT64*)S) ; break ;
	}

	result = *((UINT64*)D) - cmpVal ;

	if (result == 0)
		Z_bit_set(1) ;
	else
		Z_bit_set(0) ;

    *wd = D ;
	return retSize ;
}

static int BsccOperation(void)
{
	int retSize = 0 ;

	// Decode the condition
	int transfer = DecodeccccTable(BITS(OP,0x000f)) ;

	// TESTING !!!
	// transfer = 0 ;

	// 1 or 2 word operation...
	if (transfer)
	{
		if (BITS(OP,0x0010))
		{
			// 2 word immediate offset...
			INT16 branchOffset = (INT16)ROPCODE((PC<<1)+2) ;

			// "The PC Contains the address of the next instruction"
			PC += 2 ;
			core.ppc = PC ;

			SP++ ;
			SSH = PC ;
			SSL = SR ;

			PC += branchOffset ;

			change_pc(PC) ;
		}
		else
		{
			// 1 word Rx offset...
		}

		retSize = 0 ;
	}
	else
	{
		if (BITS(OP,0x0010))
			retSize = 2 ;
		else
			retSize = 1 ;
	}

	return retSize ;
}

static int BccOperation(void)
{
	int retSize = 0 ;

	if (!BITS(OP,0x2000))
	{
		int branch = DecodeccccTable(BITS(OP,0x000f)) ;

		if (branch)
		{
			if (BITS(OP,0x0010))
			{
				// B.cc xxxx
			    INT16 op2 = ROPCODE((PC<<1)+2) ;

				// The PC contains the address of the next instruction
				PC += 2 ;
    			core.ppc = PC ;
				PC += op2 ;

				change_pc(PC) ;
			}
			else
			{
				// B.cc Rn
			}
		}
		else
		{
			if (BITS(OP,0x0010))
				retSize = 2 ;
			else
				retSize = 1 ;
		}
	}
	else
	{
		// B.cc aa
		int branch = DecodeccccTable(BITS(OP,0x03c0)) ;

		if (branch)
		{
			INT16 offset = (INT16)AssembleAddressFrom6BitSignedRelativeShortAddress(BITS(OP,0x003f)) ;

			PC += 1 ;
			core.ppc = PC ;
			PC += offset ;

			change_pc(PC) ;
		}
		else
		{
			retSize = 1 ;
		}
	}

	return retSize ;
}

static int Tst2Operation(void)
{
	int retSize = 1 ;

	unsigned char dt = 0x00 ;
	void *destinationReg = 0x00 ;

	destinationReg = DecodeDDTable(BITS(OP,0x0003), &dt) ;

	// unnormalized

	// negative
	// bit 31 of A or B ???

	// zero
	if ( (*((UINT16*)destinationReg)) == 0)
		Z_bit_set(1);
	else
		Z_bit_set(0);

	// always clear C flag
	C_bit_set(0) ;

	return retSize ;
}

static int MACsuuuOperation(void)
{
	int retSize = 1 ;

	INT64 result = 0 ;

	int s ;
	void *S1 = 0x00, *S2 = 0x00, *D = 0x00 ;

	DecodeQQFTableSp(BITS(OP,0x0003), BITS(OP,0x0008), &S1, &S2, &D) ;

	s = BITS(OP,0x0004) ;

	// !!! There is no way this is right - wtf is EXT:MSP:LSP format ???
	if (!s)
	{
		// su
		result = ( (INT32)(*((UINT16*)S1)) *  (UINT32)(*((UINT16*)S2)) ) << 1 ;
	}
	else
	{
		// uu
		result = ( (UINT32)(*((UINT16*)S1)) * (UINT32)(*((UINT16*)S2)) ) << 1 ;
	}

	(*((UINT64*)D)) += result ;

	return retSize ;
}

static int RepOperation(void)
{
	int retSize = 1 ;

	UINT16 count = 0x0000 ;

	if (BITS(OP,0x0f00) == 0xf)
	{
		// immediate
		count = BITS(OP,0x00ff) ;
	}
	else if (BITS(OP,0x0f00) == 0x4)
	{
		// SD
		unsigned char st = 0x00 ;
		void *S ;

		S = DecodeDDDDDTable(BITS(OP,0x001f), &st) ;
		SetDestinationValue(S, st, &count, DT_WORD);
	}
	else
	{
		// X:(Rn)
	}

	TEMP = LC ;
	LC = count ;

	core.repFlag = 1 ;
	core.repAddr = PC + (retSize<<1) ;

	return retSize ;
}

static void EndOfRepProcessing(void)
{
	LC = TEMP ;

	core.repFlag = 0 ;
	core.repAddr = 0x0000 ;
}


/*
DECODERS
*/
static void *DecodeDDDDDTable(UINT16 DDDDD, unsigned char *dt)
{
	void *retAddress = 0x00 ;

	switch(DDDDD)
	{
		case 0x00: retAddress = &X0  ; *dt = DT_WORD ;      break ;
		case 0x01: retAddress = &Y0  ; *dt = DT_WORD ;      break ;
		case 0x02: retAddress = &X1  ; *dt = DT_WORD ;      break ;
		case 0x03: retAddress = &Y1  ; *dt = DT_WORD ;      break ;
		case 0x04: retAddress = &A   ; *dt = DT_LONG_WORD ; break ;
		case 0x05: retAddress = &B   ; *dt = DT_LONG_WORD ; break ;
		case 0x06: retAddress = &A0  ; *dt = DT_WORD ;      break ;
		case 0x07: retAddress = &B0  ; *dt = DT_WORD ;      break ;
		case 0x08: retAddress = &LC  ; *dt = DT_WORD ;      break ;
		case 0x09: retAddress = &SR  ; *dt = DT_WORD ;      break ;
		case 0x0a: retAddress = &OMR ; *dt = DT_BYTE ;      break ;
		case 0x0b: retAddress = &SP  ; *dt = DT_BYTE ;      break ;
		case 0x0c: retAddress = &A1  ; *dt = DT_WORD ;      break ;
		case 0x0d: retAddress = &B1  ; *dt = DT_WORD ;      break ;
		case 0x0e: retAddress = &A2  ; *dt = DT_BYTE ;      break ;
		case 0x0f: retAddress = &B2  ; *dt = DT_BYTE ;      break ;

		case 0x10: retAddress = &R0  ; *dt = DT_WORD ;      break ;
		case 0x11: retAddress = &R1  ; *dt = DT_WORD ;      break ;
		case 0x12: retAddress = &R2  ; *dt = DT_WORD ;      break ;
		case 0x13: retAddress = &R3  ; *dt = DT_WORD ;      break ;
		case 0x14: retAddress = &M0  ; *dt = DT_WORD ;      break ;
		case 0x15: retAddress = &M1  ; *dt = DT_WORD ;      break ;
		case 0x16: retAddress = &M2  ; *dt = DT_WORD ;      break ;
		case 0x17: retAddress = &M3  ; *dt = DT_WORD ;      break ;
		case 0x18: retAddress = &SSH ; *dt = DT_WORD ;      break ;
		case 0x19: retAddress = &SSL ; *dt = DT_WORD ;      break ;
		case 0x1a: retAddress = &LA  ; *dt = DT_WORD ;      break ;
		//no 0x1b
		case 0x1c: retAddress = &N0  ; *dt = DT_WORD ;      break ;
		case 0x1d: retAddress = &N1  ; *dt = DT_WORD ;      break ;
		case 0x1e: retAddress = &N2  ; *dt = DT_WORD ;      break ;
		case 0x1f: retAddress = &N3  ; *dt = DT_WORD ;      break ;
	}

	return retAddress ;
}

static void *DecodeRRTable(UINT16 RR, unsigned char *dt)
{
	void *retAddress = 0x00 ;

	switch(RR)
	{
		case 0x00: retAddress = &R0 ; *dt = DT_WORD ; break ;
		case 0x01: retAddress = &R1 ; *dt = DT_WORD ; break ;
		case 0x02: retAddress = &R2 ; *dt = DT_WORD ; break ;
		case 0x03: retAddress = &R3 ; *dt = DT_WORD ; break ;
	}

	return retAddress ;
}

static void *DecodeDDTable(UINT16 DD, unsigned char *dt)
{
	void *retAddress = 0x00 ;

	switch(DD)
	{
		case 0x00: retAddress = &X0 ; *dt = DT_WORD ; break ;
		case 0x01: retAddress = &Y0 ; *dt = DT_WORD ; break ;
		case 0x02: retAddress = &X1 ; *dt = DT_WORD ; break ;
		case 0x03: retAddress = &Y1 ; *dt = DT_WORD ; break ;
	}

	return retAddress ;
}

static void *DecodeHHHTable(UINT16 HHH, unsigned char *dt)
{
	void *retAddress = 0x00 ;

	switch(HHH)
	{
		case 0x0: retAddress = &X0 ; *dt = DT_WORD ;      break ;
		case 0x1: retAddress = &Y0 ; *dt = DT_WORD ;      break ;
		case 0x2: retAddress = &X1 ; *dt = DT_WORD ;      break ;
		case 0x3: retAddress = &Y1 ; *dt = DT_WORD ;      break ;
		case 0x4: retAddress = &A  ; *dt = DT_LONG_WORD ; break ;
		case 0x5: retAddress = &B  ; *dt = DT_LONG_WORD ; break ;
		case 0x6: retAddress = &A0 ; *dt = DT_WORD ;      break ;
		case 0x7: retAddress = &B0 ; *dt = DT_WORD ;      break ;
	}

	return retAddress ;
}

static void *DecodeHHTable(UINT16 HH, unsigned char *dt)
{
	void *retAddress = 0x00 ;

	switch(HH)
	{
		case 0x0: retAddress = &X0 ; *dt = DT_WORD ;      break ;
		case 0x1: retAddress = &Y0 ; *dt = DT_WORD ;      break ;
		case 0x2: retAddress = &A  ; *dt = DT_LONG_WORD ; break ;
		case 0x3: retAddress = &B  ; *dt = DT_LONG_WORD ; break ;
	}

	return retAddress ;
}

static void *DecodeZTable(UINT16 Z, unsigned char *dt)
{
	void *retAddress = 0x00 ;

	switch(Z)
	{
		// Fixed as per the Family Manual addendum
		case 0x01: retAddress = &A1 ; *dt = DT_WORD ; break ;
		case 0x00: retAddress = &B1 ; *dt = DT_WORD ; break ;
	}

	return retAddress ;
}


static UINT16 DecodeBBBBitMask(UINT16 BBB, UINT16 *iVal)
{
	UINT16 retVal = 0x00 ;

	switch(BBB)
	{
		case 0x4: retVal = 0xff00 ; *iVal <<= 8 ; break ;
		case 0x2: retVal = 0x0ff0 ; *iVal <<= 4 ; break ;
		case 0x1: retVal = 0x00ff ; *iVal <<= 0 ; break ;
	}

	return retVal ;
}

static void ExecuteMMTable(int x, UINT16 MM)
{
	UINT16 *rX = 0x00 ;
	UINT16 *nX = 0x00 ;

	switch(x)
	{
		case 0x0: rX = &R0 ; nX = &N0 ; break ;
		case 0x1: rX = &R1 ; nX = &N1 ; break ;
		case 0x2: rX = &R2 ; nX = &N2 ; break ;
		case 0x3: rX = &R3 ; nX = &N3 ; break ;
	}

	switch(MM)
	{
		case 0x0: /* do nothing */      break ;
		case 0x1: (*rX)++ ;             break ;
		case 0x2: (*rX)-- ;             break ;
		case 0x3: (*rX) = (*rX)+(*nX) ; break ;
	}
}

static void ExecutemTable(int x, UINT16 m)
{
	UINT16 *rX = 0x00 ;
	UINT16 *nX = 0x00 ;

	switch(x)
	{
		case 0x0: rX = &R0 ; nX = &N0 ; break ;
		case 0x1: rX = &R1 ; nX = &N1 ; break ;
		case 0x2: rX = &R2 ; nX = &N2 ; break ;
		case 0x3: rX = &R3 ; nX = &N3 ; break ;
	}

	switch(m)
	{
		case 0x0: (*rX)++ ;             break ;
		case 0x1: (*rX) = (*rX)+(*nX) ; break ;
	}
}

static void ExecutezTable(int x, UINT16 z)
{
	UINT16 *rX = 0x00 ;
	UINT16 *nX = 0x00 ;

	switch(x)
	{
		case 0x0: rX = &R0 ; nX = &N0 ; break ;
		case 0x1: rX = &R1 ; nX = &N1 ; break ;
		case 0x2: rX = &R2 ; nX = &N2 ; break ;
		case 0x3: rX = &R3 ; nX = &N3 ; break ;
	}

	if (!z)
	{
		(*rX)-- ;
	}
	else
	{
		(*rX) = (*rX)+(*nX) ;
	}
}

// Returns R address
static UINT16 ExecuteqTable(int x, UINT16 q)
{
	UINT16 *rX = 0x00 ;
	UINT16 *nX = 0x00 ;

	switch(x)
	{
		case 0x0: rX = &R0 ; nX = &N0 ; break ;
		case 0x1: rX = &R1 ; nX = &N1 ; break ;
		case 0x2: rX = &R2 ; nX = &N2 ; break ;
		case 0x3: rX = &R3 ; nX = &N3 ; break ;
	}

	switch(q)
	{
		case 0x0: /* No permanent changes */ ; return (*rX)+(*nX); break;
		case 0x1: (*rX)--;					   return (*rX);	   break;	// This one is special - it's a *PRE-decrement*!
	}

	exit(1);
	return 0x00;
}

static UINT16 AssembleDFromPTable(UINT16 P, UINT16 ppppp)
{
	UINT16 destAddr = 0x00 ;

	switch (P)
	{
		case 0x0: destAddr = ppppp ; break ;
		case 0x1: destAddr = AssembleAddressFromIOShortAddress(ppppp) ; break ;
	}

	return destAddr ;
}


static UINT16 AssembleAddressFromIOShortAddress(UINT16 pp)
{
	UINT16 fullAddy = 0xffe0 ;
	fullAddy |= pp ;
	return fullAddy ;
}

static UINT16 AssembleAddressFrom6BitSignedRelativeShortAddress(UINT16 srs)
{
	UINT16 fullAddy = srs ;
	if (fullAddy & 0x0020) fullAddy |= 0xffc0 ;

	return fullAddy ;
}

static int DecodeccccTable(UINT16 cccc)
{
	int retVal = 0 ;

	// !!! go back and check me again someday - potential bugs !!!
	switch (cccc)
	{
		// Arranged according to mnemonic table - not decoding table...
		case 0x0: if( C_bit() == 0)                              retVal = 1 ; break ; // cc(hs)
		case 0x8: if( C_bit() == 1)                              retVal = 1 ; break ; // cs(lo)
		case 0x5: if( E_bit() == 0)                              retVal = 1 ; break ; // ec
		case 0xa: if( Z_bit() == 1)                              retVal = 1 ; break ; // eq
		case 0xd: if( E_bit() == 1)                              retVal = 1 ; break ; // es
		case 0x1: if((N_bit() ^ V_bit()) == 0)                   retVal = 1 ; break ; // ge
		case 0x7: if((Z_bit() + (N_bit() ^ V_bit())) == 0)       retVal = 1 ; break ; // gt
		case 0x6: if( L_bit() == 0)                              retVal = 1 ; break ; // lc
		case 0xf: if((Z_bit() + (N_bit() ^ V_bit())) == 1)       retVal = 1 ; break ; // le
		case 0xe: if( L_bit() == 1)                              retVal = 1 ; break ; // ls
		case 0x9: if((N_bit() ^ V_bit()) == 1)                   retVal = 1 ; break ; // lt
		case 0xb: if( N_bit() == 1)                              retVal = 1 ; break ; // mi
		case 0x2: if( Z_bit() == 0)                              retVal = 1 ; break ; // ne
		case 0xc: if((Z_bit() + ((!U_bit()) & (!E_bit()))) == 1) retVal = 1 ; break ; // nr
		case 0x3: if( N_bit() == 0)                              retVal = 1 ; break ; // pl
		case 0x4: if((Z_bit() + ((!U_bit()) & (!E_bit()))) == 0) retVal = 1 ; break ; // nn
	}

	return retVal ;
}

static void Decodeh0hFTable(UINT16 h0h, UINT16 F,
					 void **source, unsigned char *st,
					 void **dest,   unsigned char *dt)
{
	UINT16 switchVal = (h0h << 1) | F ;

	switch (switchVal)
	{
		case 0x8: *source = &X0 ; *st = DT_WORD ;      *dest = &A ; *dt = DT_LONG_WORD ; break ;
		case 0x9: *source = &X0 ; *st = DT_WORD ;      *dest = &B ; *dt = DT_LONG_WORD ; break ;
		case 0xa: *source = &Y0 ; *st = DT_WORD ;      *dest = &A ; *dt = DT_LONG_WORD ; break ;
		case 0xb: *source = &Y0 ; *st = DT_WORD ;      *dest = &B ; *dt = DT_LONG_WORD ; break ;
		case 0x2: *source = &A  ; *st = DT_LONG_WORD ; *dest = &A ; *dt = DT_LONG_WORD ; break ;
		case 0x1: *source = &A  ; *st = DT_LONG_WORD ; *dest = &B ; *dt = DT_LONG_WORD ; break ;
		case 0x0: *source = &B  ; *st = DT_LONG_WORD ; *dest = &A ; *dt = DT_LONG_WORD ; break ;
		case 0x3: *source = &B  ; *st = DT_LONG_WORD ; *dest = &B ; *dt = DT_LONG_WORD ; break ;
	}
}

static void *DecodeFTable(UINT16 F, unsigned char *dt)
{
	void *retAddress = 0x00 ;

	switch(F)
	{
		case 0x0: retAddress = &A ; *dt = DT_LONG_WORD ; break ;
		case 0x1: retAddress = &B ; *dt = DT_LONG_WORD ; break ;
	}

	return retAddress ;
}

static void DecodeJJJFTable(UINT16 JJJ, UINT16 F,
					 void **source, unsigned char *st,
					 void **dest,   unsigned char *dt)
{
	UINT16 switchVal = (JJJ << 1) | F ;

	switch(switchVal)
	{
		case 0x0: *source = &B  ; *st = DT_LONG_WORD   ; *dest = &A ; *dt = DT_LONG_WORD ; break ;
		case 0x1: *source = &A  ; *st = DT_LONG_WORD   ; *dest = &B ; *dt = DT_LONG_WORD ; break ;
		case 0x4: *source = &X  ; *st = DT_DOUBLE_WORD ; *dest = &A ; *dt = DT_LONG_WORD ; break ;
		case 0x5: *source = &X  ; *st = DT_DOUBLE_WORD ; *dest = &B ; *dt = DT_LONG_WORD ; break ;
		case 0x6: *source = &Y  ; *st = DT_DOUBLE_WORD ; *dest = &A ; *dt = DT_LONG_WORD ; break ;
		case 0x7: *source = &Y  ; *st = DT_DOUBLE_WORD ; *dest = &B ; *dt = DT_LONG_WORD ; break ;
		case 0x8: *source = &X0 ; *st = DT_WORD        ; *dest = &A ; *dt = DT_LONG_WORD ; break ;
		case 0x9: *source = &X0 ; *st = DT_WORD        ; *dest = &B ; *dt = DT_LONG_WORD ; break ;
		case 0xa: *source = &Y0 ; *st = DT_WORD        ; *dest = &A ; *dt = DT_LONG_WORD ; break ;
		case 0xb: *source = &Y0 ; *st = DT_WORD        ; *dest = &B ; *dt = DT_LONG_WORD ; break ;
		case 0xc: *source = &X1 ; *st = DT_WORD        ; *dest = &A ; *dt = DT_LONG_WORD ; break ;
		case 0xd: *source = &X1 ; *st = DT_WORD        ; *dest = &B ; *dt = DT_LONG_WORD ; break ;
		case 0xe: *source = &Y1 ; *st = DT_WORD        ; *dest = &A ; *dt = DT_LONG_WORD ; break ;
		case 0xf: *source = &Y1 ; *st = DT_WORD        ; *dest = &B ; *dt = DT_LONG_WORD ; break ;
	}
}

static void DecodeJJFTable(UINT16 JJ, UINT16 F,
					void **source, unsigned char *st,
					void **dest, unsigned char *dt)
{
	UINT16 switchVal = (JJ << 1) | F ;

	switch (switchVal)
	{
		case 0x0: *source = &X0 ; *st = DT_WORD ; *dest = &A ; *dt = DT_LONG_WORD ; break ;
		case 0x1: *source = &X0 ; *st = DT_WORD ; *dest = &B ; *dt = DT_LONG_WORD ; break ;
		case 0x2: *source = &Y0 ; *st = DT_WORD ; *dest = &A ; *dt = DT_LONG_WORD ; break ;
		case 0x3: *source = &Y0 ; *st = DT_WORD ; *dest = &B ; *dt = DT_LONG_WORD ; break ;
		case 0x4: *source = &X1 ; *st = DT_WORD ; *dest = &A ; *dt = DT_LONG_WORD ; break ;
		case 0x5: *source = &X1 ; *st = DT_WORD ; *dest = &B ; *dt = DT_LONG_WORD ; break ;
		case 0x6: *source = &Y1 ; *st = DT_WORD ; *dest = &A ; *dt = DT_LONG_WORD ; break ;
		case 0x7: *source = &Y1 ; *st = DT_WORD ; *dest = &B ; *dt = DT_LONG_WORD ; break ;
	}
}

// Types not necessary - we know what we are...
static void DecodeQQFTableSp(UINT16 QQ, UINT16 F, void **S1, void **S2, void **D)
{
	UINT16 switchVal = (QQ << 1) | F ;

	switch(switchVal)
	{
		case 0x0: *S1 = &Y0 ; *S2 = &X0 ; *D = &A ; break ;
		case 0x1: *S1 = &Y0 ; *S2 = &X0 ; *D = &B ; break ;
		case 0x2: *S1 = &Y1 ; *S2 = &X0 ; *D = &A ; break ;
		case 0x3: *S1 = &Y1 ; *S2 = &X0 ; *D = &B ; break ;
		case 0x4: *S1 = &X1 ; *S2 = &Y0 ; *D = &A ; break ;
		case 0x5: *S1 = &X1 ; *S2 = &Y0 ; *D = &B ; break ;
		case 0x6: *S1 = &X1 ; *S2 = &Y1 ; *D = &A ; break ;
		case 0x7: *S1 = &X1 ; *S2 = &Y1 ; *D = &B ; break ;
	}
}

static void DecodeIIIITable(UINT16 IIII,
					 void **source, unsigned char *st,
					 void **dest, unsigned char *dt,
					 void *working)
{
	void *opposite = 0x00 ;

	if (working == &A) opposite = &B ;
	else               opposite = &A ;

	switch(IIII)
	{
		case 0x0: *source = &X0      ; *st = DT_WORD ;      *dest = opposite ; *dt = DT_LONG_WORD ; break ;
		case 0x1: *source = &Y0      ; *st = DT_WORD ;      *dest = opposite ; *dt = DT_LONG_WORD ; break ;
		case 0x2: *source = &X1      ; *st = DT_WORD ;      *dest = opposite ; *dt = DT_LONG_WORD ; break ;
		case 0x3: *source = &Y1      ; *st = DT_WORD ;      *dest = opposite ; *dt = DT_LONG_WORD ; break ;
		case 0x4: *source = &A       ; *st = DT_LONG_WORD ; *dest = &X0      ; *dt = DT_WORD ;      break ;
		case 0x5: *source = &B       ; *st = DT_LONG_WORD ; *dest = &Y0      ; *dt = DT_WORD ;      break ;
		case 0x6: *source = &A0      ; *st = DT_WORD ;      *dest = &X0      ; *dt = DT_WORD ;      break ;
		case 0x7: *source = &B0      ; *st = DT_WORD ;      *dest = &Y0      ; *dt = DT_WORD ;      break ;
		case 0x8: *source = working  ; *st = DT_LONG_WORD ; *dest = opposite ; *dt = DT_LONG_WORD ; break ;
		case 0x9: *source = working  ; *st = DT_LONG_WORD ; *dest = opposite ; *dt = DT_LONG_WORD ; break ;
		case 0xc: *source = &A       ; *st = DT_LONG_WORD ; *dest = &X1      ; *dt = DT_WORD ;      break ;
		case 0xd: *source = &B       ; *st = DT_LONG_WORD ; *dest = &Y1      ; *dt = DT_WORD ;      break ;
		case 0xe: *source = &A0      ; *st = DT_WORD ;      *dest = &X1      ; *dt = DT_WORD ;      break ;
		case 0xf: *source = &B0      ; *st = DT_WORD ;      *dest = &Y1      ; *dt = DT_WORD ;      break ;
	}
}

/*
MEMORY OPS
*/

static void XMDMOperation(UINT16 parameters, void *working, UINT64 *pa)
{
	UINT16 W ;
	unsigned char rdt = 0x00 ;
	void *R = 0x00 ;

	unsigned char sdt = 0x00 ;
	void *SD = 0x00 ;

	// Get the source
	SD = DecodeHHHTable(BITS(parameters,0x000e), &sdt) ;

	// Get the destination
	R = DecodeRRTable(BITS(parameters,0x0030), &rdt) ;

	// Move the data
	W = BITS(parameters,0x0001) ;

	if (W)
	{
		// from X:<ea> to SD...
		// !!! TODO : Fill in similar comments for other "if (W)'s" !!!
		UINT16 data = data_read_word_16le((*((UINT16*)R))<<1) ;		// read the word out
		SetDestinationValue(&data, DT_WORD, SD, sdt) ;
	}
	else
	{
		// from SD to X:<ea>...

		// If the source is the same as the ALU destination, use the Previous Accumulator value
		if (working == SD)
		{
			// the value before the ALU operation was executed...
			SetDataMemoryValue(pa, DT_LONG_WORD, (*((UINT16*)R))<<1) ;
		}
		else
		{
			// Expected memory move
			SetDataMemoryValue(SD, sdt, (*((UINT16*)R))<<1) ;
		}
	}

	// Postincrement
	ExecutemTable(BITS(parameters,0x0030), BITS(parameters,0x0040)) ;
}

static void RRDMOperation(UINT16 parameters, void *working, UINT64 *pa)
{
	unsigned char st = 0x00, dt = 0x00 ;
	void *S = 0x00, *D = 0x00;

	DecodeIIIITable(BITS(parameters,0x000f), &S, &st, &D, &dt, working) ;

	// If the source is what we're working with, use the old value
	if (S == working)
		SetDestinationValue(pa, DT_LONG_WORD, D, dt) ;
	else
		SetDestinationValue(S, st, D, dt) ;
}


static void XMDMSpecialOperation(UINT16 parameters, void *working)
{
    UINT16 W ;
	UINT16 *dest = 0x00 ;

	// Get the source/destination
	unsigned char sdt = 0x00 ;
	void *SD = 0x00 ;
	SD = DecodeHHHTable(BITS(parameters,0x000e), &sdt) ;

	// Get the opposite A/B depending on what was used before
    if (working == &A)
        dest = &B1 ;
    else if (working == &B)
        dest = &A1 ;
    else
    {
        mame_printf_debug("WTF MF\n") ;
        return ;
    }

	// Move the data
	W = BITS(parameters,0x0001) ;

	if (W)
	{
		// from X:<ea> to SD...
		// !!! DOES THIS WORK ???
		UINT16 data = data_read_word_16le((*dest)<<1) ;		// read the word out
		SetDestinationValue(&data, DT_WORD, SD, sdt) ;
	}
	else
	{
		// Normal memory move
		SetDataMemoryValue(SD, sdt, (*dest)<<1) ;
	}
}

static void ARUOperation(UINT16 parameters)
{
	ExecutezTable(BITS(parameters, 0x0003), BITS(parameters, 0x0004)) ;
}


/*
HELPERS
*/
static UINT16 Dsp56kOpMask(UINT16 cur, UINT16 mask)
{
	int i ;

	UINT16 retVal = (cur & mask) ;
	UINT16 temp = 0x0000 ;
	int offsetCount = 0 ;

	// Shift everything right, eliminating 'whitespace'...
	for (i = 0; i < 16; i++)
	{
		if (mask & (0x1<<i))		// If mask bit is non-zero
		{
			temp |= (((retVal >> i) & 0x1) << offsetCount) ;
			offsetCount++ ;
		}
	}

	return temp ;
}


static void SetDestinationValue(void *sourcePointer, unsigned char sourceType,
						 void *destinationPointer, unsigned char destinationType)
{
	UINT64 destinationValue = 0 ;

	switch(destinationType)
	{
		case DT_BYTE:
			switch(sourceType)
			{
				case DT_BYTE:        *((UINT8*)destinationPointer) = *((UINT8*) sourcePointer) ; break ;
				case DT_WORD:        *((UINT8*)destinationPointer) = *((UINT16*)sourcePointer) ; break ;
				case DT_DOUBLE_WORD: *((UINT8*)destinationPointer) = *((UINT32*)sourcePointer) ; break ;
				case DT_LONG_WORD:   *((UINT8*)destinationPointer) = *((UINT64*)sourcePointer) ; break ;
			}
		break ;

		case DT_WORD:
			switch(sourceType)
			{
				case DT_BYTE:        *((UINT16*)destinationPointer) = *((UINT8*) sourcePointer) ; break ;
				case DT_WORD:        *((UINT16*)destinationPointer) = *((UINT16*)sourcePointer) ; break ;
				case DT_DOUBLE_WORD: *((UINT16*)destinationPointer) = *((UINT32*)sourcePointer) ; break ;
				// !!! This one is interesting too - shifter limiter action !!!
				case DT_LONG_WORD:   *((UINT16*)destinationPointer) = *((UINT64*)sourcePointer) ; break ;
			}
		break ;

		case DT_DOUBLE_WORD:
			switch(sourceType)
			{
				case DT_BYTE:        *((UINT32*)destinationPointer) = *((UINT8*) sourcePointer) ; break ;
				case DT_WORD:        *((UINT32*)destinationPointer) = *((UINT16*)sourcePointer) ; break ;
				case DT_DOUBLE_WORD: *((UINT32*)destinationPointer) = *((UINT32*)sourcePointer) ; break ;
				case DT_LONG_WORD:   *((UINT32*)destinationPointer) = *((UINT64*)sourcePointer) ; break ;
			}
		break ;

		case DT_LONG_WORD:
			switch(sourceType)
			{
				case DT_BYTE:        *((UINT64*)destinationPointer) = *((UINT8*) sourcePointer) ; break ;

				// !!! sign extending works on intel, others ???
                // !!! Need to check the shift limiter here too !!!
				case DT_WORD:        destinationValue = (*((INT16*)sourcePointer)) << 16 ;		  // Insure sign extending
									 destinationValue &= (UINT64)U64(0x000000ffffff0000) ;
									 *((UINT64*)destinationPointer) = destinationValue ;		  break ;

				case DT_DOUBLE_WORD: *((UINT64*)destinationPointer) = *((UINT32*)sourcePointer) ; break ;
				case DT_LONG_WORD:   *((UINT64*)destinationPointer) = *((UINT64*)sourcePointer) ; break ;
			}
		break ;
	}
}

// !! redundant functions (data and memory) can be handled with function pointers !!
static void SetDataMemoryValue(void *sourcePointer, unsigned char sourceType, UINT32 destinationAddr)
{
	// mame_printf_debug("%d %x\n", sourceType, destinationAddr) ;

	// I wonder if this is how this should be done???
	switch(sourceType)
	{
		case DT_BYTE:        data_write_word_16le(destinationAddr, (UINT16)( (*((UINT8*) sourcePointer) & 0xff)               ) ) ; break ;
		case DT_WORD:        data_write_word_16le(destinationAddr, (UINT16)( (*((UINT16*)sourcePointer) & 0xffff)             ) ) ; break ;
		case DT_DOUBLE_WORD: data_write_word_16le(destinationAddr, (UINT16)( (*((UINT32*)sourcePointer) & 0x0000ffff)         ) ) ; break ;

		// !!! Is this universal ???
		// !!! Forget not, yon shift-limiter !!!
		case DT_LONG_WORD:   data_write_word_16le(destinationAddr, (UINT16)( ((*((UINT64*)sourcePointer)) & (UINT64)U64(0x00000000ffff0000)) >> 16) ) ; break ;
	}
}

static void SetProgramMemoryValue(void *sourcePointer, unsigned char sourceType, UINT32 destinationAddr)
{
	// I wonder if this is how this should be done???
	switch(sourceType)
	{
		case DT_BYTE:        program_write_word_16le(destinationAddr, (UINT16)( (*((UINT8*) sourcePointer) & 0xff)               ) ) ; break ;
		case DT_WORD:        program_write_word_16le(destinationAddr, (UINT16)( (*((UINT16*)sourcePointer) & 0xffff)             ) ) ; break ;
		case DT_DOUBLE_WORD: program_write_word_16le(destinationAddr, (UINT16)( (*((UINT32*)sourcePointer) & 0x0000ffff)         ) ) ; break ;

		// !!! Is this universal ???
		// !!! Forget not, yon shift-limiter !!!
		case DT_LONG_WORD:   program_write_word_16le(destinationAddr, (UINT16)( ((*((UINT64*)sourcePointer)) & (UINT64)U64(0x00000000ffff0000)) >> 16) ) ; break ;
	}
}