summarylogtreecommitdiffstats
path: root/010-dosbox-add-openglide-support.patch
blob: e0327483988cb60aec12c0ee1cecb5e1f6161660 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
--- a/configure.ac
+++ b/configure.ac
@@ -616,7 +616,7 @@ int main(int argc,char * argv[]) {
 dnl Some target detection and actions for them
 case "$host" in
     *-*-cygwin* | *-*-mingw32*)
-       LIBS="$LIBS -lwinmm"
+       LIBS="$LIBS -lwinmm -lshlwapi"
        AC_DEFINE(C_DIRECTSERIAL, 1, [ Define to 1 if you want serial passthrough support (Win32, Posix and OS/2 only).])
        if test x$have_sdl_net_lib = xyes -a x$have_sdl_net_h = xyes ; then
          LIBS="$LIBS -lws2_32"
--- a/include/glidedef.h
+++ b/include/glidedef.h
@@ -0,0 +1,179 @@
+/*
+ *  Copyright (C) 2002-2007  The DOSBox Team
+ *
+ *  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.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef GLIDEDEF_H
+#define GLIDEDEF_H
+
+#ifdef DOSBOX_DOSBOX_H
+struct GLIDE_Block
+{
+    bool splash;
+    bool enabled;
+    bool * fullscreen;
+    Bit16u width, height;
+    class GLIDE_PageHandler * lfb_pagehandler;
+    GLIDE_Block():enabled(false),fullscreen(0),width(0),height(0),lfb_pagehandler((GLIDE_PageHandler*)0) { }
+};
+extern GLIDE_Block glide;
+extern void GLIDE_ResetScreen(bool update=false);
+extern void GLIDE_DisableScreen(void);
+#endif
+
+#define GLIDE_LFB		0x60000000
+#define GLIDE_BUFFERS		3			/* Front, Back, AUX */
+#define GLIDE_PAGE_BITS		11			/* =2048 pages per buffer, should be enough for 1600x1200x4 */
+#define GLIDE_PAGES		(GLIDE_BUFFERS*(1<<GLIDE_PAGE_BITS))
+
+#ifdef __3DFX_H__
+/* If you change these defines, don't forget to change the table in glide.h and compile a matching GLIDE2X.OVL */
+
+#define	_grAADrawLine8			0	// void grAADrawLine(GrVertex *va, GrVertex *vb)
+#define	_grAADrawPoint4			1	// void grAADrawPoint(GrVertex *p)
+#define	_grAADrawPolygon12		2	// void grAADrawPolygon(int nVerts, const int ilist[], const GrVertex vlist[])
+#define	_grAADrawPolygonVertexList8	3	// void grAADrawPolygonVertexList(int nVerts, const GrVertex vlist[])
+#define	_grAADrawTriangle24		4	// void grAADrawTriangle(GrVertex *a, GrVertex *b, GrVertex *c, FxBool antialiasAB, FxBool antialiasBC, FxBool antialiasCA)
+#define	_grAlphaBlendFunction16		5	// void grAlphaBlendFunction(GrAlphaBlendFnc_t rgb_sf, GrAlphaBlendFnc_t rgb_df, GrAlphaBlendFnc_t alpha_sf, GrAlphaBlendFnc_t alpha_df)
+#define	_grAlphaCombine20		6	// void grAlphaCombine(GrCombineFunction_t func, GrCombineFactor_t factor, GrCombineLocal_t local, GrCombineOther_t other, FxBool invert)
+#define	_grAlphaControlsITRGBLighting4	7	// void grAlphaControlsITRGBLighting(FxBool enable)
+#define	_grAlphaTestFunction4		8	// void grAlphaTestFunction(GrCmpFnc_t function)
+#define	_grAlphaTestReferenceValue4	9	// void grAlphaTestReferenceValue(GrAlpha_t value)
+#define	_grBufferClear12		10	// void grBufferClear(GrColor_t color, GrAlpha_t alpha, FxU16 depth)
+#define	_grBufferNumPending0		11	// int grBufferNumPending(void)
+#define	_grBufferSwap4			12	// void grBufferSwap(int swap_interval)
+#define	_grCheckForRoom4		13	// void grCheckForRoom(FxI32 n)
+#define	_grChromakeyMode4		14	// void grChromakeyMode(GrChromakeyMode_t mode)
+#define	_grChromakeyValue4		15	// void grChromakeyValue(GrColor_t value)
+#define	_grClipWindow16			16	// void grClipWindow(FxU32 minx, FxU32 miny, FxU32 maxx, FxU32 maxy)
+#define	_grColorCombine20		17	// void grColorCombine(GrCombineFunction_t func, GrCombineFactor_t factor, GrCombineLocal_t local, GrCombineOther_t other, FxBool invert)
+#define	_grColorMask8			18	// void grColorMask(FxBool rgb, FxBool alpha)
+#define	_grConstantColorValue416	19	// void grConstantColorValue4(float a, float r, float g, float b)
+#define	_grConstantColorValue4		20	// void grConstantColorValue(GrColor_t color)
+#define	_grCullMode4			21	// void grCullMode(GrCullMode_t mode)
+#define	_grDepthBiasLevel4		22	// void grDepthBiasLevel(FxI16 level)
+#define	_grDepthBufferFunction4		23	// void grDepthBufferFunction(GrCmpFnc_t func)
+#define	_grDepthBufferMode4		24	// void grDepthBufferMode(GrDepthBufferMode_t mode)
+#define	_grDepthMask4			25	// void grDepthMask(FxBool enable)
+#define	_grDisableAllEffects0		26	// void grDisableAllEffects(void)
+#define	_grDitherMode4			27	// void grDitherMode(GrDitherMode_t mode)
+#define	_grDrawLine8			28	// void grDrawLine(const GrVertex *a, const GrVertex *b)
+#define	_grDrawPlanarPolygon12		29	// void grDrawPlanarPolygon(int nVerts, int ilist[], const GrVertex vlist[])
+#define	_grDrawPlanarPolygonVertexList8 30	// void grDrawPlanarPolygonVertexList(int nVerts, const GrVertex vlist[])
+#define	_grDrawPoint4			31	// void grDrawPoint(const GrVertex *a)
+#define	_grDrawPolygon12		32	// void grDrawPolygon(int nVerts, int ilist[], const GrVertex vlist[])
+#define	_grDrawPolygonVertexList8	33	// void grDrawPolygonVertexList(int nVerts, const GrVertex vlist[])
+#define	_grDrawTriangle12		34	// void grDrawTriangle(const GrVertex *a, const GrVertex *b, const GrVertex *c)
+#define	_grErrorSetCallback4		35	// void grErrorSetCallback(void (*function)(const char *string, FxBool fatal))
+#define	_grFogColorValue4		36	// void grFogColorValue(GrColor_t value)
+#define	_grFogMode4			37	// void grFogMode(GrFogMode_t mode)
+#define	_grFogTable4			38	// void grFogTable(const GrFog_t table[GR_FOG_TABLE_SIZE])
+#define	_grGammaCorrectionValue4	39	// void grGammaCorrectionValue(float value)
+#define	_grGlideGetState4		40	// void grGlideGetState(GrState *state)
+#define	_grGlideGetVersion4		41	// void grGlideGetVersion(char version[80])
+#define	_grGlideInit0			42	// void grGlideInit(void)
+#define	_grGlideSetState4		43	// void grGlideSetState(const GrState *state)
+#define	_grGlideShamelessPlug4		44	// void grGlideShamelessPlug(const FxBool on)
+#define	_grGlideShutdown0		45	// void grGlideShutdown(void)
+#define	_grHints8			46	// void grHints(GrHint_t type, FxU32 hintMask)
+#define	_grLfbConstantAlpha4		47	// void grLfbConstantAlpha(GrAlpha_t alpha)
+#define	_grLfbConstantDepth4		48	// void grLfbConstantDepth(FxU16 depth)
+#define	_grLfbLock24			49	// FxBool grLfbLock(GrLock_t type, GrBuffer_t buffer, GrLfbWriteMode_t writeMode, GrOriginLocation_t origin, FxBool pixelPipeline, GrLfbInfo_t *info)
+#define	_grLfbReadRegion28		50	// FxBool grLfbReadRegion(GrBuffer_t src_buffer, FxU32 src_x, FxU32 src_y, FxU32 src_width, FxU32 src_height, FxU32 dst_stride, void *dst_data)
+#define	_grLfbUnlock8			51	// FxBool grLfbUnlock(GrLock_t type, GrBuffer_t buffer)
+#define	_grLfbWriteColorFormat4		52	// void grLfbWriteColorFormat(GrColorFormat_t colorFormat)
+#define	_grLfbWriteColorSwizzle8	53	// void grLfbWriteColorSwizzle(FxBool swizzleBytes, FxBool swapWords)
+#define	_grLfbWriteRegion32		54	// FxBool grLfbWriteRegion(GrBuffer_t dst_buffer, FxU32 dst_x, FxU32 dst_y, GrLfbSrcFmt_t src_format, FxU32 src_width, FxU32 src_height, FxU32 src_stride, void *src_data)
+#define	_grRenderBuffer4		55	// void grRenderBuffer(GrBuffer_t buffer)
+#define	_grResetTriStats0		56	// void grResetTriStats()
+#define	_grSplash20			57	// void grSplash(float x, float y, float width, float height, FxU32 frame)
+#define	_grSstConfigPipeline12		58	//
+#define	_grSstControl4			59	// FxBool grSstControl(FxU32 code)
+#define	_grSstIdle0			60	// void grSstIdle(void)
+#define	_grSstIsBusy0			61	// FxBool grSstIsBusy(void)
+#define	_grSstOrigin4			62	// void grSstOrigin(GrOriginLocation_t origin)
+#define	_grSstPerfStats4		63	// void grSstPerfStats(GrSstPerfStats_t *pStats)
+#define	_grSstQueryBoards4		64	// FxBool grSstQueryBoards(GrHwConfiguration *hwConfig)
+#define	_grSstQueryHardware4		65	// FxBool grSstQueryHardware(GrHwConfiguration *hwConfig)
+#define	_grSstResetPerfStats0		66	// void grSstResetPerfStats(void)
+#define	_grSstScreenHeight0		67	// FxU32 grSstScreenHeight(void)
+#define	_grSstScreenWidth0		68	// FxU32 grSstScreenWidth(void)
+#define	_grSstSelect4			69	// void grSstSelect(int which_sst)
+#define	_grSstStatus0			70	// FxU32 grSstStatus(void)
+#define	_grSstVRetraceOn0		71	// FxBool grSstVRetraceOn(void)
+#define	_grSstVidMode8			72	//
+#define	_grSstVideoLine0		73	// FxU32 grSstVideoLine(void)
+#define	_grSstWinClose0			74	// void grSstWinClose(void)
+#define	_grSstWinOpen28			75	// FxBool grSstWinOpen(FxU32 hwnd, GrScreenResolution_t res, GrScreenRefresh_t ref, GrColorFormat_t cformat, GrOriginLocation_t org_loc, int num_buffers, int num_aux_buffers)
+#define	_grTexCalcMemRequired16		76	// FxU32 grTexCalcMemRequired(GrLOD_t smallLod, GrLOD_t largeLod, GrAspectRatio_t aspect, GrTextureFormat_t format)
+#define	_grTexClampMode12		77	// void grTexClampMode(GrChipID_t tmu, GrTextureClampMode_t sClampMode, GrTextureClampMode_t tClampMode)
+#define	_grTexCombine28			78	// void grTexCombine(GrChipID_t tmu, GrCombineFunction_t rgb_function, GrCombineFactor_t rgb_factor, GrCombineFunction_t alpha_function, GrCombineFactor_t alpha_factor, FxBool rgb_invert, FxBool alpha_invert)
+#define	_grTexCombineFunction8		79	// void grTexCombineFunction(GrChipID_t tmu, GrTextureCombineFnc_t fnc)
+#define	_grTexDetailControl16		80	// void grTexDetailControl(GrChipID_t tmu, int lodBias, FxU8 detailScale, float detailMax)
+#define	_grTexDownloadMipMap16		81	// void grTexDownloadMipMap(GrChipID_t tmu, FxU32 startAddress, FxU32 evenOdd, GrTexInfo *info)
+#define	_grTexDownloadMipMapLevel32	82	// void grTexDownloadMipMapLevel(GrChipID_t tmu, FxU32 startAddress, GrLOD_t thisLod, GrLOD_t largeLod, GrAspectRatio_t aspectRatio, GrTextureFormat_t format, FxU32 evenOdd, void *data)
+#define	_grTexDownloadMipMapLevelPartial40 83	// void grTexDownloadMipMapLevelPartial(GrChipID_t tmu, FxU32 startAddress, GrLOD_t thisLod, GrLOD_t largeLod, GrAspectRatio_t aspectRatio, GrTextureFormat_t format, FxU32 evenOdd, void *data, int start, int end)
+#define	_grTexDownloadTable12		84	// void grTexDownloadTable(GrChipID_t tmu, GrTexTable_t type, void *data)
+#define	_grTexDownloadTablePartial20	85	// void grTexDownloadTablePartial(GrChipID_t tmu, GrTexTable_t type, void *data, int start, int end)
+#define	_grTexFilterMode12		86	// void grTexFilterMode(GrChipID_t tmu, GrTextureFilterMode_t minFilterMode, GrTextureFilterMode_t magFilterMode)
+#define	_grTexLodBiasValue8		87	// void grTexLodBiasValue(GrChipID_t tmu, float bias)
+#define	_grTexMaxAddress4		88	// FxU32 grTexMaxAddress(GrChipID_t tmu)
+#define	_grTexMinAddress4		89	// FxU32 grTexMinAddress(GrChipID_t tmu)
+#define	_grTexMipMapMode12		90	// void grTexMipMapMode(GrChipID_t tmu, GrMipMapMode_t mode, FxBool lodBlend)
+#define	_grTexMultibase8		91	// void grTexMultibase(GrChipID_t tmu, FxBool enable)
+#define	_grTexMultibaseAddress20	92	// void grTexMultibaseAddress(GrChipID_t tmu, GrTexBaseRange_t range, FxU32 startAddress, FxU32 evenOdd, GrTexInfo *info)
+#define	_grTexNCCTable8			93	// void grTexNCCTable(GrChipID_t tmu, GrNCCTable_t table)
+#define	_grTexSource16			94	// void grTexSource(GrChipID_t tmu, FxU32 startAddress, FxU32 evenOdd, GrTexInfo *info)
+#define	_grTexTextureMemRequired8	95	// FxU32 grTexTextureMemRequired(FxU32 evenOdd, GrTexInfo *info)
+#define	_grTriStats8			96	// void grTriStats(FxU32 *trisProcessed, FxU32 *trisDrawn)
+#define	_gu3dfGetInfo8			97	// FxBool gu3dfGetInfo(const char *filename, Gu3dfInfo *info)
+#define	_gu3dfLoad8			98	// FxBool gu3dfLoad(const char *filename, Gu3dfInfo *info)
+#define	_guAADrawTriangleWithClip12	99	// void guAADrawTriangleWithClip(const GrVertex *va, const GrVertex *vb, const GrVertex *vc)
+#define	_guAlphaSource4			100	// void guAlphaSource(GrAlphaSource_t mode)
+#define	_guColorCombineFunction4	101	// void guColorCombineFunction(GrColorCombineFnc_t func)
+#define	_guDrawPolygonVertexListWithClip8 102	// void guDrawPolygonVertexListWithClip(int nverts, const GrVertex vlist[])
+#define	_guDrawTriangleWithClip12	103	// void guDrawTriangleWithClip(const GrVertex *va, const GrVertex *vb, const GrVertex *vc)
+#define	_guEncodeRLE1616		104	//
+#define	_guEndianSwapBytes4		105	//
+#define	_guEndianSwapWords4		106	//
+#define	_guFogGenerateExp28		107	// void guFogGenerateExp2(GrFog_t fogTable[GR_FOG_TABLE_SIZE], float density)
+#define	_guFogGenerateExp8		108	// void guFogGenerateExp(GrFog_t fogTable[GR_FOG_TABLE_SIZE], float density)
+#define	_guFogGenerateLinear12		109	// void guFogGenerateLinear(GrFog_t fogTable[GR_FOG_TABLE_SIZE], float nearW, float farW)
+#define	_guFogTableIndexToW4		110	// float guFogTableIndexToW(int i)
+#define	_guMPDrawTriangle12		111	//
+#define	_guMPInit0			112	//
+#define	_guMPTexCombineFunction4	113	//
+#define	_guMPTexSource8			114	//
+#define	_guMovieSetName4		115	//
+#define	_guMovieStart0			116	//
+#define	_guMovieStop0			117	//
+#define	_guTexAllocateMemory60		118	// GrMipMapId_t guTexAllocateMemory(GrChipID_t tmu, FxU8 evenOddMask, int width, int height, GrTextureFormat_t format, GrMipMapMode_t mmMode, GrLOD_t smallLod, GrLOD_t largeLod, GrAspectRatio_t aspectRatio, GrTextureClampMode_t sClampMode, GrTextureClampMode_t tClampMode, GrTextureFilterMode_t minFilterMode, GrTextureFilterMode_t magFilterMode, float lodBias, FxBool lodBlend)
+#define	_guTexChangeAttributes48	119	// FxBool guTexChangeAttributes(GrMipMapID_t mmid, int width, int height, GrTextureFormat_t format, GrMipMapMode_t mmMode, GrLOD_t smallLod, GrLOD_t largeLod, GrAspectRatio_t aspectRatio, GrTextureClampMode_t sClampMode, GrTextureClampMode_t tClampMode, GrTextureFilterMode_t minFilterMode, GrTextureFilterMode_t magFilterMode)
+#define	_guTexCombineFunction8		120	// void guTexCombineFunction(GrChipID_t tmu, GrTextureCombineFnc_t func)
+#define	_guTexCreateColorMipMap0	121	//
+#define	_guTexDownloadMipMap12		122	// void guTexDownloadMipMap(GrMipMapId_t mmid, const void *src, const GuNccTable *nccTable)
+#define	_guTexDownloadMipMapLevel12	123	// void guTexDownloadMipMapLevel(GrMipMapId_t mmid, GrLOD_t lod, const void **src)
+#define	_guTexGetCurrentMipMap4		124	// GrMipMapId_t guTexGetCurrentMipMap (GrChipID_t tmu)
+#define	_guTexGetMipMapInfo4		125	// GrMipMapInfo *guTexGetMipMapInfo(GrMipMapId_t mmid)
+#define	_guTexMemQueryAvail4		126	// FxU32 guTexMemQueryAvail(GrChipID_t tmu)
+#define	_guTexMemReset0			127	// void guTexMemReset(void)
+#define	_guTexSource4			128	// void guTexSource(GrMipMapId_t mmid)
+#define	_ConvertAndDownloadRle64	129	// void ConvertAndDownloadRle(GrChipID_t tmu, FxU32 startAddress, GrLOD_t thisLod, GrLOD_t largeLod, GrAspectRatio_t aspectRatio, GrTextureFormat_t format, FxU32 evenOdd, FxU8 *bm_data, long  bm_h, FxU32 u0, FxU32 v0, FxU32 width, FxU32 height, FxU32 dest_width, FxU32 dest_height, FxU16 *tlut)
+#define GLIDE_MAX			129
+
+#endif // __3DFX_H__
+
+#endif // GLIDEDEF_H
--- a/include/glide.h
+++ b/include/glide.h
@@ -0,0 +1,331 @@
+/*
+ *  Copyright (C) 2002-2007  The DOSBox Team
+ *
+ *  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.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef DOSBOX_GLIDE_H
+#define DOSBOX_GLIDE_H
+
+#define __3DFX_H__
+
+/*
+** basic data types
+*/
+typedef Bit8u   FxU8;
+typedef Bit8s   FxI8;
+typedef Bit16u  FxU16;
+typedef Bit16s  FxI16;
+typedef Bit32u  FxU32;
+typedef Bit32s  FxI32;
+typedef Bit32s  FxBool;
+typedef float   FxFloat;
+typedef double  FxDouble;
+
+/*
+** color types
+*/
+typedef Bit32u                       FxColor_t;
+typedef struct { float r, g, b, a; } FxColor4;
+
+/*
+** fundamental types
+*/
+#define FXTRUE    1
+#define FXFALSE   0
+
+/*
+** helper macros
+*/
+#define FXUNUSED( a ) ((void)(a))
+#define FXBIT( i )    ( 1L << (i) )
+
+#define FX_ENTRY
+#define FX_GLIDE_NO_FUNC_PROTO
+
+#if defined (WIN32)
+#define FX_CALL __stdcall
+#else
+#define FX_CALL
+#endif
+
+#include <openglide/sdk2_glide.h>
+#include "glidedef.h"
+
+// Careful with structures containing pointers
+//
+// GrTexInfo; GrLfbInfo_t; Gu3dfInfo; GrMipMapInfo;
+//
+
+// Some glide structs might have different size in guest 32-bit DOS (pointers)
+typedef struct {
+    Bit32s		smallLod;
+    Bit32s		largeLod;
+    Bit32s		aspectRatio;
+    Bit32s		format;
+    PhysPt		data;
+} DBGrTexInfo;
+
+typedef struct {
+    Bit32s		size;
+    PhysPt		lfbPtr;
+    Bit32u		strideInBytes;
+    Bit32s		writeMode;
+    Bit32s		origin;
+} DBGrLfbInfo_t;
+
+typedef struct {
+    Gu3dfHeader 	header;
+    GuTexTable		table;
+    PhysPt		data;
+    Bit32u		mem_required;
+} DBGu3dfInfo;
+
+typedef struct {
+    const char * name;
+    const Bit8u parms;
+} GLIDE_TABLE;
+
+typedef void (FX_CALL *pfunc0)		(void);
+typedef void (FX_CALL *pfunc1i)		(FxU32);
+typedef void (FX_CALL *pfunc1p)		(void*);
+typedef void (FX_CALL *pfunc1f)		(float);
+typedef void (FX_CALL *pfunc2i)		(FxU32, FxU32);
+typedef void (FX_CALL *pfunc1i1p)	(FxU32, void*);
+typedef void (FX_CALL *pfunc2p)		(void*, void*);
+typedef void (FX_CALL *pfunc1i1f)	(FxU32, float);
+typedef void (FX_CALL *pfunc1p1f)	(void*, float);
+typedef void (FX_CALL *pfunc3i)		(FxU32, FxU32, FxU32);
+typedef void (FX_CALL *pfunc2i1p)	(FxU32, FxU32, void*);
+typedef void (FX_CALL *pfunc1i2p)	(FxU32, void*, void*);
+typedef void (FX_CALL *pfunc3p)		(void*, void*, void*);
+typedef void (FX_CALL *pfunc1p2f)	(void*, float, float);
+typedef void (FX_CALL *pfunc4i)		(FxU32, FxU32, FxU32, FxU32);
+typedef void (FX_CALL *pfunc3i1p)	(FxU32, FxU32, FxU32, void*);
+typedef void (FX_CALL *pfunc3i1f)	(FxU32, FxU32, FxU32, float);
+typedef void (FX_CALL *pfunc4f)		(float, float, float, float);
+typedef void (FX_CALL *pfunc5i)		(FxU32, FxU32, FxU32, FxU32, FxU32);
+typedef void (FX_CALL *pfunc2i1p2i)	(FxU32, FxU32, void*, FxU32, FxU32);
+typedef void (FX_CALL *pfunc4f1i)	(float, float, float, float, FxU32);
+typedef void (FX_CALL *pfunc3p3i)	(void*, void*, void*, FxU32, FxU32, FxU32);
+typedef void (FX_CALL *pfunc7i)		(FxU32, FxU32, FxU32, FxU32, FxU32, FxU32, FxU32);
+typedef void (FX_CALL *pfunc7i1p)	(FxU32, FxU32, FxU32, FxU32, FxU32, FxU32, FxU32, void*);
+typedef void (FX_CALL *pfunc7i1p2i)	(FxU32, FxU32, FxU32, FxU32, FxU32, FxU32, FxU32, void*,
+					    FxU32, FxU32);
+typedef void (FX_CALL *pfunc7i1p7i1p)	(FxU32, FxU32, FxU32, FxU32, FxU32, FxU32, FxU32, void*,
+					    FxU32, FxU32, FxU32, FxU32, FxU32, FxU32, FxU32, void*);
+
+typedef FxU32 (FX_CALL *prfunc0)		(void);
+typedef FxU32 (FX_CALL *prfunc1i)	(FxU32);
+typedef FxU32 (FX_CALL *prfunc1p)	(void*);
+typedef FxU32 (FX_CALL *prfunc2i)	(FxU32, FxU32);
+typedef FxU32 (FX_CALL *prfunc1i1p)	(FxU32, void*);
+typedef FxU32 (FX_CALL *prfunc2p)	(void*, void*);
+typedef FxU32 (FX_CALL *prfunc4i)	(FxU32, FxU32, FxU32, FxU32);
+typedef FxU32 (FX_CALL *prfunc5i1p)	(FxU32, FxU32, FxU32, FxU32, FxU32, void*);
+typedef FxU32 (FX_CALL *prfunc7i)	(FxU32, FxU32, FxU32, FxU32, FxU32, FxU32, FxU32);
+typedef FxU32 (FX_CALL *prfunc1p6i)	(void*, FxU32, FxU32, FxU32, FxU32, FxU32, FxU32);
+typedef FxU32 (FX_CALL *prfunc6i1p)	(FxU32, FxU32, FxU32, FxU32, FxU32, FxU32, void*);
+typedef FxU32 (FX_CALL *prfunc7i1p)	(FxU32, FxU32, FxU32, FxU32, FxU32, FxU32, FxU32, void*);
+typedef FxU32 (FX_CALL *prfunc12i)	(FxU32, FxU32, FxU32, FxU32, FxU32, FxU32, FxU32,
+					    FxU32, FxU32, FxU32, FxU32, FxU32);
+typedef FxU32 (FX_CALL *prfunc13i1f1i)	(FxU32, FxU32, FxU32, FxU32, FxU32, FxU32, FxU32, FxU32,
+					    FxU32, FxU32, FxU32, FxU32, FxU32, float, FxU32);
+
+typedef void* (FX_CALL *prptfunc1i)	(FxU32);
+typedef float (FX_CALL *pffunc1i)	(FxU32);
+
+typedef union {
+    pfunc0	grFunction0;
+    pfunc1i	grFunction1i;
+    pfunc1p	grFunction1p;
+    pfunc1f	grFunction1f;
+    pfunc2i	grFunction2i;
+    pfunc1i1p	grFunction1i1p;
+    pfunc2p	grFunction2p;
+    pfunc1i1f	grFunction1i1f;
+    pfunc1p1f	grFunction1p1f;
+    pfunc3i	grFunction3i;
+    pfunc2i1p	grFunction2i1p;
+    pfunc1i2p	grFunction1i2p;
+    pfunc3p	grFunction3p;
+    pfunc1p2f	grFunction1p2f;
+    pfunc4i	grFunction4i;
+    pfunc3i1p	grFunction3i1p;
+    pfunc3i1f	grFunction3i1f;
+    pfunc4f	grFunction4f;
+    pfunc5i	grFunction5i;
+    pfunc2i1p2i	grFunction2i1p2i;
+    pfunc4f1i	grFunction4f1i;
+    pfunc3p3i	grFunction3p3i;
+    pfunc7i	grFunction7i;
+    pfunc7i1p	grFunction7i1p;
+    pfunc7i1p2i	grFunction7i1p2i;
+    pfunc7i1p7i1p grFunction7i1p7i1p;
+
+    prfunc0	grRFunction0;
+    prfunc1i	grRFunction1i;
+    prfunc1p	grRFunction1p;
+    prfunc2i	grRFunction2i;
+    prfunc1i1p	grRFunction1i1p;
+    prfunc2p	grRFunction2p;
+    prfunc4i	grRFunction4i;
+    prfunc5i1p	grRFunction5i1p;
+    prfunc7i	grRFunction7i;
+    prfunc1p6i	grRFunction1p6i;
+    prfunc6i1p	grRFunction6i1p;
+    prfunc7i1p	grRFunction7i1p;
+    prfunc12i	grRFunction12i;
+    prfunc13i1f1i grRFunction13i1f1i;
+
+    prptfunc1i	grRPTFunction1i;
+
+    pffunc1i	grFFunction1i;
+} FncPointers;
+
+static const GLIDE_TABLE grTable[] = {
+    { "grAADrawLine", 8 },
+    { "grAADrawPoint", 4 },
+    { "grAADrawPolygon", 12 },
+    { "grAADrawPolygonVertexList", 8 },
+    { "grAADrawTriangle", 24 },
+    { "grAlphaBlendFunction", 16 },
+    { "grAlphaCombine", 20 },
+    { "grAlphaControlsITRGBLighting", 4 },
+    { "grAlphaTestFunction", 4 },
+    { "grAlphaTestReferenceValue", 4 },
+    { "grBufferClear", 12 },
+    { "grBufferNumPending", 0 },
+    { "grBufferSwap", 4 },
+    { "grCheckForRoom", 4 },
+    { "grChromakeyMode", 4 },
+    { "grChromakeyValue", 4 },
+    { "grClipWindow", 16 },
+    { "grColorCombine", 20 },
+    { "grColorMask", 8 },
+    { "grConstantColorValue4", 16 },
+    { "grConstantColorValue", 4 },
+    { "grCullMode", 4 },
+    { "grDepthBiasLevel", 4 },
+    { "grDepthBufferFunction", 4 },
+    { "grDepthBufferMode", 4 },
+    { "grDepthMask", 4 },
+    { "grDisableAllEffects", 0 },
+    { "grDitherMode", 4 },
+    { "grDrawLine", 8 },
+    { "grDrawPlanarPolygon", 12 },
+    { "grDrawPlanarPolygonVertexList", 8 },
+    { "grDrawPoint", 4 },
+    { "grDrawPolygon", 12 },
+    { "grDrawPolygonVertexList", 8 },
+    { "grDrawTriangle", 12 },
+    { "grErrorSetCallback", 4 },
+    { "grFogColorValue", 4 },
+    { "grFogMode", 4 },
+    { "grFogTable", 4 },
+    { "grGammaCorrectionValue", 4 },
+    { "grGlideGetState", 4 },
+    { "grGlideGetVersion", 4 },
+    { "grGlideInit", 0 },
+    { "grGlideSetState", 4 },
+    { "grGlideShamelessPlug", 4 },
+    { "grGlideShutdown", 0 },
+    { "grHints", 8 },
+    { "grLfbConstantAlpha", 4 },
+    { "grLfbConstantDepth", 4 },
+    { "grLfbLock", 24 },
+    { "grLfbReadRegion", 28 },
+    { "grLfbUnlock", 8 },
+    { "grLfbWriteColorFormat", 4 },
+    { "grLfbWriteColorSwizzle", 8 },
+    { "grLfbWriteRegion", 32 },
+    { "grRenderBuffer", 4 },
+    { "grResetTriStats", 0 },
+    { "grSplash", 20 },
+    { "grSstConfigPipeline", 12 },
+    { "grSstControl", 4 },
+    { "grSstIdle", 0 },
+    { "grSstIsBusy", 0 },
+    { "grSstOrigin", 4 },
+    { "grSstPerfStats", 4 },
+    { "grSstQueryBoards", 4 },
+    { "grSstQueryHardware", 4 },
+    { "grSstResetPerfStats", 0 },
+    { "grSstScreenHeight", 0 },
+    { "grSstScreenWidth", 0 },
+    { "grSstSelect", 4 },
+    { "grSstStatus", 0 },
+    { "grSstVRetraceOn", 0 },
+    { "grSstVidMode", 8 },
+    { "grSstVideoLine", 0 },
+    { "grSstWinClose", 0 },
+    { "grSstWinOpen", 28 },
+    { "grTexCalcMemRequired", 16 },
+    { "grTexClampMode", 12 },
+    { "grTexCombine", 28 },
+    { "grTexCombineFunction", 8 },
+    { "grTexDetailControl", 16 },
+    { "grTexDownloadMipMap", 16 },
+    { "grTexDownloadMipMapLevel", 32 },
+    { "grTexDownloadMipMapLevelPartial", 40 },
+    { "grTexDownloadTable", 12 },
+    { "grTexDownloadTablePartial", 20 },
+    { "grTexFilterMode", 12 },
+    { "grTexLodBiasValue", 8 },
+    { "grTexMaxAddress", 4 },
+    { "grTexMinAddress", 4 },
+    { "grTexMipMapMode", 12 },
+    { "grTexMultibase", 8 },
+    { "grTexMultibaseAddress", 20 },
+    { "grTexNCCTable", 8 },
+    { "grTexSource", 16 },
+    { "grTexTextureMemRequired", 8 },
+    { "grTriStats", 8 },
+    { "gu3dfGetInfo", 8 },
+    { "gu3dfLoad", 8 },
+    { "guAADrawTriangleWithClip", 12 },
+    { "guAlphaSource", 4 },
+    { "guColorCombineFunction", 4 },
+    { "guDrawPolygonVertexListWithClip", 8 },
+    { "guDrawTriangleWithClip", 12 },
+    { "guEncodeRLE16", 16 },
+    { "guEndianSwapBytes", 4 },
+    { "guEndianSwapWords", 4 },
+    { "guFogGenerateExp2", 8 },
+    { "guFogGenerateExp", 8 },
+    { "guFogGenerateLinear", 12 },
+    { "guFogTableIndexToW", 4 },
+    { "guMPDrawTriangle", 12 },
+    { "guMPInit", 0 },
+    { "guMPTexCombineFunction", 4 },
+    { "guMPTexSource", 8 },
+    { "guMovieSetName", 4 },
+    { "guMovieStart", 0 },
+    { "guMovieStop", 0 },
+    { "guTexAllocateMemory", 60 },
+    { "guTexChangeAttributes", 48 },
+    { "guTexCombineFunction", 8 },
+    { "guTexCreateColorMipMap", 0 },
+    { "guTexDownloadMipMap", 12 },
+    { "guTexDownloadMipMapLevel", 12 },
+    { "guTexGetCurrentMipMap", 4 },
+    { "guTexGetMipMapInfo", 4 },
+    { "guTexMemQueryAvail", 4 },
+    { "guTexMemReset", 0 },
+    { "guTexSource", 4 },
+    { "ConvertAndDownloadRle", 64 }
+};
+
+#endif // DOSBOX_GLIDE_H
--- a/include/mem.h
+++ b/include/mem.h
@@ -173,6 +173,8 @@ static INLINE Bit32u phys_readd(PhysPt a
 
 void MEM_BlockWrite(PhysPt pt,void const * const data,Bitu size);
 void MEM_BlockRead(PhysPt pt,void * data,Bitu size);
+void MEM_BlockWrite32(PhysPt pt,void * data,Bitu size);
+void MEM_BlockRead32(PhysPt pt,void * data,Bitu size);
 void MEM_BlockCopy(PhysPt dest,PhysPt src,Bitu size);
 void MEM_StrCopy(PhysPt pt,char * data,Bitu size);
 
--- a/src/dosbox.cpp
+++ b/src/dosbox.cpp
@@ -81,6 +81,7 @@ void PCI_Init(Section*);
 
 void KEYBOARD_Init(Section*);	//TODO This should setup INT 16 too but ok ;)
 void JOYSTICK_Init(Section*);
+void GLIDE_Init(Section*);
 void MOUSE_Init(Section*);
 void SBLASTER_Init(Section*);
 void GUS_Init(Section*);
@@ -749,6 +750,17 @@ void DOSBOX_Init(void) {
 	Pmulti_remain->Set_help("see serial1");
 
 
+	secprop=control->AddSection_prop("glide",&GLIDE_Init,true);
+	Pbool = secprop->Add_bool("glide",Property::Changeable::WhenIdle,false);
+	Pbool->Set_help("Enable glide emulation: true,false.");
+	//Phex = secprop->Add_hex("grport",Property::Changeable::WhenIdle,0x600);
+	//Phex->Set_help("I/O port to use for host communication.");
+	Pstring = secprop->Add_string("lfb",Property::Changeable::WhenIdle,"full_noaux");
+	Pstring->Set_help("LFB access: full,full_noaux,read,read_noaux,write,write_noaux,none.\n"
+		"OpenGlide does not support locking aux buffer, please use _noaux modes.");
+	Pbool = secprop->Add_bool("splash",Property::Changeable::WhenIdle,true);
+	Pbool->Set_help("Show 3dfx splash screen (requires 3dfxSpl2.dll).");
+
 	/* All the DOS Related stuff, which will eventually start up in the shell */
 	secprop=control->AddSection_prop("dos",&DOS_Init,false);//done
 	secprop->AddInitFunction(&XMS_Init,true);//done
--- a/src/gui/sdlmain.cpp
+++ b/src/gui/sdlmain.cpp
@@ -50,6 +50,7 @@
 #include "cross.h"
 #include "control.h"
 #include "render.h"
+#include "glidedef.h"
 
 #define MAPPERFILE "mapper-" VERSION ".map"
 //#define DISABLE_JOYSTICK
@@ -620,6 +621,10 @@ check_gotbpp:
 
 
 void GFX_ResetScreen(void) {
+	if(glide.enabled) {
+		GLIDE_ResetScreen(true);
+		return;
+	}
 	GFX_Stop();
 	if (sdl.draw.callback)
 		(sdl.draw.callback)( GFX_CallBackReset );
@@ -1249,6 +1254,9 @@ void GFX_SwitchFullScreen(void) {
 		sticky_keys(true); //restore sticky keys to default state in windowed mode.
 #endif
 	}
+	if (glide.enabled)
+		GLIDE_ResetScreen();
+	else
 	GFX_ResetScreen();
 }
 
@@ -2184,7 +2192,7 @@ void GFX_Events() {
 			throw(0);
 			break;
 		case SDL_VIDEOEXPOSE:
-			if (sdl.draw.callback) sdl.draw.callback( GFX_CallBackRedraw );
+			if ((sdl.draw.callback) && (!glide.enabled)) sdl.draw.callback( GFX_CallBackRedraw );
 			break;
 #ifdef WIN32
 		case SDL_KEYDOWN:
@@ -2669,6 +2677,7 @@ int main(int argc, char* argv[]) {
 			if (strcmp(sdl_drv_name,"windib")==0) LOG_MSG("SDL_Init: Starting up with SDL windib video driver.\n          Try to update your video card and directx drivers!");
 		}
 #endif
+	glide.fullscreen = &sdl.desktop.fullscreen;
 	sdl.num_joysticks=SDL_NumJoysticks();
 
 	/* Parse configuration files */
--- a/src/hardware/glide.cpp
+++ b/src/hardware/glide.cpp
@@ -0,0 +1,1962 @@
+/*
+ *  Copyright (C) 2002-2013  The DOSBox Team
+ *
+ *  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.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "dosbox.h"
+#include "inout.h"
+#include "mem.h"
+#include "paging.h"
+#include "glide.h"
+#include "setup.h"
+#include "vga.h"
+#include "dos_inc.h"		/* for Drives[] */
+#include "control.h"
+#include "../dos/drives.h"
+
+#include <iomanip>
+#include <sstream>
+using namespace std;
+
+#include "SDL.h"
+
+#if defined (WIN32)
+#include "SDL_syswm.h"
+#include <windows.h>
+#include <Shlwapi.h>
+
+#ifdef _MSC_VER
+#pragma comment( lib, "Shlwapi" )
+#endif
+
+#else // *nix
+#include <dlfcn.h>
+
+#include <dirent.h>
+#include <errno.h>
+
+#endif
+
+extern void GFX_Stop(void);
+extern void GFX_ResetScreen(void);
+extern const char* RunningProgram;
+
+static float int_to_float(const Bit32u i)
+{
+    float f;
+    Bit32u i_native = SDL_SwapLE32(i);
+    SDL_memcpy(&f, &i_native, 4);
+    return f;
+}
+
+#define SAFE_DELETE(p)	{ if(p) { delete p; p = NULL; } }
+
+#define G_OK	1
+#define G_FAIL	0
+
+// Print debug messages
+#define LOG_GLIDE 0
+
+void VFILE_Remove(const char *name);
+static void process_msg(Bitu);
+
+/** Global Variables **/
+GLIDE_Block glide;
+
+//  Pointers to loaded routines
+static FncPointers FP;
+static void ** fn_pt=NULL;
+
+// Shared memory
+static Bit32u param[20];
+
+// Pointer to return value
+static PhysPt ret;
+static Bit16u ret_value;
+
+// Temporary texture buffer
+static Bit32u texsize=0;
+static void* texmem=NULL;
+
+static HostPt hwnd=NULL;
+static char lfbacc=0;
+
+// Tomb Rider shadow hack
+static Bit8u tomb = 0;
+static FxI32 GrOriginLocation = 0;
+
+#if defined (WIN32)
+static HINSTANCE hdll=NULL;	//  Handle to glide2x lib file
+#else
+static void * hdll=NULL;
+#endif
+
+#if LOG_GLIDE
+static int GLIDE_count[GLIDE_MAX+2];
+#endif
+
+static Bitu read_gl(Bitu port,Bitu iolen)
+{
+    Bitu r=ret_value;
+#if LOG_GLIDE
+    if(ret_value == G_OK)
+	LOG_MSG("Glide:Port read. Return address: 0x%x, value: %d", ret, mem_readd(ret));
+    else if(ret_value == G_FAIL)
+	LOG_MSG("Glide:Port read. Return address: 0x%x, value: %d. Writing G_FAIL to port", ret, mem_readd(ret));
+    else
+	LOG_MSG("Glide:Port read. Returning %hu", ret_value);
+#endif
+
+    ret_value = ret_value >> 8;
+
+    return r;
+}
+
+static void write_gl(Bitu port,Bitu val,Bitu iolen)
+{
+    static Bit16u glsegment = 0;
+
+    ret = 0;
+    ret_value = G_FAIL;
+    FP.grFunction0 = NULL;
+
+    // Allocate shared memory (80 bytes)
+    if(val > GLIDE_MAX) {
+	if(glsegment==0) {
+	    glsegment=DOS_GetMemory(5);
+#if LOG_GLIDE
+	    LOG_MSG("Glide:Memory allocated at 0x%x (segment: %hu)", glsegment<<4, glsegment);
+#endif
+	}
+	ret_value=glsegment;
+	LOG_MSG("Glide:Activated");
+	return;
+    }
+
+    // Process function parameters (80 bytes)
+    MEM_BlockRead32(PhysMake(glsegment,0), param, 80);
+    process_msg(val);
+
+//  LOG_MSG("Glide:Function %s executed OK", grTable[val].name);
+}
+
+class GLIDE_PageHandler : public PageHandler {
+private:
+    PhysPt base_addr[GLIDE_BUFFERS];	// GLIDE_LFB physical address
+    PhysPt lin_addr[GLIDE_BUFFERS];	// GLIDE_LFB linear address
+    HostPt lfb_addr[GLIDE_BUFFERS];	// Address offset from base_addr for the readable/writable buffers
+
+    /* Calculate physical address for access */
+    #define LFB_getAddr(addr) (lfb_addr[((addr - base_addr[0])>>12)>>GLIDE_PAGE_BITS]+addr)
+
+public:
+
+    FxU8 locked[GLIDE_BUFFERS];
+
+    GLIDE_PageHandler(HostPt addr, PhysPt phyaddr = GLIDE_LFB) {
+
+	if(addr == NULL) {
+	    LOG_MSG("Glide:NULL address passed to pagehandler!");
+	}
+
+	/* Set base addresses */
+	for(int i = 0; i < GLIDE_BUFFERS; i++) {
+	    locked[i] = 0;
+	    base_addr[i] = phyaddr;
+	    phyaddr += ((1<<GLIDE_PAGE_BITS)<<12);
+
+	    /* store offset from base address */
+	    lfb_addr[i] = (addr == NULL) ? NULL : (addr - base_addr[i]);
+	}
+
+	flags=PFLAG_READABLE|PFLAG_WRITEABLE|PFLAG_NOCODE;
+	PAGING_UnlinkPages(base_addr[0]>>12, GLIDE_PAGES);
+#if LOG_GLIDE
+	LOG_MSG("Glide:GLIDE_PageHandler installed at 0x%x", base_addr[0]);
+#endif
+    }
+
+    ~GLIDE_PageHandler() {
+#if LOG_GLIDE
+	LOG_MSG("Glide:Resetting page handler at 0x%x", base_addr[0]);
+#endif
+	PAGING_UnlinkPages(base_addr[0]>>12, GLIDE_PAGES);
+    }
+
+    void SetLFBAddr(HostPt addr, Bitu buffer) {
+	if(buffer >= GLIDE_BUFFERS) return;
+
+	addr = addr - base_addr[buffer];	/* Calculate offset for current buffer */
+
+	if(addr != lfb_addr[buffer]) {
+	    lfb_addr[buffer] = addr;
+#if LOG_GLIDE
+	    LOG_MSG("Glide:LFB for buffer %d offset set to 0x%p (addr: 0x%p), clear TLB", buffer, lfb_addr[buffer], addr+base_addr[buffer]);
+#endif
+	    PAGING_UnlinkPages(base_addr[buffer]>>12, 1<<GLIDE_PAGE_BITS);
+	}
+    }
+
+    PhysPt GetPhysPt(Bitu buffer = 0) {
+	if(buffer >= GLIDE_BUFFERS) return base_addr[0];
+	return base_addr[buffer];
+    }
+
+    void SetLinPt(PhysPt linaddr) {
+	for(int i = 0; i < GLIDE_BUFFERS; i++) {
+	    lin_addr[i] = linaddr;
+	    linaddr += ((1<<GLIDE_PAGE_BITS)<<12);
+	}
+    }
+
+    PhysPt GetLinPt(Bitu buffer = 0) {
+	if(buffer >= GLIDE_BUFFERS) return lin_addr[0];
+	return lin_addr[buffer];
+    }
+
+    Bitu readb(PhysPt addr) {
+//	LOG_MSG("Glide:Read from 0x%p", LFB_getAddr(addr));
+	return *(Bit8u *)(LFB_getAddr(addr));
+    }
+
+    Bitu readw(PhysPt addr) {
+//	LOG_MSG("Glide:Read from 0x%p", LFB_getAddr(addr));
+	return *(Bit16u *)(LFB_getAddr(addr));
+    }
+
+    Bitu readd(PhysPt addr) {
+//	LOG_MSG("Glide:Read from 0x%p", LFB_getAddr(addr));
+	return *(Bit32u *)(LFB_getAddr(addr));
+    }
+
+    void writeb(PhysPt addr,Bitu val) {
+//	LOG_MSG("Glide:Write to 0x%p", LFB_getAddr(addr));
+	*(Bit8u *)(LFB_getAddr(addr))=(Bit8u)val;
+    }
+
+    void writew(PhysPt addr,Bitu val) {
+//	LOG_MSG("Glide:Write to 0x%p", LFB_getAddr(addr));
+	*(Bit16u *)(LFB_getAddr(addr))=(Bit16u)val;
+    }
+
+    void writed(PhysPt addr,Bitu val) {
+//	LOG_MSG("Glide:Write to 0x%p", LFB_getAddr(addr));
+	*(Bit32u *)(LFB_getAddr(addr))=(Bit32u)val;
+    }
+
+    HostPt GetHostReadPt(Bitu phys_page) {
+	Bitu buffer = (((phys_page<<12) - base_addr[0])>>12)>>GLIDE_PAGE_BITS;
+#if LOG_GLIDE
+	// This only makes sense if full lfb access is used...
+	if (!locked[buffer]) LOG_MSG("Glide:Read from unlocked LFB at: 0x%x", phys_page<<12);
+#endif
+//	LOG_MSG("Glide:GetHostReadPt called with %d, returning 0x%p", phys_page, LFB_getAddr((phys_page*MEM_PAGESIZE)));
+	return lfb_addr[buffer]+(phys_page<<12);
+    }
+
+    HostPt GetHostWritePt(Bitu phys_page) {
+	Bitu buffer = (((phys_page<<12) - base_addr[0])>>12)>>GLIDE_PAGE_BITS;
+#if LOG_GLIDE
+	// This only makes sense if full lfb access is used...
+	if (!locked[buffer]) LOG_MSG("Glide:Write to unlocked LFB at: 0x%x", phys_page<<12);
+#endif
+//	LOG_MSG("Glide:GetHostWritePt called with %d, returning 0x%p", phys_page, LFB_getAddr((phys_page*MEM_PAGESIZE)));
+	return lfb_addr[buffer]+(phys_page<<12);
+    }
+
+    #undef LFB_getAddr
+};
+
+class GLIDE: public Module_base {
+private:
+    AutoexecObject autoexecline;
+    // Glide port
+    Bitu glide_base;
+    Bit8u *ovl_data;
+public:
+    GLIDE(Section* configuration):Module_base(configuration),glide_base(0),ovl_data(NULL) {
+	Section_prop * section=static_cast<Section_prop *>(configuration);
+
+	if(!section->Get_bool("glide")) return;
+	std::string str = section->Get_string("lfb");
+	lowcase(str);
+	if(str == "none") {
+	    LOG_MSG("Glide:Disabled LFB access");
+	    lfbacc=0;
+	} else if(str == "read_noaux") {
+	    LOG_MSG("Glide:LFB access: read-only (no aux)");
+	    lfbacc=1;
+	} else if(str == "write_noaux") {
+	    LOG_MSG("Glide:LFB access: write-only (no aux)");
+	    lfbacc=2;
+	} else if(str == "full_noaux") {
+	    LOG_MSG("Glide:LFB access: read-write (no aux)");
+	    lfbacc=3;
+	} else if(str == "read") {
+	    LOG_MSG("Glide:LFB access: read-only");
+	    lfbacc=5;
+	} else if(str == "write") {
+	    LOG_MSG("Glide:LFB access: write-only");
+	    lfbacc=6;
+	} else {
+	    LOG_MSG("Glide:LFB access: read-write");
+	    lfbacc=7;
+	}
+
+	// Load glide2x.dll
+#if defined(WIN32)
+	hdll = LoadLibrary("glide2x.dll");
+#elif defined(MACOSX)
+	hdll = dlopen("libglide2x.dylib", RTLD_NOW);
+#else
+	hdll = dlopen("libglide2x.so", RTLD_NOW);
+#endif
+
+	if(!hdll) {
+	    LOG_MSG("Glide:Unable to load glide2x library, glide emulation disabled");
+	    return;
+	}
+
+	// Allocate some temporary space
+	texmem = (void*)malloc(1600*1200*4);
+	if(texmem == NULL) {
+	    LOG_MSG("Glide:Unable to allocate texture memory, glide disabled");
+	    return;
+	}
+
+	glide.lfb_pagehandler = new GLIDE_PageHandler((HostPt)texmem);
+	if(!glide.lfb_pagehandler) {
+	    LOG_MSG("Glide:Failed to install page handler, glide disabled!");
+	    free(texmem); texmem = NULL;
+	    return;
+	}
+
+	// Load glide2x.ovl if possible, so it is available on the Z: drive
+	const char ovl_name[] = "glide2x.ovl";
+
+#if defined (WIN32)
+	// Windows is simple, the search is case insensitive
+	FILE * ovl = fopen(ovl_name, "rb");
+
+	// if not successful try to specifically search dosbox directory
+	if (ovl == NULL) {
+	    char * path = (char*)texmem;
+	    GetModuleFileName(NULL, path, 32768);
+	    // strip "\dosbox.exe" from path
+	    PathRemoveFileSpec(path);
+	    strcat(path, "\\"); strcat(path, ovl_name);
+	    ovl = fopen(path, "rb");
+	}
+
+#else
+	// Try a bit harder in *nix, perform case insensitive search and check /usr/share/dosbox as well
+	DIR * pdir; struct dirent * pfile;
+	char * path = (char*)texmem;
+	FILE * ovl = NULL;
+
+	const char * const dirname[] = { "./", "/usr/share/dosbox/", NULL };
+
+	for (int i = 0; dirname[i]; i++) {
+	    if((pdir = opendir(dirname[i]))) {
+		while(pfile = readdir(pdir)) {
+		    if(!strcasecmp(pfile->d_name, ovl_name)) {
+			strcpy(path, dirname[i]); strcat(path, pfile->d_name);
+			ovl = fopen(path, "rb");
+			if(ovl) break;
+		    }
+		}
+		closedir(pdir);
+		if(ovl) break;
+	    }
+	}
+#endif
+
+	long ovl_size = 0;
+
+	if(ovl == NULL) {
+	    LOG_MSG("Glide:GLIDE2X.OVL could not be found, make sure correct (compatible) version is in the game directory!");
+	} else {
+	    fseek(ovl, 0, SEEK_END);
+	    ovl_size=ftell(ovl);
+	    ovl_data=(Bit8u*)malloc(ovl_size);
+	    fseek(ovl, 0, SEEK_SET);
+	    fread(ovl_data, sizeof(char), ovl_size, ovl);
+	    fclose(ovl);
+	}
+
+#if LOG_GLIDE
+	SDL_memset(GLIDE_count, 0, sizeof(GLIDE_count));
+#endif
+
+	// Allocate memory for dll pointers
+	fn_pt = (void**)malloc(sizeof(void*)*(GLIDE_MAX+1));
+	if(fn_pt == NULL) {
+	    LOG_MSG("Glide:Unable to allocate memory, glide disabled");
+	    free(texmem); texmem = NULL;
+	    if(ovl_data) free(ovl_data); ovl_data = NULL;
+	    return;
+	}
+
+	for(int i=0; i<(GLIDE_MAX+1); i++) {
+#if defined(WIN32)
+	    ostringstream temp;
+	    // Add function decoration
+	    temp << "_" << grTable[i].name << "@" << (Bitu)grTable[i].parms;
+	    fn_pt[i] = (void*)(GetProcAddress(hdll, temp.str().c_str()));
+#else
+	    fn_pt[i] = (void*)(dlsym(hdll, grTable[i].name));
+#endif
+#if LOG_GLIDE
+	    if(fn_pt[i] == NULL) {
+		LOG_MSG("Glide:Warning, unable to load %s from glide2x", grTable[i].name);
+	    }
+#endif
+	}
+
+	//glide_base=section->Get_hex("grport");
+	glide_base=0x600;	// Anybody else got a better idea?
+
+	IO_RegisterReadHandler(glide_base,read_gl,IO_MB);
+	IO_RegisterWriteHandler(glide_base,write_gl,IO_MB);
+
+	ostringstream temp;
+	temp << "SET GLIDE=" << hex << glide_base << ends;
+
+	autoexecline.Install(temp.str());
+	glide.splash = section->Get_bool("splash");
+
+#if defined (WIN32)
+	// Get hwnd information
+	SDL_SysWMinfo wmi;
+	SDL_VERSION(&wmi.version);
+	if(SDL_GetWMInfo(&wmi)) {
+	    hwnd = (HostPt)wmi.window;
+	} else {
+	    LOG_MSG("SDL:Error retrieving window information");
+	}
+#endif
+
+	if(ovl_data) {
+	    VFILE_Register("GLIDE2X.OVL", ovl_data, ovl_size);
+	}
+    }
+
+    ~GLIDE() {
+	if(glide.enabled) {
+	    // void grGlideShutdown(void)
+	    FP.grFunction0 = (pfunc0)fn_pt[_grGlideShutdown0];
+	    if(FP.grFunction0) FP.grFunction0();
+	    glide.enabled = false;
+	}
+
+	SAFE_DELETE(glide.lfb_pagehandler);
+	if(fn_pt)
+	    free(fn_pt); fn_pt = NULL;
+	if(texmem)
+	    free(texmem); texmem = NULL;
+
+	if(glide_base) {
+	    IO_FreeReadHandler(glide_base,IO_MB);
+	    IO_FreeWriteHandler(glide_base,IO_MB);
+	}
+
+	if(hdll) {
+#if defined (WIN32)
+	    FreeLibrary(hdll);
+#else
+	    dlclose(hdll);
+#endif
+	    hdll = NULL;
+	}
+
+	VFILE_Remove("GLIDE2X.OVL");
+	if(ovl_data) free(ovl_data);
+    }
+};
+
+static GLIDE* test;
+void GLIDE_ShutDown(Section* sec) {
+    delete test;
+}
+
+void GLIDE_Init(Section* sec) {
+    test = new GLIDE(sec);
+    sec->AddDestroyFunction(&GLIDE_ShutDown,true);
+}
+
+void GLIDE_ResetScreen(bool update)
+{
+#if LOG_GLIDE
+	LOG_MSG("Glide:ResetScreen");
+#endif
+	VGA_SetOverride(true);
+	GFX_Stop();
+
+	// OpenGlide will resize the window on it's own (using SDL)
+	if(glide.width && (
+#ifdef WIN32
+	// dgVoodoo needs a little help :)
+	// Most other wrappers render fullscreen by default
+	  (GetProcAddress(hdll, "DispatchDosNT") != NULL) ||
+#endif
+	// and resize when mapper and/or GUI finish
+	  update)) {
+	    SDL_SetVideoMode(glide.width,glide.height,0,
+		(glide.fullscreen[0]?SDL_FULLSCREEN:0)|SDL_ANYFORMAT|SDL_SWSURFACE);
+	}
+}
+
+void GLIDE_DisableScreen(void)
+{
+	glide.enabled = false;	/* if not disabled, GFX_ResetScreen() will call GLIDE_ResetScreen() */
+	VGA_SetOverride(false);
+	GFX_ResetScreen();
+}
+
+static bool GetFileName(char * filename)
+{
+    localDrive	*ldp;
+    Bit8u	drive;
+    char	fullname[DOS_PATHLENGTH];
+
+    // Get full path
+    if(!DOS_MakeName(filename,fullname,&drive)) return false;
+
+#if LOG_GLIDE
+    LOG_MSG("Glide:Fullname: %s", fullname);
+#endif
+
+    // Get real system path
+    ldp = dynamic_cast<localDrive*>(Drives[drive]);
+    if(ldp == NULL) return false;
+
+    ldp->GetSystemFilename(filename,fullname);
+#if LOG_GLIDE
+    LOG_MSG("Glide:System path: %s", filename);
+#endif
+    return true;
+}
+
+typedef FxBool (FX_CALL *pfxSplashInit)(FxU32 hWnd, FxU32 screenWidth, FxU32 screenHeight,
+					FxU32 numColBuf, FxU32 numAuxBuf, GrColorFormat_t colorFormat);
+typedef void (FX_CALL *pfxSplash)(float x, float y, float w, float h, FxU32 frameNumber);
+
+static void grSplash(void)
+{
+#ifdef WIN32
+    FxU32 screenWidth = glide.width, screenHeight = glide.height;
+    HINSTANCE dll = LoadLibrary("3dfxSpl2.dll");
+    if(dll == NULL) {
+	return;
+    }
+
+    pfxSplashInit fxSplashInit = (pfxSplashInit)GetProcAddress(dll, "_fxSplashInit@24");
+    pfxSplash fxSplash = (pfxSplash)GetProcAddress(dll, "_fxSplash@20");
+
+    if((fxSplashInit == NULL) || (fxSplash == NULL)) {
+	FreeLibrary(dll);
+	return;
+    }
+
+    if (screenWidth == 0) {
+	screenWidth = 640;
+	screenHeight = 480;
+    }
+
+    fxSplashInit(0, screenWidth, screenHeight, 2, 1, GR_COLORFORMAT_ABGR);
+    fxSplash(0, 0, screenWidth, screenHeight, 0);
+
+    // OpenGlide does not restore this state
+    FP.grFunction1i = (pfunc1i)fn_pt[_grSstOrigin4];
+    if(FP.grFunction1i) {
+	FP.grFunction1i(GrOriginLocation);
+    }
+
+    FreeLibrary(dll);
+#endif
+}
+
+static void process_msg(Bitu value)
+{
+    GrLfbInfo_t   lfbinfo;
+    DBGrLfbInfo_t dblfbinfo;
+
+    GrTexInfo     texinfo;
+    DBGrTexInfo   dbtexinfo;
+
+    Gu3dfInfo     guinfo;
+    DBGu3dfInfo   dbguinfo;
+
+    GrVertex      vertex[3];
+
+    GrMipMapInfo * mipmap;
+
+    // Temporary memory used in functions
+    FxI32	* ilist = (FxI32*)texmem;
+    FxU16	* ptr16 = (FxU16*)texmem;
+
+    // Filename translation
+    char	  filename[512];
+
+    // Used so that the pagehandler returns the same address after buffer swap
+    static char	  b_swap = 0;
+
+    // Return value address
+    ret = param[0];
+    Bitu i = value;
+    Bitu buffer;
+    FxU32 j, k;
+
+    if((i > GLIDE_MAX) || (fn_pt[i] == NULL)) {
+	LOG_MSG("Glide:Invalid function pointer for call %s", (i > GLIDE_MAX) ? "(invalid)" : grTable[i].name);
+	return;
+    }
+
+#if LOG_GLIDE
+    LOG_MSG("Glide:Processing call %s (%d), return address: 0x%x", grTable[i].name, value, ret);
+    GLIDE_count[i]++;
+#endif
+
+    switch (value) {
+
+    case _grAADrawLine8:
+	// void grAADrawLine(GrVertex *va, GrVertex *vb)
+	FP.grFunction2p = (pfunc2p)fn_pt[i];
+	MEM_BlockRead32(param[1], &vertex[0], sizeof(GrVertex));
+	MEM_BlockRead32(param[2], &vertex[1], sizeof(GrVertex));
+	FP.grFunction2p(&vertex[0], &vertex[1]);
+	break;
+    case _grAADrawPoint4:
+	// void grAADrawPoint(GrVertex *p)
+	FP.grFunction1p = (pfunc1p)fn_pt[i];
+	MEM_BlockRead32(param[1], &vertex[0], sizeof(GrVertex));
+	FP.grFunction1p(&vertex[0]);
+	break;
+    case _grAADrawPolygon12:
+	// void grAADrawPolygon(int nVerts, const int ilist[], const GrVertex vlist[])
+	FP.grFunction1i2p = (pfunc1i2p)fn_pt[i];
+	i = sizeof(FxI32)*param[1];
+	MEM_BlockRead32(param[2], ilist, i);
+
+	// Find the number of vertices (?)
+	k = 0;
+	for(j = 0; j < param[1]; j++) {
+	    if(ilist[j] > k)
+		k = ilist[j];
+	}
+	k++;
+
+	MEM_BlockRead32(param[3], ilist+i, sizeof(GrVertex)*k);
+	FP.grFunction1i2p(param[1], ilist, ilist+i);
+	break;
+    case _grAADrawPolygonVertexList8:
+	// void grAADrawPolygonVertexList(int nVerts, const GrVertex vlist[])
+	FP.grFunction1i1p = (pfunc1i1p)fn_pt[i];
+	MEM_BlockRead32(param[2], texmem, sizeof(GrVertex)*param[1]);
+	FP.grFunction1i1p(param[1], texmem);
+	break;
+    case _grAADrawTriangle24:
+	// void grAADrawTriangle(GrVertex *a, GrVertex *b, GrVertex *c,
+	//	FxBool antialiasAB, FxBool antialiasBC, FxBool antialiasCA)
+	FP.grFunction3p3i = (pfunc3p3i)fn_pt[i];
+	MEM_BlockRead32(param[1], &vertex[0], sizeof(GrVertex));
+	MEM_BlockRead32(param[2], &vertex[1], sizeof(GrVertex));
+	MEM_BlockRead32(param[3], &vertex[2], sizeof(GrVertex));
+	FP.grFunction3p3i(&vertex[0], &vertex[1], &vertex[2], param[4], param[5], param[6]);
+	break;
+    case _grAlphaBlendFunction16:
+	// void grAlphaBlendFunction(GrAlphaBlendFnc_t rgb_sf, GrAlphaBlendFnc_t rgb_df,
+	//		GrAlphaBlendFnc_t alpha_sf, GrAlphaBlendFnc_t alpha_df)
+	if(tomb == 1) {
+	    if((FP.grFunction1i = (pfunc1i)fn_pt[_grConstantColorValue4]))
+		FP.grFunction1i(0x7f000000);
+	} else if(tomb == 2) {
+	    float color1 = 127.0;
+	    float color2 = 0.0;
+	    if((FP.grFunction4f = (pfunc4f)fn_pt[_grConstantColorValue416]))
+		FP.grFunction4f(color1, color2, color2, color2);
+	}
+	FP.grFunction4i = (pfunc4i)fn_pt[i];
+	FP.grFunction4i(param[1], param[2], param[3], param[4]);
+	break;
+    case _grAlphaCombine20:
+	// void grAlphaCombine(GrCombineFunction_t func, GrCombineFactor_t factor,
+	//		GrCombineLocal_t local, GrCombineOther_t other, FxBool invert)
+	FP.grFunction5i = (pfunc5i)fn_pt[i];
+	FP.grFunction5i(param[1], param[2], param[3], param[4], param[5]);
+	break;
+    case _grAlphaControlsITRGBLighting4:
+	// void grAlphaControlsITRGBLighting(FxBool enable)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	break;
+    case _grAlphaTestFunction4:
+	// void grAlphaTestFunction(GrCmpFnc_t function)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	break;
+    case _grAlphaTestReferenceValue4:
+	// void grAlphaTestReferenceValue(GrAlpha_t value)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	break;
+    case _grBufferClear12:
+	// void grBufferClear(GrColor_t color, GrAlpha_t alpha, FxU16 depth)
+	FP.grFunction3i = (pfunc3i)fn_pt[i];
+	FP.grFunction3i(param[1], param[2], param[3]);
+	break;
+    case _grBufferNumPending0:
+	// int grBufferNumPending(void)
+	FP.grRFunction0 = (prfunc0)fn_pt[i];
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+	mem_writed(ret, FP.grRFunction0());
+	ret_value = G_OK;
+	break;
+    case _grBufferSwap4:
+	// void grBufferSwap(int swap_interval)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	/* Breaks Extreme Assault (which always writes to same address ?) */
+	//if(!(glide.lfb_pagehandler->locked[0] || glide.lfb_pagehandler->locked[1])) b_swap = !b_swap;
+#if LOG_GLIDE
+	LOG_MSG("Glide:BufferSwap (0x%x)", b_swap);
+#endif
+	break;
+    case _grCheckForRoom4:
+	// void grCheckForRoom(FxI32 n)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	break;
+    case _grChromakeyMode4:
+	// void grChromakeyMode(GrChromakeyMode_t mode)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	break;
+    case _grChromakeyValue4:
+	// void grChromakeyValue(GrColor_t value)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	break;
+    case _grClipWindow16:
+	// void grClipWindow(FxU32 minx, FxU32 miny, FxU32 maxx, FxU32 maxy)
+	FP.grFunction4i = (pfunc4i)fn_pt[i];
+	FP.grFunction4i(param[1], param[2], param[3], param[4]);
+	break;
+    case _grColorCombine20:
+	// void grColorCombine(GrCombineFunction_t func, GrCombineFactor_t factor,
+	//		GrCombineLocal_t local, GrCombineOther_t other, FxBool invert)
+	FP.grFunction5i = (pfunc5i)fn_pt[i];
+	FP.grFunction5i(param[1], param[2], param[3], param[4], param[5]);
+	break;
+    case _grColorMask8:
+	// void grColorMask(FxBool rgb, FxBool alpha)
+	FP.grFunction2i = (pfunc2i)fn_pt[i];
+	FP.grFunction2i(param[1], param[2]);
+	break;
+    case _grConstantColorValue416:
+	// void grConstantColorValue4(float a, float r, float g, float b)
+	FP.grFunction4f = (pfunc4f)fn_pt[i];
+	FP.grFunction4f(int_to_float(param[1]), int_to_float(param[2]), int_to_float(param[3]), int_to_float(param[4]));
+	break;
+    case _grConstantColorValue4:
+	// void grConstantColorValue(GrColor_t color)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	break;
+    case _grCullMode4:
+	// void grCullMode(GrCullMode_t mode)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	break;
+    case _grDepthBiasLevel4:
+	// void grDepthBiasLevel(FxI16 level)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	break;
+    case _grDepthBufferFunction4:
+	// void grDepthBufferFunction(GrCmpFnc_t func)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	break;
+    case _grDepthBufferMode4:
+	// void grDepthBufferMode(GrDepthBufferMode_t mode)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	break;
+    case _grDepthMask4:
+	// void grDepthMask(FxBool enable)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	break;
+    case _grDisableAllEffects0:
+	// void grDisableAllEffects(void)
+	FP.grFunction0 = (pfunc0)fn_pt[i];
+	FP.grFunction0();
+	break;
+    case _grDitherMode4:
+	// void grDitherMode(GrDitherMode_t mode)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	break;
+    case _grDrawLine8:
+	// void grDrawLine(const GrVertex *a, const GrVertex *b)
+	FP.grFunction2p = (pfunc2p)fn_pt[i];
+	MEM_BlockRead32(param[1], &vertex[0], sizeof(GrVertex));
+	MEM_BlockRead32(param[2], &vertex[1], sizeof(GrVertex));
+	FP.grFunction2p(&vertex[0], &vertex[1]);
+	break;
+    case _grDrawPlanarPolygon12:
+	// void grDrawPlanarPolygon(int nVerts, int ilist[], const GrVertex vlist[])
+	FP.grFunction1i2p = (pfunc1i2p)fn_pt[i];
+	i = sizeof(FxI32)*param[1];
+	MEM_BlockRead32(param[2], ilist, i);
+
+	// Find the number of vertices (?)
+	k = 0;
+	for(j = 0; j < param[1]; j++) {
+	    if(ilist[j] > k)
+		k = ilist[j];
+	}
+	k++;
+
+	MEM_BlockRead32(param[3], ilist+i, sizeof(GrVertex)*k);
+	FP.grFunction1i2p(param[1], ilist, ilist+i);
+	break;
+    case _grDrawPlanarPolygonVertexList8:
+	// void grDrawPlanarPolygonVertexList(int nVertices, const GrVertex vlist[])
+	FP.grFunction1i1p = (pfunc1i1p)fn_pt[i];
+	MEM_BlockRead32(param[2], texmem, sizeof(GrVertex)*param[1]);
+	FP.grFunction1i1p(param[1], texmem);
+	break;
+    case _grDrawPoint4:
+	// void grDrawPoint(const GrVertex *a)
+	FP.grFunction1p = (pfunc1p)fn_pt[i];
+	MEM_BlockRead32(param[1], &vertex[0], sizeof(GrVertex));
+	FP.grFunction1p(&vertex[0]);
+	break;
+    case _grDrawPolygon12:
+	// void grDrawPolygon(int nVerts, int ilist[], const GrVertex vlist[])
+	FP.grFunction1i2p = (pfunc1i2p)fn_pt[i];
+	i = sizeof(FxI32)*param[1];
+	MEM_BlockRead32(param[2], ilist, i);
+
+	// Find the number of vertices (?)
+	k = 0;
+	for(j = 0; j < param[1]; j++) {
+	    if(ilist[j] > k)
+		k = ilist[j];
+	}
+	k++;
+
+	MEM_BlockRead32(param[3], ilist+i, sizeof(GrVertex)*k);
+	FP.grFunction1i2p(param[1], ilist, ilist+i);
+	break;
+    case _grDrawPolygonVertexList8:
+	// void grDrawPolygonVertexList(int nVerts, const GrVertex vlist[])
+	FP.grFunction1i1p = (pfunc1i1p)fn_pt[i];
+	MEM_BlockRead32(param[2], texmem, sizeof(GrVertex)*param[1]);
+	FP.grFunction1i1p(param[1], texmem);
+	break;
+    case _grDrawTriangle12:
+	// void grDrawTriangle(const GrVertex *a, const GrVertex *b, const GrVertex *c)
+	FP.grFunction3p = (pfunc3p)fn_pt[i];
+	MEM_BlockRead32(param[1], &vertex[0], sizeof(GrVertex));
+	MEM_BlockRead32(param[2], &vertex[1], sizeof(GrVertex));
+	MEM_BlockRead32(param[3], &vertex[2], sizeof(GrVertex));
+	FP.grFunction3p(&vertex[0], &vertex[1], &vertex[2]);
+	break;
+/*
+    case _grErrorSetCallback4:
+	// void grErrorSetCallback(void (*function)(const char *string, FxBool fatal))
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(*param[1]);
+	break;
+*/
+    case _grFogColorValue4:
+	// void grFogColorValue(GrColor_t value)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	break;
+    case _grFogMode4:
+	// void grFogMode(GrFogMode_t mode)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	break;
+    case _grFogTable4:
+	// void grFogTable(const GrFog_t grTable[GR_FOG_TABLE_SIZE])
+	FP.grFunction1p = (pfunc1p)fn_pt[i];
+	MEM_BlockRead32(param[1], texmem, sizeof(GrFog_t)*GR_FOG_TABLE_SIZE);
+	FP.grFunction1p(texmem);
+	break;
+    case _grGammaCorrectionValue4:
+	// void grGammaCorrectionValue(float value)
+	FP.grFunction1f = (pfunc1f)fn_pt[i];
+	FP.grFunction1f(int_to_float(param[1]));
+	break;
+    case _grGlideGetState4:
+	// void grGlideGetState(GrState *state)
+	FP.grFunction1p = (pfunc1p)fn_pt[i];
+	MEM_BlockRead32(param[1], texmem, sizeof(GrState));
+	FP.grFunction1p(texmem);
+	MEM_BlockWrite32(param[1], texmem, sizeof(GrState));
+	break;
+    case _grGlideGetVersion4:
+	// void grGlideGetVersion(char version[80])
+	FP.grFunction1p = (pfunc1p)fn_pt[i];
+	FP.grFunction1p(filename);
+	k = 0;
+	do {
+	    mem_writeb(param[1]++, filename[k++]);
+	} while(filename[k] != '\0');
+	mem_writeb(param[1], '\0');
+	break;
+    case _grGlideInit0:
+	// void grGlideInit(void)
+	if(glide.enabled) break;	/* Tie Break Tennis */
+	FP.grFunction0 = (pfunc0)fn_pt[i];
+	FP.grFunction0();
+
+	// Enable Tomb Rider displaying shadow
+	if(!strncasecmp(RunningProgram, "Tombub", 6)) tomb = 2;
+	else if(!strncasecmp(RunningProgram, "Tomb", 4)) tomb = 1;
+	else tomb = 0;
+
+	// Send LFB to the OVL (so it can map it in linear address)
+	if(mem_readd(param[1]) == 0xFFFFF1FB) {		// Find LFB magic
+	    mem_writed(param[1], glide.lfb_pagehandler->GetPhysPt());
+	    mem_writed(param[2], GLIDE_PAGES);
+	} else {
+	    LOG_MSG("Glide:Detected incompatible guest ovl/dll!");
+	}
+	break;
+    case _grGlideSetState4:
+	// void grGlideSetState(const GrState *state)
+	FP.grFunction1p = (pfunc1p)fn_pt[i];
+	MEM_BlockRead32(param[1], texmem, sizeof(GrState));
+	FP.grFunction1p(texmem);
+	MEM_BlockWrite32(param[1], texmem, sizeof(GrState));
+	break;
+    case _grGlideShamelessPlug4:
+	// void grGlideShamelessPlug(const FxBool on)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	break;
+    case _grGlideShutdown0: {
+	// void grGlideShutdown(void)
+	if(glide.enabled) {
+	    FP.grFunction0 = (pfunc0)fn_pt[_grSstWinClose0];
+	    FP.grFunction0();
+	    GLIDE_DisableScreen();
+	}
+	FP.grFunction0 = (pfunc0)fn_pt[i];
+	FP.grFunction0();
+
+	Section_prop *section=static_cast<Section_prop *>(control->GetSection("glide"));
+	if (section) glide.splash = section->Get_bool("splash");
+
+#if LOG_GLIDE
+	for(j=0;j<(GLIDE_MAX+1);j++) {
+	    if(GLIDE_count[j]) {
+		LOG_MSG("Glide:%6d calls function %s (%d)", GLIDE_count[j], grTable[j].name, j);
+	    }
+	}
+	LOG_MSG("Glide: %d framebuffer locks (%d read, %d write)", GLIDE_count[_grLfbLock24],
+	    GLIDE_count[GLIDE_MAX+1], GLIDE_count[_grLfbLock24] - GLIDE_count[GLIDE_MAX+1]);
+	SDL_memset(GLIDE_count, 0, sizeof(GLIDE_count));
+#endif
+	break;
+	}
+    case _grHints8:
+	// void grHints(GrHints_t type, FxU32 hintMask)
+	FP.grFunction2i = (pfunc2i)fn_pt[i];
+	FP.grFunction2i(param[1], param[2]);
+	break;
+    case _grLfbConstantAlpha4:
+	// void grLfbConstantAlpha(GrAlpha_t alpha)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	break;
+    case _grLfbConstantDepth4:
+	// void grLfbConstantDepth(FxU16 depth)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	break;
+    case _grLfbLock24:
+	// FxBool grLfbLock(GrLock_t type, GrBuffer_t buffer, GrLfbWriteMode_t writeMode,
+	//		GrOriginLocation_t origin, FxBool pixelPipeline, GrLfbInfo_t *info)
+	FP.grRFunction5i1p = (prfunc5i1p)fn_pt[i];
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+
+	buffer = (Bitu)param[2];
+	if (buffer >= GLIDE_BUFFERS) {
+	    LOG_MSG("Glide:Invalid buffer passed in grLfbLock (%d)", buffer);
+	    return;
+	}
+
+	// Buffer address should stay the same after BufferSwap, so check which buffer to lock
+	// (currently disabled, see _grBufferSwap4)
+	//if (buffer < 2) buffer = buffer ^ b_swap;
+
+	// Read parameters
+	MEM_BlockRead32(param[6], &dblfbinfo, sizeof(DBGrLfbInfo_t));
+	lfbinfo.size = sizeof(GrLfbInfo_t);
+	lfbinfo.origin = dblfbinfo.origin;
+	lfbinfo.lfbPtr = texmem;
+
+	k = FXTRUE;
+	j = param[1]&1; j++;
+	j = j&lfbacc;				// Check LFB access (j = 0 : fake lock)
+	if((buffer > 1) && (lfbacc < 4)) j = 0;	// Disable access to AUX buffers
+
+	if(j) {
+		// Lock the buffer
+		k = FP.grRFunction5i1p(param[1], param[2], param[3], param[4], param[5], &lfbinfo);
+		if(k == FXTRUE) {
+		    glide.lfb_pagehandler->locked[buffer]++;
+		    dblfbinfo.writeMode = lfbinfo.writeMode;
+		    dblfbinfo.strideInBytes = lfbinfo.strideInBytes;
+		    dblfbinfo.lfbPtr = glide.lfb_pagehandler->GetLinPt(buffer);
+		    MEM_BlockWrite32(param[6], &dblfbinfo, sizeof(DBGrLfbInfo_t));
+		} else {
+		    LOG_MSG("Glide:LFB Lock failed!");
+		    //k = FXFALSE;	// Lock failed ?
+		}
+	} else {
+		// else lock is faked (texmem used for read/write)
+		if(param[3] == GR_LFBWRITEMODE_ANY) dblfbinfo.writeMode = GR_LFBWRITEMODE_565;
+		else dblfbinfo.writeMode = param[3];
+
+		if(param[4] == GR_ORIGIN_ANY) dblfbinfo.origin = GR_ORIGIN_UPPER_LEFT;
+		else dblfbinfo.origin = param[4];
+
+		dblfbinfo.strideInBytes = ((glide.width>0) ? glide.width : 1600) * 4;
+		dblfbinfo.lfbPtr = glide.lfb_pagehandler->GetLinPt(buffer);
+
+		//if(!(param[1]&GR_LFB_WRITE_ONLY)) SDL_memset(texmem, 0, 1600*1200*4);	// Clear memory on read-lock
+
+		MEM_BlockWrite32(param[6], &dblfbinfo, sizeof(DBGrLfbInfo_t));
+	}
+
+	// Set LFB address for page handler to read from/write to
+	glide.lfb_pagehandler->SetLFBAddr((HostPt)lfbinfo.lfbPtr, buffer);
+	if(dblfbinfo.strideInBytes > 1600*4) LOG_MSG("Glide:WARNING LFB stride (%d) is larger than max supported: %d!", dblfbinfo.strideInBytes, 1600*4);
+
+	if(param[1]&GR_LFB_WRITE_ONLY) {	// Is a write-only lock
+#if LOG_GLIDE
+		LOG_MSG("Glide:W/O lock (%d). %s LFB: 0x%p. Returning 0x%x (stride: %d)", param[2], (j ? "Real" : "Fake"),
+			lfbinfo.lfbPtr, dblfbinfo.lfbPtr, dblfbinfo.strideInBytes);
+#endif
+	} else {	// Is a read-only lock
+#if LOG_GLIDE
+		LOG_MSG("Glide:R/O lock (%d). %s LFB: 0x%p. Returning 0x%x (stride: %d)", param[2], (j ? "Real" : "Fake"),
+			lfbinfo.lfbPtr, dblfbinfo.lfbPtr, dblfbinfo.strideInBytes);
+		GLIDE_count[GLIDE_MAX+1]++;
+#endif
+	}
+
+	mem_writed(ret, k);
+	ret_value = G_OK;
+	break;
+    case _grLfbReadRegion28:
+	// FxBool grLfbReadRegion(GrBuffer_t src_buffer, FxU32 src_x, FxU32 src_y, FxU32 src_width,
+	//		FxU32 src_height, FxU32 dst_stride, void *dst_data)
+	FP.grRFunction6i1p = (prfunc6i1p)fn_pt[i];
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+	mem_writed(ret, FP.grRFunction6i1p(param[1], param[2], param[3], param[4], param[5], param[6], ptr16));
+	MEM_BlockWrite(param[7], ptr16, param[5]*param[6]);
+	ret_value = G_OK;
+	break;
+    case _grLfbUnlock8:
+	// FxBool grLfbUnlock(GrLock_t type, GrBuffer_t buffer)
+	FP.grRFunction2i = (prfunc2i)fn_pt[i];
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle (%d)!", _grLfbUnlock8);
+	    return;
+	}
+	k = FXTRUE;
+	buffer = param[2];
+	if (buffer < 2) buffer = buffer ^ b_swap;
+#if LOG_GLIDE
+	LOG_MSG("Glide:LFB unlock buffer (%d), %d locks active", param[2], glide.lfb_pagehandler->locked[buffer]);
+#endif
+	if(glide.lfb_pagehandler->locked[buffer]) {
+	    k = FP.grRFunction2i(param[1], param[2]);
+	    glide.lfb_pagehandler->locked[buffer]--;
+	    glide.lfb_pagehandler->SetLFBAddr((HostPt)texmem, buffer);	// Reset page handler and clear TLB
+	} else {
+	    //k = FXFALSE;
+	}
+	mem_writed(ret, k);
+	ret_value = G_OK;
+	break;
+    case _grLfbWriteColorFormat4:
+	// void grLfbWriteColorFormat(GrColorFormat_t colorFormat)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	break;
+    case _grLfbWriteColorSwizzle8:
+	// void grLfbWriteColorSwizzle(FxBool swizzleBytes, FxBool swapWords)
+	FP.grFunction2i = (pfunc2i)fn_pt[i];
+	FP.grFunction2i(param[1], param[2]);
+	break;
+    case _grLfbWriteRegion32:
+	// FxBool grLfbWriteRegion(GrBuffer_t dst_buffer, FxU32 dst_x, FxU32 dst_y,
+	//	GrLfbSrcFmt_t src_format, FxU32 src_width, FxU32 src_height, FxU32 src_stride, void *src_data)
+	FP.grRFunction7i1p = (prfunc7i1p)fn_pt[i];
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+
+	MEM_BlockRead(param[8], ptr16, param[6]*param[7]);
+	mem_writed(ret, FP.grRFunction7i1p(param[1], param[2], param[3], param[4], param[5], param[6], param[7], ptr16));
+	ret_value = G_OK;
+	break;
+    case _grRenderBuffer4:
+	// void grRenderBuffer(GrBuffer_t buffer)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	break;
+    case _grResetTriStats0:
+	// void grResetTriStats()
+	FP.grFunction0 = (pfunc0)fn_pt[i];
+	FP.grFunction0();
+	break;
+    case _grSplash20:
+	// void grSplash(float x, float y, float width, float height, FxU32 frame)
+	FP.grFunction4f1i = (pfunc4f1i)fn_pt[i];
+	FP.grFunction4f1i(int_to_float(param[1]), int_to_float(param[2]), int_to_float(param[3]), int_to_float(param[4]), param[5]);
+	break;
+/*
+    case _grSstConfigPipeline12:
+	//
+	FP.grFunction3i = (pfunc3i)fn_pt[i];
+	FP.grFunction3i();
+	break;
+*/
+    case _grSstControl4:
+	// FxBool grSstControl(FxU32 code)
+	FP.grRFunction1i = (prfunc1i)fn_pt[i];
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+	mem_writed(ret, FP.grRFunction1i(param[1]));
+	ret_value = G_OK;
+	break;
+    case _grSstIdle0:
+	// void grSstIdle(void)
+	FP.grFunction0 = (pfunc0)fn_pt[i];
+	FP.grFunction0();
+	break;
+    case _grSstIsBusy0:
+	// FxBool grSstIsBusy(void)
+	FP.grRFunction0 = (prfunc0)fn_pt[i];
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+	mem_writed(ret, FP.grRFunction0());
+	ret_value = G_OK;
+	break;
+    case _grSstOrigin4:
+	// void grSstOrigin(GrOriginLocation_t origin)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	GrOriginLocation = param[1];
+	break;
+    case _grSstPerfStats4:
+	// void grSstPerfStats(GrSstPerfStats_t *pStats)
+	FP.grFunction1p = (pfunc1p)fn_pt[i];
+	MEM_BlockRead32(param[1], texmem, sizeof(GrSstPerfStats_t));
+	FP.grFunction1p(texmem);
+	MEM_BlockWrite32(param[1], texmem, sizeof(GrSstPerfStats_t));
+	break;
+    case _grSstQueryBoards4:
+	// FxBool grSstQueryBoards(GrHwConfiguration *hwConfig)
+	FP.grRFunction1p = (prfunc1p)fn_pt[i];
+	MEM_BlockRead32(param[1], texmem, sizeof(GrHwConfiguration));
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+	mem_writed(ret, FP.grRFunction1p(texmem));
+	MEM_BlockWrite32(param[1], texmem, sizeof(GrHwConfiguration));
+	ret_value = G_OK;
+	break;
+    case _grSstQueryHardware4:
+	// FxBool grSstQueryHardware(GrHwConfiguration *hwConfig)
+	FP.grRFunction1p = (prfunc1p)fn_pt[i];
+	MEM_BlockRead32(param[1], texmem, sizeof(GrHwConfiguration));
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+	mem_writed(ret, FP.grRFunction1p(texmem));
+	MEM_BlockWrite32(param[1], texmem, sizeof(GrHwConfiguration));
+	ret_value = G_OK;
+	break;
+    case _grSstResetPerfStats0:
+	// void grSstResetPerfStats(void)
+	FP.grFunction0 = (pfunc0)fn_pt[i];
+	FP.grFunction0();
+	break;
+    case _grSstScreenHeight0:
+	// FxU32 grSstScreenHeight(void)
+	FP.grRFunction0 = (prfunc0)fn_pt[i];
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+	mem_writed(ret, FP.grRFunction0());
+	ret_value = G_OK;
+	break;
+    case _grSstScreenWidth0:
+	// FxU32 grSstScreenWidth(void)
+	FP.grRFunction0 = (prfunc0)fn_pt[i];
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+	mem_writed(ret, FP.grRFunction0());
+	ret_value = G_OK;
+	break;
+    case _grSstSelect4:
+	// void grSstSelect(int which_sst)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	break;
+    case _grSstStatus0:
+	// FxU32 grSstStatus(void)
+	FP.grRFunction0 = (prfunc0)fn_pt[i];
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+	mem_writed(ret, FP.grRFunction0());
+	ret_value = G_OK;
+	break;
+    case _grSstVRetraceOn0:
+	// FxBool grSstVRetraceOn(void)
+	FP.grRFunction0 = (prfunc0)fn_pt[i];
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+	mem_writed(ret, FP.grRFunction0());
+	ret_value = G_OK;
+	break;
+/*
+    case _grSstVidMode8:
+	//
+	FP.grFunction2i = (pfunc2i)fn_pt[i];
+	FP.grFunction2i();
+	break;
+*/
+    case _grSstVideoLine0:
+	// FxU32 grSstVideoLine(void)
+	FP.grRFunction0 = (prfunc0)fn_pt[i];
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+	mem_writed(ret, FP.grRFunction0());
+	ret_value = G_OK;
+	break;
+    case _grSstWinClose0:
+	// void grSstWinClose(void)
+	FP.grFunction0 = (pfunc0)fn_pt[i];
+	FP.grFunction0();
+	if(glide.enabled) {
+	    GLIDE_DisableScreen();
+	}
+	break;
+    case _grSstWinOpen28:
+	// FxBool grSstWinOpen(FxU32 hwnd, GrScreenResolution_t res, GrScreenRefresh_t ref,
+	//	GrColorFormat_t cformat, GrOriginLocation_t org_loc, int num_buffers, int num_aux_buffers)
+	FP.grRFunction1p6i = (prfunc1p6i)fn_pt[i];
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+
+	/* Tie Break Tennis */
+	if(glide.enabled) {
+	    LOG_MSG("Glide:grSstWinOpen called when glide is active!");
+	    mem_writed(ret, FXTRUE);
+	    ret_value = G_OK;
+	    break;
+	}
+
+	// Check for successful memory map
+	if(mem_readd(param[10]) == 0) {
+	    LOG_MSG("Glide:LFB memory map failed, using default LFB address!");
+	    // Write physical address instead, it can crash but it just might work
+	    mem_writed(param[10], glide.lfb_pagehandler->GetPhysPt());
+	}
+
+	glide.enabled = true;
+	glide.width = param[8];
+	glide.height = param[9];
+	GrOriginLocation = param[5];
+
+	// Resize window and disable updates
+	GLIDE_ResetScreen();
+
+	k = FP.grRFunction1p6i(hwnd, param[2], param[3], param[4], param[5], param[6], param[7]);
+	if(k == FXFALSE) {
+	    LOG_MSG("Glide:grSstWinOpen failed!");
+	    GLIDE_DisableScreen();
+	    mem_writed(ret, FXFALSE);
+	    ret_value = G_OK;
+	    break;
+	}
+
+	mem_writed(ret, k);
+	if(glide.splash) {
+	    grSplash();
+	    glide.splash = false;
+	}
+
+	glide.lfb_pagehandler->SetLinPt(mem_readd(param[10]));
+	LOG_MSG("Glide:Resolution:%dx%d, LFB at 0x%x (physical) / 0x%x (linear)",
+		glide.width, glide.height, glide.lfb_pagehandler->GetPhysPt(), glide.lfb_pagehandler->GetLinPt());
+	ret_value = G_OK;
+	break;
+    case _grTexCalcMemRequired16:
+	// FxU32 grTexCalcMemRequired(GrLOD_t smallLod, GrLOD_t largeLod, GrAspectRatio_t aspect,
+	//	    GrTextureFormat_t format)
+	FP.grRFunction4i = (prfunc4i)fn_pt[i];
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+	mem_writed(ret, FP.grRFunction4i(param[1], param[2], param[3], param[4]));
+	ret_value = G_OK;
+	break;
+    case _grTexClampMode12:
+	// void grTexClampMode(GrChipID_t tmu, GrTextureClampMode_t sClampMode, GrTextureClampMode_t tClampMode)
+	FP.grFunction3i = (pfunc3i)fn_pt[i];
+	FP.grFunction3i(param[1], param[2], param[3]);
+	break;
+    case _grTexCombine28:
+	// void grTexCombine(GrChipID_t tmu, GrCombineFunction_t rgb_function, GrCombineFactor_t rgb_factor,
+	//	GrCombineFunction_t alpha_function, GrCombineFactor_t alpha_factor, FxBool rgb_invert,
+	//	FxBool alpha_invert)
+	FP.grFunction7i = (pfunc7i)fn_pt[i];
+	FP.grFunction7i(param[1], param[2], param[3], param[4], param[5], param[6], param[7]);
+	break;
+    case _grTexCombineFunction8:
+	// void grTexCombineFunction(GrChipID_t tmu, GrTextureCombineFnc_t fnc)
+	FP.grFunction2i = (pfunc2i)fn_pt[i];
+	FP.grFunction2i(param[1], param[2]);
+	break;
+    case _grTexDetailControl16:
+	// void grTexDetailControl(GrChipID_t tmu, int lodBias, FxU8 detailScale, float detailMax)
+	FP.grFunction3i1f = (pfunc3i1f)fn_pt[i];
+	FP.grFunction3i1f(param[1], param[2], param[3], int_to_float(param[4]));
+	break;
+    case _grTexDownloadMipMap16:
+	// void grTexDownloadMipMap(GrChipID_t tmu, FxU32 startAddress, FxU32 evenOdd, GrTexInfo *info)
+	FP.grRFunction1i1p = (prfunc1i1p)fn_pt[_grTexTextureMemRequired8];
+	if(FP.grRFunction1i1p == NULL) {
+	    LOG_MSG("Glide:Unable to get pointer to grTexTextureMemRequired");
+	    return;
+	}
+
+	MEM_BlockRead32(param[4], &dbtexinfo, sizeof(DBGrTexInfo));
+
+	texinfo.smallLod = dbtexinfo.smallLod;
+	texinfo.largeLod = dbtexinfo.largeLod;
+	texinfo.aspectRatio = dbtexinfo.aspectRatio;
+	texinfo.format = dbtexinfo.format;
+	texinfo.data = NULL;
+
+	// grTexTextureMemRequired
+	texsize = FP.grRFunction1i1p(param[3], &texinfo);
+	MEM_BlockRead(dbtexinfo.data, texmem, texsize);
+	texinfo.data = texmem;
+
+	FP.grFunction3i1p = (pfunc3i1p)fn_pt[i];
+	FP.grFunction3i1p(param[1], param[2], param[3], &texinfo);
+	break;
+    case _grTexDownloadMipMapLevel32:
+	// void grTexDownloadMipMapLevel(GrChipID_t tmu, FxU32 startAddress, GrLOD_t thisLod,
+	//	GrLOD_t largeLod, GrAspectRatio_t aspectRatio, GrTextureFormat_t format,
+	//	FxU32 evenOdd, void *data)
+	FP.grRFunction1i1p = (prfunc1i1p)fn_pt[_grTexTextureMemRequired8];
+	if(FP.grRFunction1i1p == NULL) {
+	    LOG_MSG("Glide:Unable to get pointer to grTexTextureMemRequired");
+	    return;
+	}
+
+	texinfo.smallLod = param[3];
+	texinfo.largeLod = param[3];		// Calculate only thisLod
+	texinfo.aspectRatio = param[5];
+	texinfo.format = param[6];
+	texinfo.data = NULL;
+
+	// grTexTextureMemRequired
+	texsize = FP.grRFunction1i1p(param[7], &texinfo);
+	MEM_BlockRead(param[8], texmem, texsize);
+
+#if LOG_GLIDE
+	LOG_MSG("Read %d (%d %d %d %d %d) bytes of texture data", texsize, param[3], param[4], param[5], param[6], param[7]);
+#endif
+
+	FP.grFunction7i1p = (pfunc7i1p)fn_pt[i];
+	FP.grFunction7i1p(param[1], param[2], param[3], param[4], param[5], param[6], param[7], texmem);
+	break;
+    case _grTexDownloadMipMapLevelPartial40:
+	// FX_ENTRY void FX_CALL grTexDownloadMipMapLevelPartial(GrChipID_t tmu, FxU32 startAddress,
+	//    GrLOD_t thisLod, GrLOD_t largeLod, GrAspectRatio_t aspectRatio, GrTextureFormat_t format,
+	//    FxU32 evenOdd, void *data, int start, int end);
+	FP.grRFunction1i1p = (prfunc1i1p)fn_pt[_grTexTextureMemRequired8];
+	if(FP.grRFunction1i1p == NULL) {
+	    LOG_MSG("Glide:Unable to get pointer to grTexTextureMemRequired");
+	    return;
+	}
+
+	texinfo.smallLod = param[3];
+	texinfo.largeLod = param[3];		// Calculate only thisLod
+	texinfo.aspectRatio = param[5];
+	texinfo.format = param[6];
+	texinfo.data = NULL;
+
+	// grTexTextureMemRequired
+	texsize = FP.grRFunction1i1p(param[7], &texinfo);
+	MEM_BlockRead(param[8], texmem, texsize);
+
+	FP.grFunction7i1p2i = (pfunc7i1p2i)fn_pt[i];
+	FP.grFunction7i1p2i(param[1], param[2], param[3], param[4], param[5], param[6], param[7], texmem,
+			    param[9], param[10]);
+	break;
+    case _grTexDownloadTable12:
+	// void grTexDownloadTable(GrChipID_t tmu, GrTexTable_t type, void *data)
+	FP.grFunction2i1p = (pfunc2i1p)fn_pt[i];
+
+	if(param[2] == GR_TEXTABLE_PALETTE) {
+	    MEM_BlockRead32(param[3], texmem, sizeof(GuTexPalette));
+	} else { // GR_TEXTABLE_NCC0 or GR_TEXTABLE_NCC1
+	    MEM_BlockRead32(param[3], texmem, sizeof(GuNccTable));
+	}
+
+	FP.grFunction2i1p(param[1], param[2], texmem);
+	break;
+    case _grTexDownloadTablePartial20:
+	// void grTexDownloadTablePartial(GrChipID_t tmu, GrTexTable_t type, void *data, int start, int end)
+	FP.grFunction2i1p2i = (pfunc2i1p2i)fn_pt[i];
+
+	if(param[2] == GR_TEXTABLE_PALETTE) {
+	    MEM_BlockRead32(param[3], texmem, sizeof(GuTexPalette));
+	    FP.grFunction2i1p2i(param[1], param[2], texmem, param[4], param[5]);
+	} else { // GR_TEXTABLE_NCC0 or GR_TEXTABLE_NCC1
+	    LOG_MSG("Glide:Downloading partial NCC tables is not supported!");
+	}
+
+	break;
+    case _grTexFilterMode12:
+	// void grTexFilterMode(GrChipID_t tmu, GrTextureFilterMode_t minFilterMode,
+	//	GrTextureFilterMode_t magFilterMode)
+	FP.grFunction3i = (pfunc3i)fn_pt[i];
+	FP.grFunction3i(param[1], param[2], param[3]);
+	break;
+    case _grTexLodBiasValue8:
+	// void grTexLodBiasValue(GrChipID_t tmu, float bias)
+	FP.grFunction1i1f = (pfunc1i1f)fn_pt[i];
+	FP.grFunction1i1f(param[1], int_to_float(param[2]));
+	break;
+    case _grTexMaxAddress4:
+	// FxU32 grTexMaxAddress(GrChipID_t tmu)
+	FP.grRFunction1i = (prfunc1i)fn_pt[i];
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+	mem_writed(ret, FP.grRFunction1i(param[1]));
+	ret_value = G_OK;
+	break;
+    case _grTexMinAddress4:
+	// FxU32 grTexMinAddress(GrChipID_t tmu)
+	FP.grRFunction1i = (prfunc1i)fn_pt[i];
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+	mem_writed(ret, FP.grRFunction1i(param[1]));
+	ret_value = G_OK;
+	break;
+    case _grTexMipMapMode12:
+	// void grTexMipMapMode(GrChipID_t tmu, GrMipMapMode_t mode, FxBool lodBlend)
+	FP.grFunction3i = (pfunc3i)fn_pt[i];
+	FP.grFunction3i(param[1], param[2], param[3]);
+	break;
+    case _grTexMultibase8:
+	// void grTexMultibase(GrChipID_t tmu, FxBool enable)
+	FP.grFunction2i = (pfunc2i)fn_pt[i];
+	FP.grFunction2i(param[1], param[2]);
+	break;
+/*
+    case _grTexMultibaseAddress20:
+	// void grTexMultibaseAddress(GrChipID_t tmu, GrTexBaseRange_t range, FxU32 startAddress,
+	//	FxU32 evenOdd, GrTexInfo *info)
+	FP.grFunction4i1p = (pfunc4i1p)fn_pt[i];
+
+	// This is a bit more complicated since *info contains a pointer to data
+	texinfo = (GrTexInfo*)param[5];
+	data = (PhysPt)texinfo->data;			// Store for later reference
+	texinfo->data = VIRTOREAL(data);
+#if LOG_GLIDE
+	if(log_func[value-_grAADrawLine8] == 1) {
+	    LOG_MSG("Glide:Replacing pointer 0x%x with 0x%x in function %d", data, texinfo->data, _grTexMultibaseAddress20);
+	    log_func[value-_grAADrawLine8] = 2;
+	}
+#endif
+	FP.grFunction20(param[1], param[2], param[3], param[4], (int)texinfo);
+	texinfo->data = (void*)data;			// Change the pointer back
+	break;
+*/
+    case _grTexNCCTable8:
+	// void grTexNCCTable(GrChipID_t tmu, GrNCCTable_t table)
+	FP.grFunction2i = (pfunc2i)fn_pt[i];
+	FP.grFunction2i(param[1], param[2]);
+	break;
+    case _grTexSource16:
+	// void grTexSource(GrChipID_t tmu, FxU32 startAddress, FxU32 evenOdd, GrTexInfo *info)
+	FP.grFunction3i1p = (pfunc3i1p)fn_pt[i];
+
+	// Copy the data from DB struct
+	MEM_BlockRead32(param[4], &dbtexinfo, sizeof(DBGrTexInfo));
+
+	texinfo.smallLod = dbtexinfo.smallLod;
+	texinfo.largeLod = dbtexinfo.largeLod;
+	texinfo.aspectRatio = dbtexinfo.aspectRatio;
+	texinfo.format = dbtexinfo.format;
+	// Should the data pointer be filled ?
+
+	FP.grFunction3i1p(param[1], param[2], param[3], &texinfo);
+	break;
+    case _grTexTextureMemRequired8:
+	// FxU32 grTexTextureMemRequired(FxU32 evenOdd, GrTexInfo *info)
+	FP.grRFunction1i1p = (prfunc1i1p)fn_pt[i];
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+
+	// Copy the data from DB struct
+	MEM_BlockRead32(param[2], &dbtexinfo, sizeof(DBGrTexInfo));
+
+	texinfo.smallLod = dbtexinfo.smallLod;
+	texinfo.largeLod = dbtexinfo.largeLod;
+	texinfo.aspectRatio = dbtexinfo.aspectRatio;
+	texinfo.format = dbtexinfo.format;
+
+	mem_writed(ret, FP.grRFunction1i1p(param[1], &texinfo));
+
+	ret_value = G_OK;
+	break;
+    case _grTriStats8:
+	// void grTriStats(FxU32 *trisProcessed, FxU32 *trisDrawn)
+	FP.grFunction2p = (pfunc2p)fn_pt[i];
+	MEM_BlockRead32(param[1], ilist, sizeof(FxU32));
+	MEM_BlockRead32(param[2], ilist + 1, sizeof(FxU32));
+	FP.grFunction2p(ilist, ilist + 1);
+	MEM_BlockWrite32(param[1], ilist, sizeof(FxU32));
+	MEM_BlockWrite32(param[2], ilist + 1, sizeof(FxU32));
+	break;
+    case _gu3dfGetInfo8:
+	// FxBool gu3dfGetInfo(const char *filename, Gu3dfInfo *info)
+	FP.grRFunction2p = (prfunc2p)fn_pt[i];
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+	MEM_StrCopy(param[1], filename, 512);
+
+#if LOG_GLIDE
+	LOG_MSG("Glide:Filename info found in gu3dfGetInfo: %s", filename);
+#endif
+	if(!GetFileName(filename)) break;
+	mem_writed(ret, FP.grRFunction2p(filename, &guinfo));
+
+	// Copy the data back to DB struct if successful
+	if(mem_readd(ret)) {
+	    MEM_BlockRead32(param[2], &dbguinfo, sizeof(DBGu3dfInfo));
+	    dbguinfo.header.width = (Bit32u)guinfo.header.width;
+	    dbguinfo.header.height = (Bit32u)guinfo.header.height;
+	    dbguinfo.header.small_lod = (Bit32s)guinfo.header.small_lod;
+	    dbguinfo.header.large_lod = (Bit32s)guinfo.header.large_lod;
+	    dbguinfo.header.aspect_ratio = (Bit32s)guinfo.header.aspect_ratio;
+	    dbguinfo.header.format = (Bit32s)guinfo.header.format;
+	    dbguinfo.mem_required = (Bit32u)guinfo.mem_required;
+	    MEM_BlockWrite32(param[2], &dbguinfo, sizeof(DBGu3dfInfo));
+	}
+
+	ret_value = G_OK;
+	break;
+    case _gu3dfLoad8:
+	// FxBool gu3dfLoad(const char *filename, Gu3dfInfo *info)
+	FP.grRFunction2p = (prfunc2p)fn_pt[i];
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+
+	// Although glide ref specifies *info should be filled by gu3dfGetInfo before calling gu3dfLoad,
+	// OpenGlide will re-read the header in gu3dfLoad as well
+	MEM_BlockRead32(param[2], &dbguinfo, sizeof(DBGu3dfInfo));
+	MEM_StrCopy(param[1], filename, 512);
+
+#if LOG_GLIDE
+	LOG_MSG("Glide:Filename info found in gu3dfLoad: %s", filename);
+#endif
+	if(!GetFileName(filename)) break;
+
+	guinfo.data = texmem;
+	mem_writed(ret, FP.grRFunction2p(filename, &guinfo));
+
+	// Copy the data back to DB struct if successful
+	if(mem_readd(ret)) {
+	    for(j=0;j<256;j++)
+		dbguinfo.table.palette.data[j] = (Bit32u)guinfo.table.palette.data[j];
+	    MEM_BlockWrite(dbguinfo.data, guinfo.data, guinfo.mem_required);
+	}
+
+	MEM_BlockWrite32(param[2], &dbguinfo, sizeof(DBGu3dfInfo));
+	ret_value = G_OK;
+	break;
+    case _guAADrawTriangleWithClip12:
+	// void guAADrawTriangleWithClip(const GrVertex *va, const GrVertex *vb, const GrVertex *vc)
+	FP.grFunction3p = (pfunc3p)fn_pt[i];
+	MEM_BlockRead32(param[1], &vertex[0], sizeof(GrVertex));
+	MEM_BlockRead32(param[2], &vertex[1], sizeof(GrVertex));
+	MEM_BlockRead32(param[3], &vertex[2], sizeof(GrVertex));
+	FP.grFunction3p(&vertex[0], &vertex[1], &vertex[2]);
+	break;
+    case _guAlphaSource4:
+	// void guAlphaSource(GrAlphaSourceMode_t mode)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	break;
+    case _guColorCombineFunction4:
+	// void guColorCombineFunction(GrColorCombineFunction_t func)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	break;
+    case _guDrawPolygonVertexListWithClip8:
+	// void guDrawPolygonVertexListWithClip(int nverts, const GrVertex vlist[])
+	FP.grFunction1i1p = (pfunc1i1p)fn_pt[i];
+	MEM_BlockRead32(param[2], texmem, sizeof(GrVertex)*param[1]);
+	FP.grFunction1i1p(param[1], texmem);
+	break;
+    case _guDrawTriangleWithClip12:
+	// void guDrawTriangleWithClip(const GrVertex *va, const GrVertex *vb, const GrVertex *vc)
+	FP.grFunction3p = (pfunc3p)fn_pt[i];
+	MEM_BlockRead32(param[1], &vertex[0], sizeof(GrVertex));
+	MEM_BlockRead32(param[2], &vertex[1], sizeof(GrVertex));
+	MEM_BlockRead32(param[3], &vertex[2], sizeof(GrVertex));
+	FP.grFunction3p(&vertex[0], &vertex[1], &vertex[2]);
+	break;
+/*
+    case _guEncodeRLE1616:
+	//
+	FP.grFunction16 = (pfunc16)fn_pt[i];
+	FP.grFunction16();
+	break;
+    case _guEndianSwapBytes4:
+	//
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i();
+	break;
+    case _guEndianSwapWords4:
+	//
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i();
+	break;
+*/
+    case _guFogGenerateExp28:
+	// void guFogGenerateExp2(GrFog_t fogTable[GR_FOG_TABLE_SIZE], float density)
+	FP.grFunction1p1f = (pfunc1p1f)fn_pt[i];
+	FP.grFunction1p1f(texmem, int_to_float(param[2]));
+	MEM_BlockWrite32(param[1], texmem, GR_FOG_TABLE_SIZE*sizeof(GrFog_t));
+	break;
+    case _guFogGenerateExp8:
+	// void guFogGenerateExp(GrFog_t fogTable[GR_FOG_TABLE_SIZE], float density)
+	FP.grFunction1p1f = (pfunc1p1f)fn_pt[i];
+	FP.grFunction1p1f(texmem, int_to_float(param[2]));
+	MEM_BlockWrite32(param[1], texmem, GR_FOG_TABLE_SIZE*sizeof(GrFog_t));
+	break;
+    case _guFogGenerateLinear12:
+	// void guFogGenerateLinear(GrFog_t fogTable[GR_FOG_TABLE_SIZE], float nearW, float farW)
+	FP.grFunction1p2f = (pfunc1p2f)fn_pt[i];
+	FP.grFunction1p2f(texmem, int_to_float(param[2]), int_to_float(param[3]));
+	MEM_BlockWrite32(param[1], texmem, GR_FOG_TABLE_SIZE*sizeof(GrFog_t));
+	break;
+    case _guFogTableIndexToW4: {
+	// float guFogTableIndexToW(int i)
+	FP.grFFunction1i = (pffunc1i)fn_pt[i];
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+	float tmp = FP.grFFunction1i(param[1]);
+	SDL_memcpy(&j, &tmp, 4);
+	mem_writed(ret, SDL_SwapLE32(j));
+	ret_value = G_OK;
+	break;
+    }
+/*
+    case _guMPDrawTriangle12:
+	//
+	FP.grFunction3i = (pfunc3i)fn_pt[i];
+	FP.grFunction3i();
+	break;
+    case _guMPInit0:
+	//
+	FP.grFunction0 = (pfunc0)fn_pt[i];
+	FP.grFunction0();
+	break;
+    case _guMPTexCombineFunction4:
+	//
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i();
+	break;
+    case _guMPTexSource8:
+	//
+	FP.grFunction2i = (pfunc2i)fn_pt[i];
+	FP.grFunction2i();
+	break;
+    case _guMovieSetName4:
+	//
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i();
+	break;
+    case _guMovieStart0:
+	//
+	FP.grFunction0 = (pfunc0)fn_pt[i];
+	FP.grFunction0();
+	break;
+    case _guMovieStop0:
+	//
+	FP.grFunction0 = (pfunc0)fn_pt[i];
+	FP.grFunction0();
+	break;
+*/
+    case _guTexAllocateMemory60:
+	// GrMipMapId_t guTexAllocateMemory(GrChipID_t tmu, FxU8 evenOddMask, int width, int height,
+	//	    GrTextureFormat_t format, GrMipMapMode_t mmMode, GrLOD_t smallLod, GrLOD_t largeLod,
+	//	    GrAspectRatio_t aspectRatio, GrTextureClampMode_t sClampMode,
+	//	    GrTextureClampMode_t tClampMode, GrTextureFilterMode_t minFilterMode,
+	//	    GrTextureFilterMode_t magFilterMode, float lodBias, FxBool lodBlend)
+	FP.grRFunction13i1f1i = (prfunc13i1f1i)fn_pt[i];
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+	mem_writed(ret, FP.grRFunction13i1f1i(param[1], param[2], param[3], param[4], param[5], param[6], param[7],
+			    param[8], param[9], param[10], param[11], param[12], param[13], int_to_float(param[14]), param[15]));
+	ret_value = G_OK;
+	break;
+    case _guTexChangeAttributes48:
+	// FxBool guTexChangeAttributes(GrMipMapID_t mmid, int width, int height, GrTextureFormat_t format,
+	//	    GrMipMapMode_t mmMode, GrLOD_t smallLod, GrLOD_t largeLod, GrAspectRatio_t aspectRatio,
+	//	    GrTextureClampMode_t sClampMode, GrTextureClampMode_t tClampMode,
+	//	    GrTextureFilterMode_t minFilterMode, GrTextureFilterMode_t magFilterMode)
+	FP.grRFunction12i = (prfunc12i)fn_pt[i];
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+	mem_writed(ret, FP.grRFunction12i(param[1], param[2], param[3], param[4], param[5], param[6], param[7],
+			param[8], param[9], param[10], param[11], param[12]));
+	ret_value = G_OK;
+	break;
+    case _guTexCombineFunction8:
+	// void guTexCombineFunction(GrChipID_t tmu, GrTextureCombineFnc_t func)
+	FP.grFunction2i = (pfunc2i)fn_pt[i];
+	FP.grFunction2i(param[1], param[2]);
+	break;
+/*
+    case _guTexCreateColorMipMap0:
+	//
+	FP.grFunction0 = (pfunc0)fn_pt[i];
+	FP.grFunction0();
+	break;
+*/
+    case _guTexDownloadMipMap12:
+	// void guTexDownloadMipMap(GrMipMapId_t mmid, const void *src, const GuNccTable *nccTable)
+	FP.grRPTFunction1i = (prptfunc1i)fn_pt[_guTexGetMipMapInfo4];
+	mipmap = (GrMipMapInfo*)FP.grRPTFunction1i(param[1]);
+
+	if(mipmap) {
+	    texinfo.aspectRatio = mipmap->aspect_ratio;
+	    texinfo.format      = mipmap->format;
+	    texinfo.largeLod    = mipmap->lod_max;
+	    texinfo.smallLod    = mipmap->lod_min;
+
+	    FP.grRFunction1i1p = (prfunc1i1p)fn_pt[_grTexTextureMemRequired8];
+	    if(FP.grRFunction1i1p == NULL) {
+		LOG_MSG("Glide:Unable to get pointer to grTexTextureMemRequired");
+		return;
+	    }
+
+	    texsize = FP.grRFunction1i1p(mipmap->odd_even_mask, &texinfo);
+
+	    MEM_BlockRead(param[2], texmem, texsize);
+	    MEM_BlockRead32(param[3], (Bit8u*)texmem+texsize, sizeof(GuNccTable));
+
+	    FP.grFunction1i2p = (pfunc1i2p)fn_pt[i];
+	    FP.grFunction1i2p(param[1], texmem, (Bit8u*)texmem+texsize);
+	} else {
+	    LOG_MSG("Glide:Unable to get GrMipMapInfo pointer");
+	}
+	break;
+/*
+    case _guTexDownloadMipMapLevel12:
+	// void guTexDownloadMipMapLevel(GrMipMapId_t mmid, GrLOD_t lod, const void **src)
+	FP.grFunction2i1p = (pfunc2i1p)fn_pt[i];
+	FP.grFunction2i1p(param[1], param[2], *param[3]);
+	break;
+*/
+    case _guTexGetCurrentMipMap4:
+	// GrMipMapId_t guTexGetCurrentMipMap(GrChipID_t tmu)
+	FP.grRFunction1i = (prfunc1i)fn_pt[i];
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+	mem_writed(ret, FP.grRFunction1i(param[1]));
+	ret_value = G_OK;
+	break;
+/*
+    case _guTexGetMipMapInfo4:
+	// GrMipMapInfo *guTexGetMipMapInfo(GrMipMapId_t mmid)
+	FP.grRFunction4 = (prfunc4)fn_pt[i];
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+	mem_writed(ret, FP.grRFunction4(param[1]));
+	ret_value = G_OK;
+	break;
+*/
+    case _guTexMemQueryAvail4:
+	// FxU32 guTexMemQueryAvail(GrChipID_t tmu)
+	FP.grRFunction1i = (prfunc1i)fn_pt[i];
+	if(ret == 0) {
+	    LOG_MSG("Glide:Invalid return value handle for %s!", grTable[i].name);
+	    return;
+	}
+	mem_writed(ret, FP.grRFunction1i(param[1]));
+	ret_value = G_OK;
+	break;
+    case _guTexMemReset0:
+	// void guTexMemReset(void)
+	FP.grFunction0 = (pfunc0)fn_pt[i];
+	FP.grFunction0();
+	break;
+    case _guTexSource4:
+	// void guTexSource(GrMipMapId_t mmid)
+	FP.grFunction1i = (pfunc1i)fn_pt[i];
+	FP.grFunction1i(param[1]);
+	break;
+    case _ConvertAndDownloadRle64: {
+	// void ConvertAndDownloadRle(GrChipID_t tmu, FxU32 startAddress, GrLOD_t thisLod, GrLOD_t largeLod,
+	//				GrAspectRatio_t aspectRatio, GrTextureFormat_t format, FxU32 evenOdd,
+	//				FxU8 *bm_data, long  bm_h, FxU32 u0, FxU32 v0, FxU32 width, FxU32 height,
+	//				FxU32 dest_width, FxU32 dest_height, FxU16 *tlut)
+
+#if LOG_GLIDE
+	LOG_MSG("Glide: RLE width: %d, height: %d, bm_h: %d, u0: %d, v0: %d, dest %dx%d",
+	    param[12], param[13], param[9], param[10], param[11], param[14], param[15]);
+#endif
+
+	FxU8 c;
+	FxU32 scount = 0;
+	FxU32 dcount = 0;
+
+	FxU16 * src = ptr16 + param[14]*param[15];
+	FxU32 offset = 4 + param[9];
+
+	// Line offset (v0)
+	for(j = 0; j < param[11]; j++ ) {
+	    offset += mem_readb(param[8]+4+j);
+	}
+
+	// Write height lines
+	for(k = 0; k < param[13]; k++) {
+
+	    // Decode one RLE line
+	    scount = offset;
+	    while((c = mem_readb(param[8]+scount)) != 0xE0) {
+
+		if(c > 0xE0) {
+		    for(int count = 0; count < (c&0x1f); count++) {
+
+			// tlut is FxU16*
+			src[dcount] = mem_readw(param[16]+(mem_readb(param[8]+scount+1)<<1));
+			dcount++;
+		    }
+		    scount += 2;
+
+		} else {
+		    src[dcount] = mem_readw(param[16]+(c<<1));
+		    dcount++; scount++;
+		}
+	    }
+
+	    // Copy Line into destination texture, offset u0
+	    SDL_memcpy(ptr16 + (k*param[14]), src + param[10], sizeof(FxU16)*param[14]);
+	    offset += mem_readb(param[8] + 4 + j++);
+	    dcount = 0;
+	}
+
+	// One additional line
+	if(param[13] < param[15])
+	    SDL_memcpy(ptr16 + (k*param[14]), src + param[10], sizeof(FxU16)*param[14]);
+
+	// Download decoded texture
+	texinfo.smallLod = param[3];
+	texinfo.largeLod = param[4];
+	texinfo.aspectRatio = param[5];
+	texinfo.format = param[6];
+	texinfo.data = ptr16;
+
+	// void grTexDownloadMipMap(GrChipID_t tmu, FxU32 startAddress, FxU32 evenOdd, GrTexInfo *info)
+	FP.grFunction3i1p = (pfunc3i1p)fn_pt[_grTexDownloadMipMap16];
+	if(FP.grFunction3i1p == NULL) {
+	    LOG_MSG("Glide:Unable to get pointer to grTexDownloadMipMap");
+	    break;
+	}
+	FP.grFunction3i1p(param[1], param[2], param[7], &texinfo);
+	break;
+    }
+    default:
+	LOG_MSG("Glide:Unsupported glide call %s", grTable[i].name);
+	break;
+
+    }	/* switch */
+}	/* process_msg() */
--- a/src/hardware/Makefile.am
+++ b/src/hardware/Makefile.am
@@ -10,6 +10,6 @@ libhardware_a_SOURCES = adlib.cpp dma.cp
                         memory.cpp mixer.cpp pcspeaker.cpp pci_bus.cpp pic.cpp sblaster.cpp tandy_sound.cpp timer.cpp \
 			vga.cpp vga_attr.cpp vga_crtc.cpp vga_dac.cpp vga_draw.cpp vga_gfx.cpp vga_other.cpp \
 			vga_memory.cpp vga_misc.cpp vga_seq.cpp vga_xga.cpp vga_s3.cpp vga_tseng.cpp vga_paradise.cpp \
-			cmos.cpp disney.cpp gus.cpp mpu401.cpp ipx.cpp ipxserver.cpp dbopl.cpp
+			cmos.cpp disney.cpp gus.cpp mpu401.cpp ipx.cpp ipxserver.cpp dbopl.cpp glide.cpp
 
 
--- a/src/hardware/memory.cpp
+++ b/src/hardware/memory.cpp
@@ -23,6 +23,7 @@
 #include "setup.h"
 #include "paging.h"
 #include "regs.h"
+#include "glidedef.h"
 
 #include <string.h>
 
@@ -140,6 +141,8 @@ PageHandler * MEM_GetPageHandler(Bitu ph
 	} else if ((phys_page>=memory.lfb.start_page+0x01000000/4096) &&
 				(phys_page<memory.lfb.start_page+0x01000000/4096+16)) {
 		return memory.lfb.mmiohandler;
+	} else if (glide.enabled && (phys_page>=(GLIDE_LFB>>12)) && (phys_page<(GLIDE_LFB>>12)+GLIDE_PAGES)) {
+		return (PageHandler*)glide.lfb_pagehandler;
 	}
 	return &illegal_page_handler;
 }
@@ -191,6 +194,24 @@ void MEM_BlockWrite(PhysPt pt,void const
 	}
 }
 
+void MEM_BlockRead32(PhysPt pt,void * data,Bitu size) {
+	Bit32u * write=(Bit32u *) data;
+	size>>=2;
+	while (size--) {
+		*write++=mem_readd_inline(pt);
+		pt+=4;
+	}
+}
+
+void MEM_BlockWrite32(PhysPt pt,void * data,Bitu size) {
+	Bit32u * read=(Bit32u *) data;
+	size>>=2;
+	while (size--) {
+		mem_writed_inline(pt,*read++);
+		pt+=4;
+	}
+}
+
 void MEM_BlockCopy(PhysPt dest,PhysPt src,Bitu size) {
 	mem_memcpy(dest,src,size);
 }