File: ROMStubs.cpp

package info (click to toggle)
pose 3.5-1
  • links: PTS
  • area: contrib
  • in suites: woody
  • size: 13,108 kB
  • ctags: 29,485
  • sloc: cpp: 93,990; ansic: 62,838; sh: 1,970; perl: 1,891; python: 1,242; makefile: 616
file content (3220 lines) | stat: -rw-r--r-- 80,600 bytes parent folder | download | duplicates (3)
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
/* -*- mode: C++; tab-width: 4 -*- */
/* ===================================================================== *\
	Copyright (c) 1998-2001 Palm, Inc. or its subsidiaries.
	All rights reserved.

	This file is part of the Palm OS Emulator.

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.
\* ===================================================================== */

#include "EmCommon.h"
#include "ROMStubs.h"

#include "EmBankMapped.h"		// EmBankMapped::GetEmulatedAddress
#include "EmSubroutine.h"		// EmSubroutine
#include "Marshal.h"			// CALLER_PUT_PARAM_VAL
#include "Miscellaneous.h"		// StMemoryMapper


#pragma mark -

// ---------------------------------------------------------------------------
//		 Clipboard Manager functions
// ---------------------------------------------------------------------------

// --------------------
// Called:
//
//	*	trap patches that keep the Palm Clipboard in sync with the host clipboard.
// --------------------

void ClipboardAddItem (const ClipboardFormatType format, const void* ptr, UInt16 length)
{
	// Prepare the stack.
	CALLER_SETUP ("void", "const ClipboardFormatType format, const void* ptr, UInt16 length");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (ClipboardFormatType, format);
	CALLER_PUT_PARAM_PTR (void, ptr, length, Marshal::kInput);
	CALLER_PUT_PARAM_VAL (UInt16, length);

	// Call the function.
	sub.Call (sysTrapClipboardAddItem);

	// Write back any "by ref" parameters.

	// Return the result.
}

// --------------------
// Called:
//
//	*	trap patches that keep the Palm Clipboard in sync with the host clipboard.
// --------------------

MemHandle ClipboardGetItem (const ClipboardFormatType format, UInt16* length)
{
	// Prepare the stack.
	CALLER_SETUP ("MemHandle", "const ClipboardFormatType format, UInt16* length");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (ClipboardFormatType, format);
	CALLER_PUT_PARAM_REF (UInt16, length, Marshal::kInOut);

	// Call the function.
	sub.Call (sysTrapClipboardGetItem);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (length);

	// Return the result.
	RETURN_RESULT_PTR (MemHandle);
}

#pragma mark -

// ---------------------------------------------------------------------------
//		 Control Manager functions
// ---------------------------------------------------------------------------

// ---------------------------------------------------------------------------
//		 CtlGetLabel, used in Minimization
// ---------------------------------------------------------------------------

const Char* CtlGetLabel (const ControlType *controlP)
{
	// Prepare the stack.
	CALLER_SETUP ("const Char *", "const ControlType *controlP");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (ControlType*, controlP);

	// Call the function.
	sub.Call (sysTrapCtlGetLabel);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (const Char*);
}

#pragma mark -

// ---------------------------------------------------------------------------
//		 Desktop Link Server functions
// ---------------------------------------------------------------------------

// --------------------
// Called:
//
//	*	by SetHotSyncUserName when the user name needs to be set (during
//		boot-up, after a .psf file has been loaded, and after the preferences
//		have changed.
// --------------------

Err DlkDispatchRequest (DlkServerSessionPtr sessP)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "DlkServerSessionType* sessP");

	// Set the parameters.
	CALLER_PUT_PARAM_REF (DlkServerSessionType, sessP, Marshal::kInput);

	// Call the function.
	sub.Call (sysTrapDlkDispatchRequest);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called
//
//	*	in Patches::PostLoad to get the user name so that it
//		can be used to establish the preference setting.
// --------------------

Err DlkGetSyncInfo (UInt32* succSyncDateP, UInt32* lastSyncDateP,
			DlkSyncStateType* syncStateP, Char* nameBufP,
			Char* logBufP, Int32* logLenP)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", 
		"UInt32* succSyncDateP, UInt32* lastSyncDateP,"
		"DlkSyncStateType* syncStateP, Char* nameBufP,"
		"Char* logBufP, Int32* logLenP");

	// Set the parameters.
	Int32	logLen = logLenP ? *logLenP : 0;

	CALLER_PUT_PARAM_REF (UInt32, succSyncDateP, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (UInt32, lastSyncDateP, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (DlkSyncStateType, syncStateP, Marshal::kInOut);
	CALLER_PUT_PARAM_PTR (Char, nameBufP, dlkUserNameBufSize, Marshal::kInOut);
	CALLER_PUT_PARAM_PTR (Char, logBufP, logLen, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (Int32, logLenP, Marshal::kInOut);

	// Call the function.
	sub.Call (sysTrapDlkGetSyncInfo);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (succSyncDateP);
	CALLER_GET_PARAM_REF (lastSyncDateP);
	CALLER_GET_PARAM_REF (syncStateP);
	CALLER_GET_PARAM_REF (logLenP);

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

#pragma mark -

// ---------------------------------------------------------------------------
//		 Data Manager functions
// ---------------------------------------------------------------------------

// --------------------
// Called:
//
//	*	from My_DmCreateDatabaseFromImage after a database was successfully
//		installed, or after an error occurs (different code paths).  This
//		function is called any time a .prc, .pdb, or .pqa file is installed.
//
//	*	from My_ShlExportAsPilotFile (same comments)
//
//	*	from AppGetExtraInfo after opening a resource database to get its name.
//		This function is called any time a list of databases is needed (for
//		example, in the New Gremlin and Export Database dialogs).
//
//	*	while booting up (InstallCalibrationInfo) or starting a Gremlin
//		(ResetCalibrationInfo) as part of the process of setting the
//		calibration info to an identity state.
// --------------------

Err DmCloseDatabase (DmOpenRef dbR)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "DmOpenRef dbR");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (DmOpenRef, dbR);

	// Call the function.
	sub.Call (sysTrapDmCloseDatabase);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called
//
//	*	from My_DmCreateDatabaseFromImage.  This function is called any
//		time a .prc, .pdb, or .pqa file is installed.
// --------------------

Err DmCreateDatabase (UInt16 cardNo, const Char * const nameP, 
					UInt32 creator, UInt32 type, Boolean resDB)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "UInt16 cardNo, const Char * const nameP, "
					"UInt32 creator, UInt32 type, Boolean resDB");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (UInt16, cardNo);
	CALLER_PUT_PARAM_STR (Char, nameP);
	CALLER_PUT_PARAM_VAL (UInt32, creator);
	CALLER_PUT_PARAM_VAL (UInt32, type);
	CALLER_PUT_PARAM_VAL (Boolean, resDB);

	// Call the function.
	sub.Call (sysTrapDmCreateDatabase);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	when exporting a database (first to generate the list of databases
//		that can be exported, then again to later determine if the
//		database is a resource database or not).
//
//	*	when we need to switch to another application.  Mostly called when
//		starting a Gremlin on a particular application.
//
//	*	after an application has been launched, in order to collect information
//		on that application for later error reporting.
// --------------------

Err DmDatabaseInfo (UInt16 cardNo, LocalID	dbID, Char* nameP,
					UInt16* attributesP, UInt16* versionP, UInt32* crDateP,
					UInt32* modDateP, UInt32* bckUpDateP,
					UInt32* modNumP, LocalID* appInfoIDP,
					LocalID* sortInfoIDP, UInt32* typeP,
					UInt32* creatorP)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", 
					"UInt16 cardNo, LocalID	dbID, Char* nameP,"
					"UInt16* attributesP, UInt16* versionP, UInt32* crDateP,"
					"UInt32* modDateP, UInt32* bckUpDateP,"
					"UInt32* modNumP, LocalID* appInfoIDP,"
					"LocalID* sortInfoIDP, UInt32* typeP,"
					"UInt32* creatorP");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (UInt16, cardNo);
	CALLER_PUT_PARAM_VAL (LocalID, dbID);
	CALLER_PUT_PARAM_PTR (Char, nameP, dmDBNameLength, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (UInt16, attributesP, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (UInt16, versionP, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (UInt32, crDateP, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (UInt32, modDateP, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (UInt32, bckUpDateP, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (UInt32, modNumP, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (LocalID, appInfoIDP, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (LocalID, sortInfoIDP, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (UInt32, typeP, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (UInt32, creatorP, Marshal::kInOut);

	// Call the function.
	sub.Call (sysTrapDmDatabaseInfo);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (attributesP);
	CALLER_GET_PARAM_REF (versionP);
	CALLER_GET_PARAM_REF (crDateP);
	CALLER_GET_PARAM_REF (modDateP);
	CALLER_GET_PARAM_REF (bckUpDateP);
	CALLER_GET_PARAM_REF (modNumP);
	CALLER_GET_PARAM_REF (appInfoIDP);
	CALLER_GET_PARAM_REF (sortInfoIDP);
	CALLER_GET_PARAM_REF (typeP);
	CALLER_GET_PARAM_REF (creatorP);

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	from LoadPalmFile to delete a previous version of a database
//		that we're trying to install.
//
//	*	from My_DmCreateDatabaseFromImage if the attempt to install a
//		database fails.
// --------------------

Err DmDeleteDatabase (UInt16 cardNo, LocalID dbID)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "UInt16 cardNo, LocalID dbID");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (UInt16, cardNo);
	CALLER_PUT_PARAM_VAL (LocalID, dbID);

	// Call the function.
	sub.Call (sysTrapDmDeleteDatabase);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	by the application install code (My_DmCreateDatabaseFromImage)
//		in order to get the dbID of the database it just created.
//
//	*	by the application install code (LoadPalmFile) to determine
//		if there's a previous instance of the application that needs
//		to be deleted.
//
//	*	by the application export code (My_ShlExportAsPilotFile) to find
//		the database to be exported.
//
//	*	by code that switches to an application installed from the
//		AutoRun directory.
// --------------------

LocalID DmFindDatabase (UInt16 cardNo, const Char* nameP)
{
	// Prepare the stack.
	CALLER_SETUP ("LocalID", "UInt16 cardNo, const Char* nameP");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (UInt16, cardNo);
	CALLER_PUT_PARAM_STR (Char, nameP);

	// Call the function.
	sub.Call (sysTrapDmFindDatabase);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (LocalID);
}

// --------------------
// Called:
//
//	*	by AppGetExtraInfo to get the 'tAIN' resource.
//
//	*	by CollectCurrentAppInfo to get the 'tAIN' and 'tver' resources.
// --------------------

MemHandle DmGet1Resource (DmResType type, DmResID id)
{
	// Prepare the stack.
	CALLER_SETUP ("MemHandle", "DmResType type, DmResID id");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (DmResType, type);
	CALLER_PUT_PARAM_VAL (DmResID, id);

	// Call the function.
	sub.Call (sysTrapDmGet1Resource);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (MemHandle);
}

// --------------------
// Called:
//
//	*	by GetDatabases when iterating over all the databases in the system.
//		Called when generating a list of databases to display (e.g.,
//		in the New Gremlin and Export Database dialogs).
// --------------------

LocalID DmGetDatabase (UInt16 cardNo, UInt16 index)
{
	// Prepare the stack.
	CALLER_SETUP ("LocalID", "UInt16 cardNo, UInt16 index");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (UInt16, cardNo);
	CALLER_PUT_PARAM_VAL (UInt16, index);

	// Call the function.
	sub.Call (sysTrapDmGetDatabase);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (LocalID);
}

// --------------------
// Called:
//
//	*	by the application export code (My_ShlExportAsPilotFile) when failing
//		to find or open the requested database.
//
//	*	AppGetExtraInfo when failing to open an application database in
//		order to get its name.
// --------------------

Err DmGetLastErr (void)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "void");

	// Set the parameters.

	// Call the function.
	sub.Call (sysTrapDmGetLastErr);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	by Gremlins (Gremlins::New) when it needs to find the application
//		responsible for a "runnable" database.
//
//	*	same comments for Patches::SwitchToApp.
// --------------------

Err	DmGetNextDatabaseByTypeCreator (Boolean newSearch, DmSearchStatePtr stateInfoP,
			 		UInt32 type, UInt32 creator, Boolean onlyLatestVers, 
			 		UInt16* cardNoP, LocalID* dbIDP)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", 
		"Boolean newSearch, DmSearchStatePtr stateInfoP, "
		"UInt32 type, UInt32 creator, Boolean onlyLatestVers, "
		"UInt16* cardNoP, LocalID* dbIDP");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (Boolean, newSearch);
	CALLER_PUT_PARAM_REF (DmSearchStateType, stateInfoP, Marshal::kInOut);
	CALLER_PUT_PARAM_VAL (UInt32, type);
	CALLER_PUT_PARAM_VAL (UInt32, creator);
	CALLER_PUT_PARAM_VAL (Boolean, onlyLatestVers);
	CALLER_PUT_PARAM_REF (UInt16, cardNoP, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (LocalID, dbIDP, Marshal::kInOut);

	// Call the function.
	sub.Call (sysTrapDmGetNextDatabaseByTypeCreator);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (stateInfoP);
	CALLER_GET_PARAM_REF (cardNoP);
	CALLER_GET_PARAM_REF (dbIDP);

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	while booting up (InstallCalibrationInfo) or starting a Gremlin
//		(ResetCalibrationInfo) as part of the process of setting the
//		calibration info to an identity state.
// --------------------

MemHandle DmGetResource (DmResType type, DmResID id)
{
	// Prepare the stack.
	CALLER_SETUP ("MemHandle", "DmResType type, DmResID id");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (DmResType, type);
	CALLER_PUT_PARAM_VAL (DmResID, id);

	// Call the function.
	sub.Call (sysTrapDmGetResource);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (MemHandle);
}

// --------------------
// Called:
//
//	*	by the application export code (My_ShlExportAsPilotFile)
//		when iterating over all the resources.
// --------------------

MemHandle DmGetResourceIndex (DmOpenRef dbP, UInt16 index)
{
	// Prepare the stack.
	CALLER_SETUP ("MemHandle", "DmOpenRef dbP, UInt16 index");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (DmOpenRef, dbP);
	CALLER_PUT_PARAM_VAL (UInt16, index);

	// Call the function.
	sub.Call (sysTrapDmGetResourceIndex);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (MemHandle);
}

// --------------------
// Called:
//
//	*	by the application install code (My_DmCreateDatabaseFromImage)
//		to create an app info block.
// --------------------

MemHandle DmNewHandle (DmOpenRef dbR, UInt32 size)
{
	// Prepare the stack.
	CALLER_SETUP ("MemHandle", "DmOpenRef dbR, UInt32 size");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (DmOpenRef, dbR);
	CALLER_PUT_PARAM_VAL (UInt32, size);

	// Call the function.
	sub.Call (sysTrapDmNewHandle);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (MemHandle);
}

// --------------------
// Called:
//
//	*	by the application install code (My_DmCreateDatabaseFromImage)
//		to create new records.
// --------------------

MemHandle DmNewRecord (DmOpenRef dbR, UInt16* atP, UInt32 size)
{
	// Prepare the stack.
	CALLER_SETUP ("MemHandle", "DmOpenRef dbR, UInt16* atP, UInt32 size");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (DmOpenRef, dbR);
	CALLER_PUT_PARAM_REF (UInt16, atP, Marshal::kInOut);
	CALLER_PUT_PARAM_VAL (UInt32, size);

	// Call the function.
	sub.Call (sysTrapDmNewRecord);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (atP);

	// Return the result.
	RETURN_RESULT_PTR (MemHandle);
}

// --------------------
// Called:
//
//	*	by the application install code (My_DmCreateDatabaseFromImage)
//		to create new resources.
//
//	*	while booting up (InstallCalibrationInfo)  as part of the process
//		of setting the calibration info to an identity state.
// --------------------

MemHandle DmNewResource (DmOpenRef dbR, DmResType resType, DmResID resID, UInt32 size)
{
	// Prepare the stack.
	CALLER_SETUP ("MemHandle", "DmOpenRef dbR, DmResType resType, DmResID resID, UInt32 size");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (DmOpenRef, dbR);
	CALLER_PUT_PARAM_VAL (DmResType, resType);
	CALLER_PUT_PARAM_VAL (DmResID, resID);
	CALLER_PUT_PARAM_VAL (UInt32, size);

	// Call the function.
	sub.Call (sysTrapDmNewResource);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (MemHandle);
}

// --------------------
// Called:
//
//	*	.
// --------------------

DmOpenRef DmNextOpenDatabase (DmOpenRef currentP)
{
	// Prepare the stack.
	CALLER_SETUP ("DmOpenRef", "DmOpenRef currentP");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (DmOpenRef, currentP);

	// Call the function.
	sub.Call (sysTrapDmNextOpenDatabase);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (DmOpenRef);
}

// --------------------
// Called:
//
//	*	when iterating over all databases in the system (GetDatabases).
//		Called when generating a list of databases to display (e.g.,
//		in the New Gremlin and Export Database dialogs).
// --------------------

UInt16 DmNumDatabases (UInt16 cardNo)
{
	// Prepare the stack.
	CALLER_SETUP ("UInt16", "UInt16 cardNo");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (UInt16, cardNo);

	// Call the function.
	sub.Call (sysTrapDmNumDatabases);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (UInt16);
}

// --------------------
// Called:
//
//	*	by the application export code (My_ShlExportAsPilotFile)
//		in order to loop over all the records/resources in a database.
// --------------------

UInt16 DmNumRecords (DmOpenRef dbP)
{
	// Prepare the stack.
	CALLER_SETUP ("UInt16", "DmOpenRef dbP");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (DmOpenRef, dbP);

	// Call the function.
	sub.Call (sysTrapDmNumRecords);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (UInt16);
}

// --------------------
// Called:
//
//	*	.
// --------------------
UInt16 DmNumResources (DmOpenRef dbP)
{
	// Prepare the stack.
	CALLER_SETUP ("UInt16", "DmOpenRef dbP");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (DmOpenRef, dbP);

	// Call the function.
	sub.Call (sysTrapDmNumResources);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (UInt16);
}

// --------------------
// Called:
//
//	*	by the application install code (My_DmCreateDatabaseFromImage)
//		so that new records/resources can be added to the new database.
//
//	*	by the application export code (My_ShlExportAsPilotFile)
//		so that records/resources can be retrieved and written out.
//
//	*	by AppGetExtraInfo to get information out of an application's
//		'tAIN' resource.
// --------------------

DmOpenRef DmOpenDatabase (UInt16 cardNo, LocalID dbID, UInt16 mode)
{
	// Prepare the stack.
	CALLER_SETUP ("DmOpenRef", "UInt16 cardNo, LocalID dbID, UInt16 mode");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (UInt16, cardNo);
	CALLER_PUT_PARAM_VAL (LocalID, dbID);
	CALLER_PUT_PARAM_VAL (UInt16, mode);

	// Call the function.
	sub.Call (sysTrapDmOpenDatabase);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (DmOpenRef);
}

// --------------------
// Called:
//
//	*	after an application has been launched (CollectCurrentAppInfo)
//		to get the app's dbID and card number.
// --------------------

Err DmOpenDatabaseInfo (DmOpenRef dbP, LocalID* dbIDP, 
					UInt16* openCountP, UInt16* modeP, UInt16* cardNoP,
					Boolean* resDBP)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", 
		"DmOpenRef dbP, LocalID* dbIDP, "
		"UInt16* openCountP, UInt16* modeP, UInt16* cardNoP,"
		"Boolean* resDBP");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (DmOpenRef, dbP);
	CALLER_PUT_PARAM_REF (LocalID, dbIDP, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (UInt16, openCountP, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (UInt16, modeP, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (UInt16, cardNoP, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (Boolean, resDBP, Marshal::kInOut);

	// Call the function.
	sub.Call (sysTrapDmOpenDatabaseInfo);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (dbIDP);
	CALLER_GET_PARAM_REF (openCountP);
	CALLER_GET_PARAM_REF (modeP);
	CALLER_GET_PARAM_REF (cardNoP);
	CALLER_GET_PARAM_REF (resDBP);

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	by the application export code (My_ShlExportAsPilotFile) in order
//		to get information about exported records.
// --------------------

Err DmRecordInfo (DmOpenRef dbP, UInt16 index,
					UInt16* attrP, UInt32* uniqueIDP, LocalID* chunkIDP)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", 
		"DmOpenRef dbP, UInt16 index,"
		"UInt16* attrP, UInt32* uniqueIDP, LocalID* chunkIDP");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (DmOpenRef, dbP);
	CALLER_PUT_PARAM_VAL (UInt16, index);
	CALLER_PUT_PARAM_REF (UInt16, attrP, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (UInt32, uniqueIDP, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (LocalID, chunkIDP, Marshal::kInOut);

	// Call the function.
	sub.Call (sysTrapDmRecordInfo);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (attrP);
	CALLER_GET_PARAM_REF (uniqueIDP);
	CALLER_GET_PARAM_REF (chunkIDP);

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	by the application install code (My_DmCreateDatabaseFromImage) to release
//		records created by DmNewRecord.
// --------------------

Err DmReleaseRecord (DmOpenRef dbR, UInt16 index, Boolean dirty)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "DmOpenRef dbR, UInt16 index, Boolean dirty");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (DmOpenRef, dbR);
	CALLER_PUT_PARAM_VAL (UInt16, index);
	CALLER_PUT_PARAM_VAL (Boolean, dirty);

	// Call the function.
	sub.Call (sysTrapDmReleaseRecord);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	by all code that calls DmNewResource, DmGet1Resource, DmGetResource,
//		DmGetResourceIndex, etc.
// --------------------

Err DmReleaseResource (MemHandle resourceH)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "MemHandle resourceH");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (MemHandle, resourceH);

	// Call the function.
	sub.Call (sysTrapDmReleaseResource);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	by application export code (My_ShlExportAsPilotFile) to get
//		information about the resources being written out.
// --------------------

Err DmResourceInfo (DmOpenRef dbP, UInt16 index,
					DmResType* resTypeP, DmResID* resIDP,  
					LocalID* chunkLocalIDP)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", 
		"DmOpenRef dbP, UInt16 index,"
		"DmResType* resTypeP, DmResID* resIDP,"
		"LocalID* chunkLocalIDP");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (DmOpenRef, dbP);
	CALLER_PUT_PARAM_VAL (UInt16, index);
	CALLER_PUT_PARAM_REF (DmResType, resTypeP, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (DmResID, resIDP, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (LocalID, chunkLocalIDP, Marshal::kInOut);

	// Call the function.
	sub.Call (sysTrapDmResourceInfo);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (resTypeP);
	CALLER_GET_PARAM_REF (resIDP);
	CALLER_GET_PARAM_REF (chunkLocalIDP);

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	by application export code (My_ShlExportAsPilotFile) to get
//		information about the records being written out.
// --------------------

MemHandle DmQueryRecord (DmOpenRef dbP, UInt16 index)
{
	// Prepare the stack.
	CALLER_SETUP ("MemHandle", "DmOpenRef dbP, UInt16 index");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (DmOpenRef, dbP);
	CALLER_PUT_PARAM_VAL (UInt16, index);

	// Call the function.
	sub.Call (sysTrapDmQueryRecord);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (MemHandle);
}

// --------------------
// Called:
//
//	*	by application install code (My_DmCreateDatabaseFromImage) to
//		set the attributes of newly-created databases.
// --------------------

Err DmSetDatabaseInfo (UInt16 cardNo, LocalID dbID, const Char* nameP,
					UInt16* attributesP, UInt16* versionP, UInt32* crDateP,
					UInt32* modDateP, UInt32* bckUpDateP,
					UInt32* modNumP, LocalID* appInfoIDP,
					LocalID* sortInfoIDP, UInt32* typeP,
					UInt32* creatorP)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", 
		"UInt16 cardNo, LocalID dbID, const Char* nameP,"
		"UInt16* attributesP, UInt16* versionP, UInt32* crDateP,"
		"UInt32* modDateP, UInt32* bckUpDateP,"
		"UInt32* modNumP, LocalID* appInfoIDP,"
		"LocalID* sortInfoIDP, UInt32* typeP,"
		"UInt32* creatorP");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (UInt16, cardNo);
	CALLER_PUT_PARAM_VAL (LocalID, dbID);
	CALLER_PUT_PARAM_STR (Char, nameP);
	CALLER_PUT_PARAM_REF (UInt16, attributesP, Marshal::kInput);
	CALLER_PUT_PARAM_REF (UInt16, versionP, Marshal::kInput);
	CALLER_PUT_PARAM_REF (UInt32, crDateP, Marshal::kInput);
	CALLER_PUT_PARAM_REF (UInt32, modDateP, Marshal::kInput);
	CALLER_PUT_PARAM_REF (UInt32, bckUpDateP, Marshal::kInput);
	CALLER_PUT_PARAM_REF (UInt32, modNumP, Marshal::kInput);
	CALLER_PUT_PARAM_REF (LocalID, appInfoIDP, Marshal::kInput);
	CALLER_PUT_PARAM_REF (LocalID, sortInfoIDP, Marshal::kInput);
	CALLER_PUT_PARAM_REF (UInt32, typeP, Marshal::kInput);
	CALLER_PUT_PARAM_REF (UInt32, creatorP, Marshal::kInput);

	// Call the function.
	sub.Call (sysTrapDmSetDatabaseInfo);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	by application install code (My_DmCreateDatabaseFromImage) to
//		set the attributes of newly-created records.
// --------------------

Err DmSetRecordInfo (DmOpenRef dbR, UInt16 index, UInt16* attrP, UInt32* uniqueIDP)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "DmOpenRef dbR, UInt16 index, UInt16* attrP, UInt32* uniqueIDP");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (DmOpenRef, dbR);
	CALLER_PUT_PARAM_VAL (UInt16, index);
	CALLER_PUT_PARAM_REF (UInt16, attrP, Marshal::kInput);
	CALLER_PUT_PARAM_REF (UInt32, uniqueIDP, Marshal::kInput);

	// Call the function.
	sub.Call (sysTrapDmSetRecordInfo);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	by application install code (My_DmCreateDatabaseFromImage) to
//		copy data into the newly-created records and resources.
//
//	*	while booting up (InstallCalibrationInfo) as part of the process
//		of setting the calibration info to an identity state.
// --------------------

Err DmWrite (MemPtr recordP, UInt32 offset, const void * const srcP, UInt32 bytes)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "MemPtr recordP, UInt32 offset, const void * const srcP, UInt32 bytes");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (MemPtr, recordP);
	CALLER_PUT_PARAM_VAL (UInt32, offset);
	CALLER_PUT_PARAM_PTR (void, srcP, bytes, Marshal::kInput);
	CALLER_PUT_PARAM_VAL (UInt32, bytes);

	// Call the function.
	sub.Call (sysTrapDmWrite);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

#pragma mark -

// ---------------------------------------------------------------------------
//		 Event Manager functions
// ---------------------------------------------------------------------------

// --------------------
// Called:
//
//	*	by Gremlins app switch code to insert an app stop event
// --------------------

void EvtAddEventToQueue (EventType* event)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "EventType* event");

	// Set the parameters.
	CALLER_PUT_PARAM_REF (EventType, event, Marshal::kInput);

	// Call the function.
	sub.Call (sysTrapEvtAddEventToQueue);

	// Write back any "by ref" parameters.

	// Return the result.
}

// --------------------
// Called:
//
//	*	by Gremlins and key event insertion code (StubAppEnqueueKey) to
//		insert a key event.
// --------------------

Err EvtEnqueueKey (UInt16 ascii, UInt16 keycode, UInt16 modifiers)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "UInt16 ascii, UInt16 keycode, UInt16 modifiers");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (UInt16, ascii);
	CALLER_PUT_PARAM_VAL (UInt16, keycode);
	CALLER_PUT_PARAM_VAL (UInt16, modifiers);

	// Call the function.
	sub.Call (sysTrapEvtEnqueueKey);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	by Gremlins and pen event insertion code (StubEnqueuePt) to
//		insert a pen event.
// --------------------

Err EvtEnqueuePenPoint (PointType* ptP)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "PointType* ptP");

	// Set the parameters.
	CALLER_PUT_PARAM_REF (PointType, ptP, Marshal::kInput);

	// Call the function.
	sub.Call (sysTrapEvtEnqueuePenPoint);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	by Gremlins code (FakeEventXY) in order to target silkscreen buttons.
// --------------------

const PenBtnInfoType*	EvtGetPenBtnList(UInt16* numButtons)
{
	// Prepare the stack.
	CALLER_SETUP ("const PenBtnInfoType*", "UInt16* numButtons");

	// Set the parameters.
	CALLER_PUT_PARAM_REF (UInt16, numButtons, Marshal::kOutput);

	// Call the function.
	sub.Call (sysTrapEvtGetPenBtnList);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (numButtons);

	// Return the result.
	RETURN_RESULT_PTR (const PenBtnInfoType*);
}

// --------------------
// Called:
//
//	*	by Gremlins code (Gremlins::GetFakeEvent) to make sure the device
//		doesn't fall asleep, even though Gremlins is pumping in key events.
// --------------------

Err EvtResetAutoOffTimer (void)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "void");

	// Set the parameters.

	// Call the function.
	sub.Call (sysTrapEvtResetAutoOffTimer);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	by Gremlin code (Gremlins::New, Gremlins::Resume, Hordes::Step) to
//		wake a device out of snooze mode or a call to EvtGetEvent with an
//		infinite timeout.
//
//	*	by pen and key event insertion code to wake a device out of snooze
//		mode or a call to EvtGetEvent with an infinite timeout.
//
//	*	by HostSignalWait if the caller is looking for an idle event.
// --------------------

Err EvtWakeup (void)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "void");

	// Set the parameters.

	// Call the function.
	sub.Call (sysTrapEvtWakeup);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Err);
}


#if 0
// ---------------------------------------------------------------------------
//		 Exchange Manager functions
// ---------------------------------------------------------------------------

#pragma mark -

typedef enum
{
	exgLibTrapHandleEvent = sysLibTrapCustom,
	exgLibTrapConnect,
	exgLibTrapAccept,
	exgLibTrapDisconnect,
	exgLibTrapPut,
	exgLibTrapGet,
	exgLibTrapSend,
	exgLibTrapReceive,
	exgLibTrapControl,	// <-- Needed for this
	exgLibReserved1,
	exgLibTrapLast
} ExgLibTrapNumberEnum;

Err 	ExgLibControl(UInt16 libRefNum, UInt16 op, void *valueP, UInt16 *valueLenP)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "UInt16 libRefNum, UInt16 op, emuptr valueP, emuptr valueLenP");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (UInt16, libRefNum);
	CALLER_PUT_PARAM_VAL (UInt16, op);
	CALLER_PUT_PARAM_VAL (emuptr, valueP);
	CALLER_PUT_PARAM_VAL (emuptr, valueLenP);

	sub.SetParamVal ("libRefNum", libRefNum);
	sub.SetParamVal ("op", op);
	sub.SetParamVal ("valueP", valueP);
	sub.SetParamVal ("valueLenP", valueLenP);

	sub.Call (exgLibTrapControl);

	Err result;
	sub.GetReturnVal (result);
	return result;
}
#endif

#pragma mark -

// ---------------------------------------------------------------------------
//		 Field Manager functions
// ---------------------------------------------------------------------------

// --------------------
// Called:
//
//	*	by Gremlin code (IsFocus, SpaceLeftInFocus) to see if a field
//		is editable.
// --------------------

void FldGetAttributes (const FieldType* fld, const FieldAttrPtr attrP)
{
	// Prepare the stack.
	CALLER_SETUP ("void", "const FieldType* fld, const FieldAttrPtr attrP");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (FieldType*, fld);
	CALLER_PUT_PARAM_REF (FieldAttrType, attrP, Marshal::kInOut);

	// Call the function.
	sub.Call (sysTrapFldGetAttributes);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (attrP);

	// Return the result.
}

// --------------------
// Called:
//
//	*	by EventOutput to try to find out where the gremlin tapped inside a field.
// --------------------

UInt16 FldGetInsPtPosition (const FieldType* fld)
{
	// Prepare the stack.
	CALLER_SETUP ("UInt16", "const FieldType* fld");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (FieldType*, fld);

	// Call the function.
	sub.Call (sysTrapFldGetInsPtPosition);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (UInt16);
}

// --------------------
// Called:
//
//	*	by Gremlin code (SpaceLeftInFocus) to determine if more characters
//		should be jammed into a field.
// --------------------

UInt16 FldGetMaxChars (const FieldType* fld)
{
	// Prepare the stack.
	CALLER_SETUP ("UInt16", "const FieldType* fld");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (FieldType*, fld);

	// Call the function.
	sub.Call (sysTrapFldGetMaxChars);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (UInt16);
}

// --------------------
// Called:
//
//	*	by Gremlin code (SpaceLeftInFocus) to determine if more characters
//		should be jammed into a field.
// --------------------

UInt16 FldGetTextLength (const FieldType* fld)
{
	// Prepare the stack.
	CALLER_SETUP ("UInt16", "const FieldType* fld");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (FieldType*, fld);

	// Call the function.
	sub.Call (sysTrapFldGetTextLength);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (UInt16);
}

// --------------------
// Called:
//
//	*	by Minimization code to get the text of a field to beautify the output.
// --------------------

Char* FldGetTextPtr (FieldType* fldP)
{
	// Prepare the stack.
	CALLER_SETUP ("Char*", "FieldType* fldP");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (FieldType*, fldP);

	// Call the function.
	sub.Call (sysTrapFldGetTextPtr);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (Char*);
}

#pragma mark -

// ---------------------------------------------------------------------------
//		 Font Manager functions
// ---------------------------------------------------------------------------

// --------------------
// Called:
//
//	*	by Gremlin code (FakeLocalMovement) to generate strokes based on
//		the font height.
// --------------------

Int16 FntLineHeight (void)
{
	// Prepare the stack.
	CALLER_SETUP ("Int16", "void");

	// Set the parameters.

	// Call the function.
	sub.Call (sysTrapFntLineHeight);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Int16);
}

// --------------------
// Called:
//
// --------------------

UInt8 FntSetFont (UInt8 fontId)
{
	// Prepare the stack.
	CALLER_SETUP ("UInt8", "UInt8 fontId");

	// Set the parameters.

	CALLER_PUT_PARAM_VAL (UInt8, fontId);

	// Call the function.
	sub.Call (sysTrapFntSetFont);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL(UInt8);
}

#pragma mark -

// ---------------------------------------------------------------------------
//		 Form Manager functions
// ---------------------------------------------------------------------------

// --------------------
// Called:
//
//	*	by Gremlin code (GetFocusObject) to determine if the active form
//		is the active window.
//
//	*	by Gremlin code (FakeEventXY) to see if there's a form that should
//		be targeted.
// --------------------

FormType* FrmGetActiveForm (void)
{
	// Prepare the stack.
	CALLER_SETUP ("FormType*", "void");

	// Set the parameters.

	// Call the function.
	sub.Call (sysTrapFrmGetActiveForm);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (FormType*);
}

// --------------------
// Called:
//
//	*	by Gremlin code (GetFocusObject) when trying to determine the
//		object that has the focus and that should get preferred attention.
// --------------------

UInt16 FrmGetFocus (const FormType* frm)
{
	// Prepare the stack.
	CALLER_SETUP ("UInt16", "const FormType* frm");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (FormType*, frm);

	// Call the function.
	sub.Call (sysTrapFrmGetFocus);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (UInt16);
}

// --------------------
// Called:
//
//	*	EmEventOutput::GetEventInfo
// --------------------

UInt16 FrmGetFormId (const FormType* frm)
{
	// Prepare the stack.
	CALLER_SETUP ("UInt16", "const FormType* frm");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (FormType*, frm);

	// Call the function.
	sub.Call (sysTrapFrmGetFormId);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (UInt16);
}

// --------------------
// Called:
//
//	*	by Gremlin code (CollectOKObjects) in order to iterate over
//		all the objects in a form.
// --------------------

UInt16 FrmGetNumberOfObjects (const FormType* frm)
{
	// Prepare the stack.
	CALLER_SETUP ("UInt16", "const FormType* frm");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (FormType*, frm);

	// Call the function.
	sub.Call (sysTrapFrmGetNumberOfObjects);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (UInt16);
}

// --------------------
// Called:
//
//	*	by Gremlin code (FakeEventXY) to generate a random point within
//		a form object.
//
//	*	by Gremlin code (CollectOKObjects) to get the bounds of an object
//		for validation.
// --------------------

void FrmGetObjectBounds (const FormType* frm, const UInt16 pObjIndex, const RectanglePtr r)
{
	// Prepare the stack.
	CALLER_SETUP ("void", "const FormType* frm, const UInt16 pObjIndex, const RectanglePtr r");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (FormType*, frm);
	CALLER_PUT_PARAM_VAL (UInt16, pObjIndex);
	CALLER_PUT_PARAM_REF (RectangleType, r, Marshal::kInOut);

	// Call the function.
	sub.Call (sysTrapFrmGetObjectBounds);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (r);

	// Return the result.
}

// --------------------
// Called:
//
//	*	by Gremlin code (CollectOKObjects) to get the ID of an object
//		for use in any error messages that might occur.
// --------------------

UInt16 FrmGetObjectId (const FormType* frm, const UInt16 objIndex)
{
	// Prepare the stack.
	CALLER_SETUP ("UInt16", "const FormType* frm, const UInt16 objIndex");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (FormType*, frm);
	CALLER_PUT_PARAM_VAL (UInt16, objIndex);

	// Call the function.
	sub.Call (sysTrapFrmGetObjectId);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (UInt16);
}

// --------------------
// Called:
//
//	*	by minimization code, when replaying the events the final time,
//		in order to grab the control names.
// --------------------

UInt16 FrmGetObjectIndex (const FormType* formP, UInt16 objID)
{
	// Prepare the stack.
	CALLER_SETUP ("UInt16", "const FormType* formP, UInt16 objID");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (FormType*, formP);
	CALLER_PUT_PARAM_VAL (UInt16, objID);

	// Call the function.
	sub.Call (sysTrapFrmGetObjectIndex);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (UInt16);
}

// --------------------
// Called:
//
//	*	by Gremlin code (GetFocusObject) to get a pointer to a table object
//		so that we can call TblGetCurrentField on it.
//
//	*	by Gremlin code (CollectOKObjects) to get a pointer to control
//		and list objects so that we can validate them.
// --------------------

MemPtr FrmGetObjectPtr (const FormType* frm, const UInt16 objIndex)
{
	// Prepare the stack.
	CALLER_SETUP ("MemPtr", "const FormType* frm, const UInt16 objIndex");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (FormType*, frm);
	CALLER_PUT_PARAM_VAL (UInt16, objIndex);

	// Call the function.
	sub.Call (sysTrapFrmGetObjectPtr);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (MemPtr);
}

// --------------------
// Called:
//
//	*	by Gremlin code (GetFocusObject) to see if the focussed object
//		is a table that might have an embedded field.
//
//	*	by Gremlin code (CollectOKObjects) to see if the object we're
//		iterating over is one that we'd like to emulate a tap on.
// --------------------

FormObjectKind FrmGetObjectType (const FormType* frm, const UInt16 objIndex)
{
	// Prepare the stack.
	CALLER_SETUP ("FormObjectKind", "const FormType* frm, const UInt16 objIndex");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (FormType*, frm);
	CALLER_PUT_PARAM_VAL (UInt16, objIndex);

	// Call the function.
	sub.Call (sysTrapFrmGetObjectType);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (FormObjectKind);
}

// --------------------
// Called:
//
//	*	by logging code (StubEmFrmGetTitle) to get the form's title.
// --------------------

const Char* FrmGetTitle (const FormType* frm)
{
	// Prepare the stack.
	CALLER_SETUP ("const Char*", "const FormType* frm");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (FormType*, frm);

	// Call the function.
	sub.Call (sysTrapFrmGetTitle);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (const Char*);
}

// --------------------
// Called:
//
//	*	by Gremlin code (GetFocusObject, FakeEventXY) to determine if the active
//		form is the active window.
// --------------------

WinHandle FrmGetWindowHandle (const FormType* frm)
{
	// Prepare the stack.
	CALLER_SETUP ("WinHandle", "const FormType* frm");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (FormType*, frm);

	// Call the function.
	sub.Call (sysTrapFrmGetWindowHandle);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (WinHandle);
}

#pragma mark -

// ---------------------------------------------------------------------------
//		 File System functions
// ---------------------------------------------------------------------------

typedef enum {
	FSTrapLibAPIVersion = sysLibTrapCustom,
	FSTrapCustomControl,	// <-- Needed for this
	FSTrapFilesystemType,
	
	FSTrapFileCreate,
	FSTrapFileOpen,
	FSTrapFileClose,
	FSTrapFileRead,
	FSTrapFileWrite,
	FSTrapFileDelete,
	FSTrapFileRename,
	FSTrapFileSeek,
	FSTrapFileEOF,
	FSTrapFileTell,
	FSTrapFileResize,
	FSTrapFileAttributesGet,
	FSTrapFileAttributesSet,
	FSTrapFileDateGet,
	FSTrapFileDateSet,
	FSTrapFileSize,
	
	FSTrapDirCreate,
	FSTrapDirEntryEnumerate,
	
	FSTrapVolumeFormat,
	FSTrapVolumeMount,
	FSTrapVolumeUnmount,
	FSTrapVolumeInfo,
	FSTrapVolumeLabelGet,
	FSTrapVolumeLabelSet,
	FSTrapVolumeSize,
	
	FSMaxSelector = FSTrapVolumeSize,

	FSBigSelector = 0x7FFF	// Force FSLibSelector to be 16 bits.
} FSLibSelector;

Err FSCustomControl (UInt16 fsLibRefNum, UInt32 apiCreator, UInt16 apiSelector, 
					void *valueP, UInt16 *valueLenP)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", 
		"UInt16 fsLibRefNum, UInt32 apiCreator, UInt16 apiSelector, "
		"emuptr valueP, UInt16 *valueLenP");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (UInt16, fsLibRefNum);
	CALLER_PUT_PARAM_VAL (UInt32, apiCreator);
	CALLER_PUT_PARAM_VAL (UInt16, apiSelector);
	CALLER_PUT_PARAM_VAL (emuptr, valueP);		// !!! Only works for our mount/unmount calls!
	CALLER_PUT_PARAM_REF (UInt16, valueLenP, Marshal::kInOut);

	// Call the function.
	sub.Call (FSTrapCustomControl);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (valueLenP);

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

#pragma mark -

// ---------------------------------------------------------------------------
//		 Feature Manager functions
// ---------------------------------------------------------------------------

// --------------------
// Called:
//
//	*	by Gremlin code (IntlMgrExists) to see if the Intenational Manager
//		exists before trying to call it.
//
//	*	by Gremlin code (Gremlins::GetFakeEvent) to see what language system
//		we're using (so we know whether to use the English or Japanese quotes).
//
//	*	during bootup (patch on FtrInit) to get the ROM version.
// --------------------

Err FtrGet (UInt32 creator, UInt16 featureNum, UInt32* valueP)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "UInt32 creator, UInt16 featureNum, UInt32* valueP");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (UInt32, creator);
	CALLER_PUT_PARAM_VAL (UInt16, featureNum);
	CALLER_PUT_PARAM_REF (UInt32, valueP, Marshal::kInOut);

	// Call the function.
	sub.Call (sysTrapFtrGet);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (valueP);

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	to install the 'pose' feature after creating or loading a session.
//
//	*	by Poser's debugger handling code (Debug::EventCallback) after a
//		connection to an external debugger is established.
//
//	*	after creating a new session and we are currently connected to a debugger.
//
//	*	after reloading a .psf file and we are currently connected to a debugger.
// --------------------

Err FtrSet (UInt32 creator, UInt16 featureNum, UInt32 newValue)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "UInt32 creator, UInt16 featureNum, UInt32 newValue");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (UInt32, creator);
	CALLER_PUT_PARAM_VAL (UInt16, featureNum);
	CALLER_PUT_PARAM_VAL (UInt32, newValue);

	// Call the function.
	sub.Call (sysTrapFtrSet);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	by Poser's debugger handling code (Debug::EventCallback) when it
//		detects that the connection to an external debugger has been broken.
//
//	*	after reloading a .psf file and we are not currently connected to a debugger.
// --------------------

Err	FtrUnregister (UInt32 creator, UInt16 featureNum)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "UInt32 creator, UInt16 featureNum");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (UInt32, creator);
	CALLER_PUT_PARAM_VAL (UInt16, featureNum);

	// Call the function.
	sub.Call (sysTrapFtrUnregister);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

#pragma mark -

// ---------------------------------------------------------------------------
//		 International Manager functions
// ---------------------------------------------------------------------------

// --------------------
// Called:
//
//	*	By dialog code, if the check is enabled.
// --------------------

Boolean IntlSetStrictChecks (Boolean iStrictChecks)
{
	// Prepare the stack.
	CALLER_SETUP ("Boolean", "Boolean iStrictChecks");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (Boolean, iStrictChecks);

	// Call the function.
	sub.CallSelector (sysTrapIntlDispatch, intlIntlStrictChecks);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Boolean);
}

// ---------------------------------------------------------------------------
//		 List Manager functions
// ---------------------------------------------------------------------------

#pragma mark -

// --------------------
// Called:
//
//	*	by PrvValidateFormObjectSize in Miscellaneous.cpp to determine if 
//		a zero-height list has any items.
// --------------------

Int16 LstGetNumberOfItems (const ListType* lst)
{
	// Prepare the stack.
	CALLER_SETUP ("Int16", "const ListType* lst");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (ListType*, lst);

	// Call the function.
	sub.Call (sysTrapLstGetNumberOfItems);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Int16);
}

// --------------------
// Called:
//
//	*	By EventOutput code to try to find out which
//      item in a list was tapped by a gremlin.
// --------------------

Int16 LstGetSelection (const ListType* lst)
{
	// Prepare the stack.
	CALLER_SETUP ("Int16", "const ListType* lst");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (ListType*, lst);

	// Call the function.
	sub.Call (sysTrapLstGetSelection);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Int16);
}

// --------------------
// Called:
//
//	*	By EventOutput code to try to find the
//      text of the item in a list that was tapped by a gremlin.
// --------------------

Char * LstGetSelectionText (const ListType *lst, Int16 itemNum)
{
	// Prepare the stack.
	CALLER_SETUP ("Char *", "const ListType* lst, Int16 itemNum");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (ListType*, lst);
	CALLER_PUT_PARAM_VAL (Int16, itemNum);

	// Call the function.
	sub.Call (sysTrapLstGetSelectionText);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (Char*);
}

#pragma mark -

// ---------------------------------------------------------------------------
//		 Memory Manager functions
// ---------------------------------------------------------------------------

// --------------------
// Called:
//
//	*	in our patch to SysUIAppSwitch (called as MemPtrFree) to free up any
//		left over cmdPBP's.
// --------------------

Err MemChunkFree (MemPtr chunkDataP)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "MemPtr chunkDataP");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (MemPtr, chunkDataP);

	// Call the function.
	sub.Call (sysTrapMemChunkFree);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	during the application install process (My_DmCreateDatabaseFromImage)
//		in order to lock a database handle before calling DmWrite.
//
//	*	by our SysAppStartup patch (CollectCurrentAppInfo) to get information
//		from the 'tAIN' or 'tver' resources.
//
//	*	while booting up (InstallCalibrationInfo) or starting a Gremlin
//		(ResetCalibrationInfo) as part of the process of setting the
//		calibration info to an identity state.
// --------------------

MemPtr MemHandleLock (MemHandle h)
{
	// Prepare the stack.
	CALLER_SETUP ("MemPtr", "MemHandle h");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (MemHandle, h);

	// Call the function.
	sub.Call (sysTrapMemHandleLock);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (MemPtr);
}

// --------------------
// Called:
//
//	*	during the application export process (My_ShlExportAsPilotFile)
//		all over the place
// --------------------

UInt32 MemHandleSize (MemHandle h)
{
	// Prepare the stack.
	CALLER_SETUP ("UInt32", "MemHandle h");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (MemHandle, h);

	// Call the function.
	sub.Call (sysTrapMemHandleSize);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (UInt32);
}

// --------------------
// Called:
//
//	*	during the application install process (My_DmCreateDatabaseFromImage)
//		to set the app info block field after the block's been created.
// --------------------

LocalID MemHandleToLocalID (MemHandle h)
{
	// Prepare the stack.
	CALLER_SETUP ("LocalID", "MemHandle h");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (MemHandle, h);

	// Call the function.
	sub.Call (sysTrapMemHandleToLocalID);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (LocalID);
}

// --------------------
// Called:
//
//	*	during the application install process (My_DmCreateDatabaseFromImage)
//		in order to unlock a database handle after copying the data
//		into it.
//
//	*	getting information about a database (AppGetExtraInfo) from its 'tAIN'
//		resource or app info block.
//
//	*	while booting up (InstallCalibrationInfo) or starting a Gremlin
//		(ResetCalibrationInfo) as part of the process of setting the
//		calibration info to an identity state.
// --------------------

Err MemHandleUnlock (MemHandle h)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "MemHandle h");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (MemHandle, h);

	// Call the function.
	sub.Call (sysTrapMemHandleUnlock);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	from our patch to MemInitHeapTable when walking all current
//		heaps to locate them all.
// --------------------

UInt16 MemHeapID (UInt16 cardNo, UInt16 heapIndex)
{
	// Prepare the stack.
	CALLER_SETUP ("UInt16", "UInt16 cardNo, UInt16 heapIndex");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (UInt16, cardNo);
	CALLER_PUT_PARAM_VAL (UInt16, heapIndex);

	// Call the function.
	sub.Call (sysTrapMemHeapID);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (UInt16);
}

// --------------------
// Called:
//
//	*	by EmPalmHeap::GetHeapHeaderInfo (heapID) in order to get a heap
//		pointer that can be passed to EmPalmHeap::GetHeapHeaderInfo (ptr).
//		This version of GetHeapHeaderInfo is called from the version of
//		the EmPalmHeap constructor that taks a heap ID.  This version of
//		the constructor is called from our patches on MemInitHeapTable
//		and MemHeapInit.
// --------------------

MemPtr MemHeapPtr (UInt16 heapID)
{
	// Prepare the stack.
	CALLER_SETUP ("MemPtr", "UInt16 heapID");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (UInt16, heapID);

	// Call the function.
	sub.Call (sysTrapMemHeapPtr);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (MemPtr);
}

// --------------------
// Called:
//
//	*	while getting an application's name (AppGetExtraInfo) from
//		the app info block -- we need to determine if the block
//		is a handle or not so that we know whether or not to lock it.
// --------------------

LocalIDKind MemLocalIDKind (LocalID local)
{
	// Prepare the stack.
	CALLER_SETUP ("LocalIDKind", "LocalID local");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (LocalID, local);

	// Call the function.
	sub.Call (sysTrapMemLocalIDKind);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (LocalIDKind);
}

// --------------------
// Called:
//
//	*	when exporting a database (My_ShlExportAsPilotFile) to get the
//		app info and sort info handles so that we can get their sizes.
//
//	*	while getting an application's name (AppGetExtraInfo) from the
//		app info block.
// --------------------

MemPtr MemLocalIDToGlobal (LocalID local, UInt16 cardNo)
{
	// Prepare the stack.
	CALLER_SETUP ("MemPtr", "LocalID local, UInt16 cardNo");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (LocalID, local);
	CALLER_PUT_PARAM_VAL (UInt16, cardNo);

	// Call the function.
	sub.Call (sysTrapMemLocalIDToGlobal);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (MemPtr);
}

// --------------------
// Called:
//
//	*	when iterating over all databases in the system (GetDatabases).
//		Called when generating a list of databases to display (e.g.,
//		in the New Gremlin and Export Database dialogs).
// --------------------

UInt16 MemNumCards (void)
{
	// Prepare the stack.
	CALLER_SETUP ("UInt16", "void");

	// Set the parameters.

	// Call the function.
	sub.Call (sysTrapMemNumCards);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (UInt16);
}

// --------------------
// Called:
//
//	*	while booting up on a patch to MemInitHeapTable to determine
//		how many heaps we need to track.
// --------------------

UInt16 MemNumHeaps (UInt16 cardNo)
{
	// Prepare the stack.
	CALLER_SETUP ("UInt16", "UInt16 cardNo");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (UInt16, cardNo);

	// Call the function.
	sub.Call (sysTrapMemNumHeaps);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (UInt16);
}

// --------------------
// Called:
//
//	*	when booting up (PrvSetCurrentDate) to set the current date
//		stored in the non-volatile data section.
// --------------------

Err MemNVParams (Boolean set, SysNVParamsPtr paramsP)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "Boolean set, SysNVParamsPtr paramsP");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (Boolean, set);
	CALLER_PUT_PARAM_REF (SysNVParamsType, paramsP, Marshal::kInOut);

	// Call the function.
	sub.Call (sysTrapMemNVParams);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (paramsP);

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	by Gremlins (Gremlins::New) when it needs to create a cmdPBP  telling
//		 Clipper which PQA to launch.
//
//	*	same comments for Patches::SwitchToApp, called when a .pqa was in
//		AutoRun or AutoRunAndQuit.
// --------------------

MemPtr MemPtrNew (UInt32 size)
{
	// Prepare the stack.
	CALLER_SETUP ("MemPtr", "UInt32 size");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (UInt32, size);

	// Call the function.
	sub.Call (sysTrapMemPtrNew);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (MemPtr);
}

// --------------------
// Called:
//
//	*	by Gremlins (Gremlins::New) when it needs to create a cmdPBP  telling
//		 Clipper which PQA to launch.
//
//	*	same comments for Patches::SwitchToApp, called when a .pqa was in
//		AutoRun or AutoRunAndQuit.
// --------------------

Err MemPtrSetOwner (MemPtr p, UInt16 owner)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "MemPtr p, UInt16 owner");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (MemPtr, p);
	CALLER_PUT_PARAM_VAL (UInt16, owner);

	// Call the function.
	sub.Call (sysTrapMemPtrSetOwner);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	while generate a list of databases and their names.  Some non-application
//		databases have special resources with this information; the resource
//		size needs to be checked to see if this information is included.
//
//	*	by our SysAppStartup patch (CollectCurrentAppInfo) to get the size of the stack.
// --------------------

UInt32 MemPtrSize (MemPtr p)
{
	// Prepare the stack.
	CALLER_SETUP ("UInt32", "MemPtr p");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (MemPtr, p);

	// Call the function.
	sub.Call (sysTrapMemPtrSize);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (UInt32);
}

// --------------------
// Called:
//
//	*	during the application export process (My_ShlExportAsPilotFile)
//		in order to unlock a database handle after copying the data
//		out of it.
// --------------------

Err MemPtrUnlock (MemPtr p)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "MemPtr p");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (MemPtr, p);

	// Call the function.
	sub.Call (sysTrapMemPtrUnlock);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

#pragma mark -

// ---------------------------------------------------------------------------
//		 Net Library functions
// ---------------------------------------------------------------------------

// --------------------
// Called:
//
//	*	NetLib redirection code (Platform_NetLib::OpenConfig) to activate
//		the configuration passed into NetOpenConfig.  The process mirrors
//		that which goes on in NetLib itself.
// --------------------

Err NetLibConfigMakeActive (UInt16 refNum, UInt16 configIndex)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "UInt16 refNum, UInt16 configIndex");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (UInt16, refNum);
	CALLER_PUT_PARAM_VAL (UInt16, configIndex);

	// Call the function.
	sub.Call (netLibConfigMakeActive);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

#pragma mark -

// ---------------------------------------------------------------------------
//		 Pen Manager functions
// ---------------------------------------------------------------------------

// --------------------
// Called:
//
//	*	while starting a Gremlin (ResetCalibrationInfo) to reset the Pen
//		calibration information *after* the Pen manager has read the
//		preference file (that is, merely changing the preference data
//		won't work, since PenOpen has already read it).
// --------------------

Err PenCalibrate (PointType* digTopLeftP, PointType* digBotRightP,
					PointType* scrTopLeftP, PointType* scrBotRightP)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", 
		"PointType* digTopLeftP, PointType* digBotRightP,"
		"PointType* scrTopLeftP, PointType* scrBotRightP");

	// Set the parameters.
	CALLER_PUT_PARAM_REF (PointType, digTopLeftP, Marshal::kInput);
	CALLER_PUT_PARAM_REF (PointType, digBotRightP, Marshal::kInput);
	CALLER_PUT_PARAM_REF (PointType, scrTopLeftP, Marshal::kInput);
	CALLER_PUT_PARAM_REF (PointType, scrBotRightP, Marshal::kInput);

	// Call the function.
	sub.Call (sysTrapPenCalibrate);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	while booting up (InstallCalibrationInfo) or starting a Gremlin
//		(ResetCalibrationInfo) as part of the process of setting the
//		calibration info to an identity state.
// --------------------

Err	 PenRawToScreen(PointType* penP)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "PointType* penP");

	// Set the parameters.
	CALLER_PUT_PARAM_REF (PointType, penP, Marshal::kInOut);

	// Call the function.
	sub.Call (sysTrapPenRawToScreen);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (penP);

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	our EvtEnqueuePenPoint wrapper.
// --------------------

Err PenScreenToRaw (PointType* penP)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "PointType* penP");

	// Set the parameters.
	CALLER_PUT_PARAM_REF (PointType, penP, Marshal::kInOut);

	// Call the function.
	sub.Call (sysTrapPenScreenToRaw);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (penP);

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

#pragma mark -

// ---------------------------------------------------------------------------
//		 Peferences Manager functions
// ---------------------------------------------------------------------------

// --------------------
// Called:
//
//	*	while booting up (InstallCalibrationInfo) or starting a Gremlin
//		(ResetCalibrationInfo) as part of the process of setting the
//		calibration info to an identity state (1.0 devices only).
// --------------------

DmOpenRef PrefOpenPreferenceDBV10 (void)
{
	// Prepare the stack.
	CALLER_SETUP ("DmOpenRef", "void");

	// Set the parameters.

	// Call the function.
	sub.Call (sysTrapPrefOpenPreferenceDBV10);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (DmOpenRef);
}

// --------------------
// Called:
//
//	*	while booting up (InstallCalibrationInfo) or starting a Gremlin
//		(ResetCalibrationInfo) as part of the process of setting the
//		calibration info to an identity state (2.0 devices and later).
// --------------------

DmOpenRef PrefOpenPreferenceDB (Boolean saved)
{
	// Prepare the stack.
	CALLER_SETUP ("DmOpenRef", "Boolean saved");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (Boolean, saved);

	// Call the function.
	sub.Call (sysTrapPrefOpenPreferenceDB);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (DmOpenRef);
}

// --------------------
// Called:
//
//	*	while booting up in a tailpatch to UIInitialize to turn off
//		any auto-off values.
// --------------------

void PrefSetPreference (SystemPreferencesChoice choice, UInt32 value)
{
	// Prepare the stack.
	CALLER_SETUP ("void", "SystemPreferencesChoice choice, UInt32 value");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (SystemPreferencesChoice, choice);
	CALLER_PUT_PARAM_VAL (UInt32, value);

	// Call the function.
	sub.Call (sysTrapPrefSetPreference);

	// Write back any "by ref" parameters.

	// Return the result.
}

#pragma mark -

// ---------------------------------------------------------------------------
//		 System Manager functions
// ---------------------------------------------------------------------------

// --------------------
// Called:
//
//	*	in a headpatch to SysUIAppSwitch to see if the application we're
//		switching to is allowed (it may not be during Gremlins).
// --------------------

Err	SysCurAppDatabase (UInt16* cardNoP, LocalID* dbIDP)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "UInt16* cardNoP, LocalID* dbIDP");

	// Set the parameters.
	CALLER_PUT_PARAM_REF (UInt16, cardNoP, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (LocalID, dbIDP, Marshal::kInOut);

	// Call the function.
	sub.Call (sysTrapSysCurAppDatabase);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (cardNoP);
	CALLER_GET_PARAM_REF (dbIDP);

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	in the memory access checking code (GWH_ExamineChunk) to iterate
//		the tasks.  This is part of the hueristic to see if a task
//		that's being terminated is still trying to access its stack after
//		it's been deleted.
// --------------------

Err SysKernelInfo (MemPtr p)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "SysKernelInfoPtr p");

	// Set the parameters.
	CALLER_PUT_PARAM_REF (SysKernelInfoType, p, Marshal::kInOut);

	// Call the function.
	sub.Call (sysTrapSysKernelInfo);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (p);

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	.
// --------------------

Err SysLibFind (const Char *nameP, UInt16 *refNumP)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "const Char *nameP, UInt16 *refNumP");

	// Set the parameters.
	CALLER_PUT_PARAM_STR (Char, nameP);
	CALLER_PUT_PARAM_REF (UInt16, refNumP, Marshal::kInOut);

	// Call the function.
	sub.Call (sysTrapSysLibFind);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (refNumP);

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	.
// --------------------

Err SysLibLoad (UInt32 libType, UInt32 libCreator, UInt16 *refNumP)
{
	// Prepare the stack.
	CALLER_SETUP ("Err", "UInt32 libType, UInt32 libCreator, UInt16 *refNumP");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (UInt32, libType);
	CALLER_PUT_PARAM_VAL (UInt32, libCreator);
	CALLER_PUT_PARAM_REF (UInt16, refNumP, Marshal::kInOut);

	// Call the function.
	sub.Call (sysTrapSysLibLoad);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (refNumP);

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

// --------------------
// Called:
//
//	*	.
// --------------------

SysLibTblEntryPtr SysLibTblEntry (UInt16 refNum)
{
	// Prepare the stack.
	CALLER_SETUP ("SysLibTblEntryPtr", "UInt16 refNum");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (UInt16, refNum);

	// Call the function.
	sub.Call (sysTrapSysLibTblEntry);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (SysLibTblEntryPtr);
}

// --------------------
// Called:
//
//	*	while booting up in a tailpatch to UIInitialize to turn off
//		any auto-off values.
// --------------------

UInt16 SysSetAutoOffTime (UInt16 seconds)
{
	// Prepare the stack.
	CALLER_SETUP ("UInt16", "UInt16 seconds");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (UInt16, seconds);

	// Call the function.
	sub.Call (sysTrapSysSetAutoOffTime);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (UInt16);
}

// --------------------
// Called:
//
//	*	By Gremlin code (Gremlins::New) to switch to an approved application
//		(either one on the approved list, or one that can "run" one on the
//		approved like, like a PQA).
//
//	*	By Patches::SwitchToApp to switch to a given application.  This
//		function is called after booting or loading a session and the user
//		has a file in the AutoRun or AutoRunAndQuit directories.
// --------------------

Err SysUIAppSwitch (UInt16 cardNo, LocalID dbID, UInt16 cmd, MemPtr cmdPBP)
{	
	// Prepare the stack.
	CALLER_SETUP ("Err", "UInt16 cardNo, LocalID dbID, UInt16 cmd, MemPtr cmdPBP");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (UInt16, cardNo);
	CALLER_PUT_PARAM_VAL (LocalID, dbID);
	CALLER_PUT_PARAM_VAL (UInt16, cmd);
	CALLER_PUT_PARAM_VAL (MemPtr, cmdPBP);

	// Call the function.
	sub.Call (sysTrapSysUIAppSwitch);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Err);
}

#pragma mark -

// ---------------------------------------------------------------------------
//		 Table Manager functions
// ---------------------------------------------------------------------------

// --------------------
// Called:
//
//	*	By EventOutput code
// --------------------

Coord TblGetColumnSpacing (const TableType* tableP, Int16 column)
{
	// Prepare the stack.
	CALLER_SETUP ("Coord", "const TableType* tableP, Int16 column");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (TableType*, tableP);
	CALLER_PUT_PARAM_VAL (Int16, column);

	// Call the function.
	sub.Call (sysTrapTblGetColumnSpacing);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Coord);
}

// --------------------
// Called:
//
//	*	By EventOutput code
// --------------------

Coord TblGetColumnWidth (const TableType* tableP, Int16 column)
{
	// Prepare the stack.
	CALLER_SETUP ("Coord", "const TableType* tableP, Int16 column");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (TableType*, tableP);
	CALLER_PUT_PARAM_VAL (Int16, column);

	// Call the function.
	sub.Call (sysTrapTblGetColumnWidth);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Coord);
}

// --------------------
// Called:
//
//	*	By Gremlin code (GetFocusObject) to determine if there's a sub-field
//		in a table that needs to be targeted.
// --------------------

FieldPtr TblGetCurrentField (const TableType* table)
{
	// Prepare the stack.
	CALLER_SETUP ("FieldPtr", "const TableType* table");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (TableType*, table);

	// Call the function.
	sub.Call (sysTrapTblGetCurrentField);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (FieldPtr);
}

// --------------------
// Called:
//
//	*	By EventOutput code
// --------------------

Coord TblGetRowHeight (const TableType* tableP, Int16 row)
{
	// Prepare the stack.
	CALLER_SETUP ("Coord", "const TableType* tableP, Int16 row");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (TableType*, tableP);
	CALLER_PUT_PARAM_VAL (Int16, row);

	// Call the function.
	sub.Call (sysTrapTblGetRowHeight);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (Coord);
}

// --------------------
// Called:
//
//	*	By EventOutput code (GetPreviousEventInfo) to try to find out where
//      in the table was tapped by a gremlin.
// --------------------

Boolean TblGetSelection (const TableType* tableP, Int16* rowP, Int16* columnP)
{
	// Prepare the stack.
	CALLER_SETUP ("Boolean", "const TableType* tableP, Int16* rowP, Int16* columnP");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (TableType*, tableP);
	CALLER_PUT_PARAM_REF (Int16, rowP, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (Int16, columnP, Marshal::kInOut);

	// Call the function.
	sub.Call (sysTrapTblGetSelection);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (rowP);
	CALLER_GET_PARAM_REF (columnP);

	// Return the result.
	RETURN_RESULT_VAL (Boolean);
}

#pragma mark -

// ---------------------------------------------------------------------------
//		 Text Manager functions
// ---------------------------------------------------------------------------

// --------------------
// Called:
//
//	*	By Gremlin code (GetFakeEvent) when generating the percentage
//		that any character is randomly posted to the application.
// --------------------

UInt8 TxtByteAttr(UInt8 inByte)
{
	// Prepare the stack.
	CALLER_SETUP ("UInt8", "UInt8 inByte");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (UInt8, inByte);

	// Call the function.
	sub.CallSelector (sysTrapIntlDispatch, intlTxtByteAttr);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_VAL (UInt8);
}

// --------------------
// Called:
//
//	*	By Gremlin code (GetFakeEvent) when generating the percentage
//		that any character is randomly posted to the application.
// --------------------

UInt16 TxtCharBounds (const Char* inText, UInt32 inOffset, UInt32* outStart, UInt32* outEnd)
{
	// Prepare the stack.
	CALLER_SETUP ("UInt16", "const Char* inText, UInt32 inOffset, UInt32* outStart, UInt32* outEnd");

	// Set the parameters.
	CALLER_PUT_PARAM_PTR (Char, inText, inOffset + 4, Marshal::kInput);
	CALLER_PUT_PARAM_VAL (UInt32, inOffset);
	CALLER_PUT_PARAM_REF (UInt32, outStart, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (UInt32, outEnd, Marshal::kInOut);

	// Call the function.
	sub.CallSelector (sysTrapIntlDispatch, intlTxtCharBounds);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (outStart);
	CALLER_GET_PARAM_REF (outEnd);

	// Return the result.
	RETURN_RESULT_VAL (UInt16);
}

// --------------------
// Called:
//
//	*	By Gremlin code (SendCharsToType) when iterating over the hardcoded
//		text to be posted to the application.
// --------------------

UInt16 TxtGetNextChar (const Char* inText, UInt32 inOffset, WChar* outChar)
{
	// Prepare the stack.
	CALLER_SETUP ("UInt16", "const Char* inText, UInt32 inOffset, WChar* outChar");

	// Set the parameters.
	CALLER_PUT_PARAM_PTR (Char, inText, inOffset + 4, Marshal::kInput);
	CALLER_PUT_PARAM_VAL (UInt32, inOffset);
	CALLER_PUT_PARAM_REF (WChar, outChar, Marshal::kInOut);

	// Call the function.
	sub.CallSelector (sysTrapIntlDispatch, intlTxtGetNextChar);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (outChar);

	// Return the result.
	RETURN_RESULT_VAL (UInt16);
}

#pragma mark -

// ---------------------------------------------------------------------------
//		 Window Manager functions
// ---------------------------------------------------------------------------

// --------------------
// Called:
//
//	*	By Gremlins code (FakeEventXY) after picking a window object to click on.
// --------------------

void WinDisplayToWindowPt (Int16* extentX, Int16* extentY)
{
	// Prepare the stack.
	CALLER_SETUP ("void", "Int16* extentX, Int16* extentY");

	// Set the parameters.
	CALLER_PUT_PARAM_REF (Int16, extentX, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (Int16, extentY, Marshal::kInOut);

	// Call the function.
	sub.Call (sysTrapWinDisplayToWindowPt);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (extentX);
	CALLER_GET_PARAM_REF (extentY);

	// Return the result.
}

// --------------------
// Called:
//
//	*	By Gremlin code (GetFocusObject) to make sure that the active window
//		is also the active form.
//
//	*	By Gremlin code (RandomWindowXY) to determine if there's a window
//		within which a pen event should be generated.
//
//	*	By Gremlin code (RandomWindowXY) to set the draw window before calling
//		WinGetWindowBounds.
// --------------------

WinHandle WinGetActiveWindow (void)
{
	// Prepare the stack.
	CALLER_SETUP ("WinHandle", "void");

	// Set the parameters.

	// Call the function.
	sub.Call (sysTrapWinGetActiveWindow);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (WinHandle);
}

// --------------------
// Called:
//
//	*	By Gremlin code (FakeLocalMovement) to clip random pen dragging
//		to the window's bounds.
//
//	*	By Gremlin code (RandomScreenXY) to generate a random pen event
//		within a window's bounds.
//
//	*	By Gremlin code (FakeEventXY) to clip a random pen event within
//		an object to the window's bounds.
//
//	*	By Gremlin code (CollectOKObjects) to check to see if all objects
//		are within the window's bounds.
// --------------------

void WinGetDisplayExtent (Int16* extentX, Int16* extentY)
{
	// Prepare the stack.
	CALLER_SETUP ("void", "Int16* extentX, Int16* extentY");

	// Set the parameters.
	CALLER_PUT_PARAM_REF (Int16, extentX, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (Int16, extentY, Marshal::kInOut);

	// Call the function.
	sub.Call (sysTrapWinGetDisplayExtent);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (extentX);
	CALLER_GET_PARAM_REF (extentY);

	// Return the result.
}

// --------------------
// Called:
//
//	*	By logging code (StubEmPrintFormID) to walk the window list in
//		order to ensure that a WinHandle is valid before trying to get
//		its name/title.
// --------------------

WinHandle WinGetFirstWindow (void)
{
	// Prepare the stack.
	CALLER_SETUP ("WinHandle", "void");

	// Set the parameters.

	// Call the function.
	sub.Call (sysTrapWinGetFirstWindow);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (WinHandle);
}

// --------------------
// Called:
//
//	*	By Gremlins code (RandomWindowXY) before calling WinGetWindowBounds
//		while determining a random location to tap in the window.
//
//	!!! This is renamed to WinGetDrawWindowBounds in Bellagio.
// --------------------

void WinGetWindowBounds (RectanglePtr r)
{
	// Prepare the stack.
	CALLER_SETUP ("void", "RectanglePtr r");

	// Set the parameters.
	CALLER_PUT_PARAM_REF (RectangleType, r, Marshal::kInOut);

	// Call the function.
	sub.Call (sysTrapWinGetDrawWindowBounds);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (r);

	// Return the result.
}

// --------------------
// Called:
//
//	* In our tailpatch of TblHandleEvent to fix a Palm OS 3.5 bug.
// --------------------

void WinPopDrawState (void)
{
	// Prepare the stack.
	CALLER_SETUP ("void", "void");

	// Set the parameters.

	// Call the function.
	sub.Call (sysTrapWinPopDrawState);

	// Write back any "by ref" parameters.

	// Return the result.
}

// --------------------
// Called:
//
// --------------------

WinHandle WinSetDrawWindow (WinHandle winHandle)
{
	// Prepare the stack.
	CALLER_SETUP ("WinHandle", "WinHandle winHandle");

	// Set the parameters.
	CALLER_PUT_PARAM_VAL (WinHandle, winHandle);

	// Call the function.
	sub.Call (sysTrapWinSetDrawWindow);

	// Write back any "by ref" parameters.

	// Return the result.
	RETURN_RESULT_PTR (WinHandle);
}

// --------------------
// Called:
//
//	*	By Gremlins code (FakeEventXY) after picking a window object to click on.
// --------------------

void WinWindowToDisplayPt (Int16* extentX, Int16* extentY)
{
	// Prepare the stack.
	CALLER_SETUP ("void", "Int16* extentX, Int16* extentY");

	// Set the parameters.
	CALLER_PUT_PARAM_REF (Int16, extentX, Marshal::kInOut);
	CALLER_PUT_PARAM_REF (Int16, extentY, Marshal::kInOut);

	// Call the function.
	sub.Call (sysTrapWinWindowToDisplayPt);

	// Write back any "by ref" parameters.
	CALLER_GET_PARAM_REF (extentX);
	CALLER_GET_PARAM_REF (extentY);

	// Return the result.
}