summaryrefslogtreecommitdiff
blob: e908f921a9082b630713ccc50486659884b8e9b7 (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
diff -urN grub-0.91/ChangeLog grub/ChangeLog
--- grub-0.91/ChangeLog	Sat Jan 19 15:26:02 2002
+++ grub/ChangeLog	Mon Jan 21 22:44:25 2002
@@ -1877,6 +1877,18 @@
 	[!STAGE1_5] (CMDLINE_WIDTH): New macro.
 	[!STAGE1_5] (CMDLINE_MARGIN): Likewise.
 	* stage2/shared.h (TERMINAL_DUMB): Likewise.
+
+2000-08-29  Paulo C�sar Pereira de Andrade <pcpa@conectiva.com.br>
+
+        * configure.in: Added --disable-vga16 option, in case user does not
+        want the new VGA graphics interface.
+        * stage2/asm.S: Added some new functions, for graphics operations,
+        and renamed several functions to allow wrapping them.
+        * stage2/stage2.c: Main changes for VGA16 support.
+        * stage2/char_io.c: Modified calls of grub_putchar to putchar
+        * stage2/disk_io.c: Same as for char_io.c
+        * stage2/cmdline.c: Also, the same as for char_io.c
+        * stage2/shared.h: Definitions for externs and wrapping functions.
 	
 2000-08-28  OKUJI Yoshinori  <okuji@gnu.org>
 
diff -urN grub-0.91/configure.in grub/configure.in
--- grub-0.91/configure.in	Tue Jan 15 05:27:59 2002
+++ grub/configure.in	Mon Jan 21 22:44:25 2002
@@ -18,6 +18,7 @@
 AC_PREREQ(2.13)
 
 AC_CANONICAL_HOST
+AM_PROG_LIBTOOL
 
 case "$host_cpu" in
 i[[3456]]86) host_cpu=i386 ;;
@@ -610,6 +611,12 @@
 ASFLAGS='$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)'
 AC_SUBST(ASFLAGS)
 
+AC_ARG_ENABLE(vga16,
+  [  --disable-vga16        disable VGA graphics interface])
+
+if test x"$enable_vga16" != xno; then
+  STAGE2_CFLAGS="$STAGE2_CFLAGS -DVGA16=1"
+fi
 
 dnl Output.
 AC_OUTPUT([Makefile stage1/Makefile stage2/Makefile docs/Makefile \
diff -urN grub-0.91/stage2/asm.S grub/stage2/asm.S
--- grub-0.91/stage2/asm.S	Sat Dec 29 13:05:36 2001
+++ grub/stage2/asm.S	Mon Jan 21 22:44:25 2002
@@ -1865,7 +1865,7 @@
  *                      %cl = cursor ending scanline
  */
 
-ENTRY(nocursor)
+ENTRY(grub_nocursor)
 	push	%ebp
 	push	%ebx                    /* save EBX */
 
@@ -1951,7 +1951,7 @@
 
 
 /*
- * console_set_attrib(attr) :  Sets the character attributes for character at
+ * grub_set_attrib(attr) :  Sets the character attributes for character at
  *		current cursor position.
  *
  *  Bitfields for character's display attribute:
@@ -1985,7 +1985,7 @@
  *			%cx = count to display (???, possible side-effects!!)
  */
 
-ENTRY(console_set_attrib)
+ENTRY(grub_set_attrib)
 	push	%ebp
 	push	%ebx
 
@@ -2009,6 +2009,263 @@
 	pop	%ebp
 	ret
 
+#ifdef VGA16
+VARIABLE(cursorX)
+.word	0
+VARIABLE(cursorY)
+.word	0
+VARIABLE(cursorWidth)
+.word	0
+VARIABLE(cursorHeight)
+.word	0
+VARIABLE(cursorCount)
+.word	0
+VARIABLE(cursorBuf)
+.byte	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+
+/*
+ * set_int1c_handler(void)
+ */
+ENTRY(set_int1c_handler)
+	pushl	%edi
+
+	/* save the original int1c handler */
+	movl	$0x70, %edi
+	movw	(%edi), %ax
+	movw	%ax, ABS(int1c_offset)
+	movw	2(%edi), %ax
+	movw	%ax, ABS(int1c_segment)
+
+	/* save the new int1c handler */
+	movw	$ABS(int1c_handler), %ax
+	movw	%ax, (%edi)
+	xorw	%ax, %ax
+	movw	%ax, 2(%edi)
+
+	popl	%edi
+	ret
+
+
+/*
+ * unset_int1c_handler(void)
+ */
+ENTRY(unset_int1c_handler)
+	pushl	%edi
+
+	/* check if int1c_handler is set */
+	movl	$0x70, %edi
+	movw	$ABS(int1c_handler), %ax
+	cmpw	%ax, (%edi)
+	jne	int1c_1
+	xorw	%ax, %ax
+	cmpw	%ax, 2(%edi)
+	jne	int1c_1
+
+	/* restore the original */
+	movw	ABS(int1c_offset), %ax
+	movw	%ax, (%edi)
+	movw	ABS(int1c_segment), %ax
+	movw	%ax, 2(%edi)
+
+int1c_1:
+	popl	%edi
+	ret
+
+/*
+ * blinks graphics cursor
+ */
+	.code16
+write_data:
+	movw	$0, %ax
+	movw	%ax, %ds
+
+	mov	$0xA000, %ax		/* video in es:di */
+	mov	%ax, %es
+	mov	$80, %ax
+	movw	$ABS(cursorY), %si
+	mov	%ds:(%si), %bx
+	mul	%bx
+	movw	$ABS(cursorX), %si
+	mov	%ds:(%si), %bx
+	shr	$3, %bx			/* %bx /= 8 */
+	add	%bx, %ax
+	mov	%ax, %di
+
+	movw	$ABS(cursorBuf), %si	/* fontBuf in ds:si */
+
+	/* prepare for data moving */
+	mov	$16, %dx		/* altura da fonte */
+	mov	$80, %bx		/* bytes por linha */
+
+write_loop:
+	movb	%ds:(%si), %al
+	xorb	$0xff, %al
+	movb	%al, %ds:(%si)		/* invert cursorBuf */
+	movb	%al, %es:(%di)		/* write to video */
+	add	%bx, %di
+	inc	%si
+	dec	%dx
+	jg	write_loop
+	ret
+
+int1c_handler:
+	pusha
+	mov	$0, %ax
+	mov	%ax, %ds
+	mov	$ABS(cursorCount), %si
+	mov	%ds:(%si), %ax
+	inc	%ax
+	mov	%ax, %ds:(%si)
+	cmp	$9, %ax
+	jne	int1c_done
+
+	mov	$0, %ax
+	mov	%ax, %ds:(%si)
+/*
+	movw	$0x3c4, %dx
+	movb	$0x020f, %ax
+	outw	%ax, %dx
+*/
+	call	write_data
+
+int1c_done:
+	popa
+	iret
+	/* call previous int1c handler */
+	/* ljmp */
+	.byte	0xea
+int1c_offset:	.word	0
+int1c_segment:	.word	0
+	.code32
+
+
+ENTRY(get_font)
+	push	%ebp
+	push	%ebx
+	push	%ecx
+	push	%edx
+
+	call	EXT_C(prot_to_real)
+	.code16
+
+	movw	$0x1130, %ax
+	movb	$6, %bh		/* font 8x16 */
+	int	$0x10
+	movw	%bp, %dx
+	movw	%es, %cx
+
+	DATA32	call	EXT_C(real_to_prot)
+	.code32
+
+	xorl	%eax, %eax
+	movw	%cx, %ax
+	shll	$4, %eax
+	movw	%dx, %ax
+
+	pop	%edx
+	pop	%ecx
+	pop	%ebx
+	pop	%ebp
+	ret
+
+/*
+ * set_videomode(mode)
+ * BIOS call "INT 10H Function 0h" to set video mode
+ *	Call with	%ah = 0x0
+ *			%al = video mode
+ */
+ENTRY(set_videomode)
+	push	%ebp
+	push	%ebx
+	push	%ecx
+
+	movb	0x10(%esp), %cl
+
+	call	EXT_C(prot_to_real)
+	.code16
+
+	xorw	%bx, %bx
+	movb	$0xf, %ah
+	int	$0x10			/* Get Current Video mode */
+	movb	%al, %ch
+	xorb	%ah, %ah
+	movb	%cl, %al
+        int	$0x10			/* Set Video mode */
+
+	DATA32	call	EXT_C(real_to_prot)
+	.code32
+
+	xorb	%ah, %ah
+	movb	%ch, %al
+
+	pop	%ecx
+	pop	%ebx
+	pop	%ebp
+	ret
+
+/*
+ * set_palette(index, red, green, blue)
+ * BIOS call "INT 10H Function 10h" to set individual dac register
+ *	Call with	%ah = 0x10
+ *			%bx = register number
+ *			%ch = new value for green (0-63)
+ *			%cl = new value for blue (0-63)
+ *			%dh = new value for red (0-63)
+ */
+
+ENTRY(set_palette)
+	push	%ebp
+	push	%eax
+	push	%ebx
+	push	%ecx
+	push	%edx
+
+	movw	$0x3c8, %bx		/* address write mode register */
+
+	/* wait vertical retrace */
+
+	movw	$0x3da, %dx
+l1b:	inb	%dx, %al	/* wait vertical active display */
+	test	$8, %al
+	jnz	l1b
+
+l2b:	inb	%dx, %al	/* wait vertical retrace */
+	test	$8, %al
+	jnz	l2b
+
+	mov	%bx, %dx
+	movb	0x18(%esp), %al		/* index */
+	outb	%al, %dx
+	inc	%dx
+
+	movb	0x1c(%esp), %al		/* red */
+	outb	%al, %dx
+
+	movb	0x20(%esp), %al		/* green */
+	outb	%al, %dx
+
+	movb	0x24(%esp), %al		/* blue */
+	outb	%al, %dx
+
+	movw	0x18(%esp), %bx
+
+	call	EXT_C(prot_to_real)
+	.code16
+
+	movb	%bl, %bh
+	movw	$0x1000, %ax
+	int	$0x10
+
+	DATA32	call	EXT_C(real_to_prot)
+	.code32	
+
+	pop	%edx
+	pop	%ecx
+	pop	%ebx
+	pop	%eax
+	pop	%ebp
+	ret
+#endif
 
 /*
  * getrtsecs()
diff -urN grub-0.91/stage2/builtins.c grub/stage2/builtins.c
--- grub-0.91/stage2/builtins.c	Wed Jan  2 18:23:30 2002
+++ grub/stage2/builtins.c	Mon Jan 21 22:44:25 2002
@@ -133,6 +133,36 @@
   grub_printf ("[%d,%d,%d]", sector, offset, length);
 }
 
+#ifdef VGA16
+/* background */
+static int
+background_func(char *arg, int flags)
+{
+    if (grub_strlen(arg) == 6) {
+	int r = ((hex(arg[0]) << 4) | hex(arg[1])) >> 2;
+	int g = ((hex(arg[2]) << 4) | hex(arg[3])) >> 2;
+	int b = ((hex(arg[4]) << 4) | hex(arg[5])) >> 2;
+
+	background = (r << 16) | (g << 8) | b;
+	if (vga_inited)
+	    set_palette(0, r, g, b);
+	return (0);
+    }
+
+    return (1);
+}
+
+static struct builtin builtin_background =
+{
+  "background",
+  background_func,
+  BUILTIN_CMDLINE | BUILTIN_MENU,
+  "background RRGGBB",
+  "Sets the background color when in graphics mode."
+  "RR is red, GG is green, and BB blue. Numbers must be in hexadecimal."
+};
+#endif  /* VGA16 */
+
 
 /* blocklist */
 static int
@@ -399,6 +429,40 @@
 #endif /* SUPPORT_NETBOOT */
 
 
+#ifdef VGA16
+
+/* foreground */
+static int
+border_func(char *arg, int flags)
+{
+    if (grub_strlen(arg) == 6) {
+	int r = ((hex(arg[0]) << 4) | hex(arg[1])) >> 2;
+	int g = ((hex(arg[2]) << 4) | hex(arg[3])) >> 2;
+	int b = ((hex(arg[4]) << 4) | hex(arg[5])) >> 2;
+
+	border = (r << 16) | (g << 8) | b;
+	if (vga_inited)
+	    set_palette(0x11, r, g, b);
+
+	return (0);
+    }
+
+    return (1);
+}
+
+static struct builtin builtin_border =
+{
+  "border",
+  border_func,
+  BUILTIN_CMDLINE | BUILTIN_MENU,
+  "border RRGGBB",
+  "Sets the border video color when in graphics mode."
+  "RR is red, GG is green, and BB blue. Numbers must be in hexadecimal."
+};
+
+#endif /* VGA16 */
+
+
 /* cat */
 static int
 cat_func (char *arg, int flags)
@@ -409,7 +473,7 @@
     return 1;
 
   while (grub_read (&c, 1))
-    grub_putchar (c);
+    putchar (c);
 
   grub_close ();
   return 0;
@@ -963,6 +1027,44 @@
   return 0;
 }
 
+
+#ifdef VGA16
+/* display */
+static int
+display_func(char *arg, int flags)
+{
+    int i;
+
+    for (i = 0; i < MAX_DISPLAYS; i++) {
+	if (grub_strcmp(arg, display_entries[i].name) == 0)
+	    break;
+    }
+
+    if (i >= MAX_DISPLAYS)
+	return (1);
+
+    display_idx = i;
+    if (display->End)
+	(*display->End)();
+    display = &display_entries[display_idx];
+
+    /* Restart cmain */
+    grub_longjmp (restart_env, 0);
+    /*NOTREACHED*/
+
+    return (0);
+}
+
+static struct builtin builtin_display =
+{
+  "display",
+  display_func,
+  BUILTIN_CMDLINE,
+  "display MODEL",
+  "Changes display type. Available modes are \"text\" and \"vga16\"."
+};
+#endif /* VGA16 */
+
 static struct builtin builtin_displaymem =
 {
   "displaymem",
@@ -1238,6 +1340,39 @@
   " the devices which contain the file."
 };
 
+#ifdef VGA16
+
+/* foreground */
+static int
+foreground_func(char *arg, int flags)
+{
+    if (grub_strlen(arg) == 6) {
+	int r = ((hex(arg[0]) << 4) | hex(arg[1])) >> 2;
+	int g = ((hex(arg[2]) << 4) | hex(arg[3])) >> 2;
+	int b = ((hex(arg[4]) << 4) | hex(arg[5])) >> 2;
+
+	foreground = (r << 16) | (g << 8) | b;
+	if (vga_inited)
+	    set_palette(15, r, g, b);
+
+	return (0);
+    }
+
+    return (1);
+}
+
+static struct builtin builtin_foreground =
+{
+  "foreground",
+  foreground_func,
+  BUILTIN_CMDLINE | BUILTIN_MENU,
+  "foreground RRGGBB",
+  "Sets the foreground color when in graphics mode."
+  "RR is red, GG is green, and BB blue. Numbers must be in hexadecimal."
+};
+
+#endif /* VGA16 */
+
 
 /* fstest */
 static int
@@ -1390,12 +1525,13 @@
 
 
 /* help */
-#define MAX_SHORT_DOC_LEN	39
-#define MAX_LONG_DOC_LEN	66
 
 static int
 help_func (char *arg, int flags)
 {
+  int MAX_SHORT_DOC_LEN = (view_x1 - view_x0 + 1) / 2 - 1;
+  int MAX_LONG_DOC_LEN = (view_x1 - view_x0) - 14;
+
   if (! *arg)
     {
       /* Invoked with no argument. Print the list of the short docs.  */
@@ -1418,13 +1554,13 @@
 	    len = MAX_SHORT_DOC_LEN - 1;
 
 	  for (i = 0; i < len; i++)
-	    grub_putchar ((*builtin)->short_doc[i]);
+	    putchar ((*builtin)->short_doc[i]);
 
 	  for (; i < MAX_SHORT_DOC_LEN; i++)
-	    grub_putchar (' ');
+	    putchar (' ');
 
 	  if (! left)
-	    grub_putchar ('\n');
+	    putchar ('\n');
 
 	  left = ! left;
 	}
@@ -1474,8 +1610,8 @@
 
 		      grub_printf ("    ");
 		      for (i = 0; i < len; i++)
-			grub_putchar (*doc++);
-		      grub_putchar ('\n');
+			putchar (*doc++);
+		      putchar ('\n');
 		    }
 		}
 	    }
@@ -3149,6 +3285,74 @@
   "Save the current entry as the default boot entry."
 };
 
+#ifdef VGA16
+/*splashimage*/
+static int
+splashimage_func(char *arg, int flags)
+{
+    if (strlen(arg) > 63)
+	return (1);
+    if (flags == BUILTIN_CMDLINE) {
+	if (!grub_open(arg))
+	    return (1);
+	grub_close();
+    }
+
+    if (flags == BUILTIN_CMDLINE || !splash_set) {
+	strcpy(splashimage, arg);
+	splash_set = 1;
+    }
+
+    if (flags == BUILTIN_CMDLINE && vga_inited) {
+	display->End();
+	display->Begin();
+	cls();
+/*	grub_longjmp(restart_env, 0);*/
+    }
+
+    return (0);
+}
+
+static struct builtin builtin_splashimage =
+{
+  "splashimage",
+  splashimage_func,
+  BUILTIN_CMDLINE | BUILTIN_MENU,
+  "splashimage FILE",
+  "Load FILE as the background image when in graphics mode."
+};
+
+/*shade*/
+static int
+shade_func(char *arg, int flags)
+{
+   int new_shade;
+
+    if (!arg || safe_parse_maxint(&arg, &new_shade) == 0)
+	return (1);
+
+    if (shade != new_shade) {
+	shade = new_shade;
+	if (flags == BUILTIN_CMDLINE && vga_inited) {
+	    display->End();
+	    display->Begin();
+	    cls();
+	}
+    }
+
+    return (0);
+}
+
+static struct builtin builtin_shade =
+{
+  "shade",
+  shade_func,
+  BUILTIN_CMDLINE | BUILTIN_MENU,
+  "shade INTEGER",
+  "If set to 0, disables the use of shaded text, else enables it."
+};
+#endif /* VGA16 */
+
 
 #ifdef SUPPORT_SERIAL
 /* serial */
@@ -4438,16 +4642,79 @@
   "Probe VBE information. If the mode number MODE is specified, show only"
   " the information about only the mode."
 };
-  
+
+#ifdef VGA16
 
+/* viewport */
+static int
+viewport_func (char *arg, int flags)
+{
+    int i;
+    int x0 = 80, y0 = 25, x1 = 0, y1 = 0;
+    int *pos[4] = { &x0, &y0, &x1, &y1 };
+    extern int viewport_set;
+
+    if (!arg)
+	return (1);
+    for (i = 0; i < 4; i++) {
+	if (!*arg)
+	    return (1);
+	while (*arg && (*arg == ' ' || *arg == '\t'))
+	    ++arg;
+	if (!safe_parse_maxint(&arg, pos[i]))
+	    return (1);
+	while (*arg && (*arg != ' ' && *arg != '\t'))
+	    ++arg;
+    }
+
+    x1 += x0;
+    y1 += y0;
+
+    /* minimum size is 60 colums and 16 rows */
+    if (x0 > x1 - 60 || y0 > y1 - 16 || x0 < 0 || y0 < 0 || x1 > 80 || y1 > 30)
+	return (1);
+
+    viewport_set = 1;
+    view_x0 = x0;
+    view_y0 = y0;
+    view_x1 = x1;
+    view_y1 = y1;
+
+    if (flags == BUILTIN_CMDLINE && vga_inited) {
+	display->End();
+	display->Begin();
+	cls();
+    }
+
+    return (0);
+}
+
+static struct builtin builtin_viewport =
+{
+  "viewport",
+  viewport_func,
+  BUILTIN_CMDLINE | BUILTIN_MENU,
+  "viewport x y width height",
+  "Changes grub internals to output text in the window defined by"
+  " four parameters. The x and y parameters are 0 based. This option"
+  " only works with the vga interface."
+};
+#endif /* VGA16 */
+  
 /* The table of builtin commands. Sorted in dictionary order.  */
 struct builtin *builtin_table[] =
 {
+#ifdef VGA16
+  &builtin_background,
+#endif /* VGA16 */
   &builtin_blocklist,
   &builtin_boot,
 #ifdef SUPPORT_NETBOOT
   &builtin_bootp,
 #endif /* SUPPORT_NETBOOT */
+#ifdef VGA16
+  &builtin_border,
+#endif /* VGA16 */
   &builtin_cat,
   &builtin_chainloader,
   &builtin_cmp,
@@ -4461,11 +4728,17 @@
 #ifdef SUPPORT_NETBOOT
   &builtin_dhcp,
 #endif /* SUPPORT_NETBOOT */
+#ifdef VGA16
+  &builtin_display,
+#endif /* VGA16 */
   &builtin_displayapm,
   &builtin_displaymem,
   &builtin_embed,
   &builtin_fallback,
   &builtin_find,
+#ifdef VGA16
+  &builtin_foreground,
+#endif /* VGA16 */
   &builtin_fstest,
   &builtin_geometry,
   &builtin_halt,
@@ -4508,6 +4781,10 @@
 #endif /* SUPPORT_SERIAL */
   &builtin_setkey,
   &builtin_setup,
+#ifdef VGA16
+  &builtin_shade,
+  &builtin_splashimage,
+#endif /* VGA16 */
 #if defined(SUPPORT_SERIAL) || defined(SUPPORT_HERCULES)
   &builtin_terminal,
 #endif /* SUPPORT_SERIAL || SUPPORT_HERCULES */
@@ -4521,5 +4798,8 @@
   &builtin_unhide,
   &builtin_uppermem,
   &builtin_vbeprobe,
+#ifdef VGA16
+  &builtin_viewport,
+#endif /* VGA16 */
   0
 };
diff -urN grub-0.91/stage2/char_io.c grub/stage2/char_io.c
--- grub-0.91/stage2/char_io.c	Fri Jan 18 13:01:26 2002
+++ grub/stage2/char_io.c	Mon Jan 21 22:47:43 2002
@@ -262,8 +262,8 @@
 
   /* XXX: These should be defined in shared.h, but I leave these here,
      until this code is freezed.  */
-#define CMDLINE_WIDTH	78
-#define CMDLINE_MARGIN	10
+  int CMDLINE_WIDTH = (view_x1 - view_x0) - 2;
+  int CMDLINE_MARGIN = 10;
   
   int xpos, lpos, c, section;
   /* The length of PROMPT.  */
@@ -313,7 +313,7 @@
 	    {
 	      int y = getxy () & 0xFF;
 	      
-	      gotoxy (xpos, y);
+	      gotoxy (xpos + view_x0, y);
 	    }
 # ifdef SUPPORT_SERIAL
 	  else if (! (terminal & TERMINAL_DUMB) && (count > 4))
@@ -325,7 +325,7 @@
 	      int i;
 	      
 	      for (i = 0; i < count; i++)
-		grub_putchar ('\b');
+		putchar ('\b');
 	    }
 # endif /* SUPPORT_SERIAL */
 	}
@@ -351,7 +351,7 @@
 	    {
 	      int y = getxy () & 0xFF;
 	      
-	      gotoxy (xpos, y);
+	      gotoxy (xpos + view_x0, y);
 	    }
 # ifdef SUPPORT_SERIAL
 	  else if (! (terminal & TERMINAL_DUMB) && (count > 4))
@@ -365,9 +365,9 @@
 	      for (i = lpos - count; i < lpos; i++)
 		{
 		  if (! echo_char)
-		    grub_putchar (buf[i]);
+		    putchar (buf[i]);
 		  else
-		    grub_putchar (echo_char);
+		    putchar (echo_char);
 		}
 	    }
 # endif /* SUPPORT_SERIAL */
@@ -395,7 +395,7 @@
 	  /* From the start to the end.  */
 	  len = CMDLINE_WIDTH;
 	  pos = 0;
-	  grub_putchar ('\r');
+	  putchar ('\r');
 
 	  /* If SECTION is the first section, print the prompt, otherwise,
 	     print `<'.  */
@@ -407,7 +407,7 @@
 	    }
 	  else
 	    {
-	      grub_putchar ('<');
+	      putchar ('<');
 	      len--;
 	      pos++;
 	    }
@@ -443,9 +443,9 @@
       for (i = start; i < start + len && i < llen; i++)
 	{
 	  if (! echo_char)
-	    grub_putchar (buf[i]);
+	    putchar (buf[i]);
 	  else
-	    grub_putchar (echo_char);
+	    putchar (echo_char);
 
 	  pos++;
 	}
@@ -455,7 +455,7 @@
          /* Fill up the rest of the line with spaces.  */
          for (; i < start + len; i++)
            {
-             grub_putchar (' ');
+             putchar (' ');
              pos++;
            }
 	  
@@ -464,9 +464,9 @@
          if (pos == CMDLINE_WIDTH)
            {
              if (start + len < llen)
-               grub_putchar ('>');
+               putchar ('>');
              else
-               grub_putchar (' ');
+               putchar (' ');
              
              pos++;
            }
@@ -480,7 +480,7 @@
            {
              int y = getxy () & 0xFF;
              
-             gotoxy (xpos, y);
+             gotoxy (xpos + view_x0, y);
            }
 # ifdef SUPPORT_SERIAL      
          else if (! (terminal & TERMINAL_SERIAL) && (pos - xpos > 4))
@@ -490,7 +490,7 @@
          else
            {
              for (i = 0; i < pos - xpos; i++)
-               grub_putchar ('\b');
+               putchar ('\b');
            }
 # endif /* SUPPORT_SERIAL */
        }
@@ -500,7 +500,7 @@
   void cl_init (void)
     {
       /* Distinguish us from other lines and error messages!  */
-      grub_putchar ('\n');
+      putchar ('\n');
 
       /* Print full line and set position here.  */
       cl_refresh (1, 0);
@@ -631,7 +631,7 @@
 			/* There are more than one candidates, so print
 			   the list.  */
 
-			grub_putchar ('\n');
+			putchar ('\n');
 			/* Enable the auto fill mode temporarily.  */
 			auto_fill = 1;
 			print_completions (is_filename, 0);
@@ -773,7 +773,7 @@
 	}
     }
 
-  grub_putchar ('\n');
+  putchar ('\n');
 
   /* If ECHO_CHAR is NUL, remove the leading spaces.  */
   lpos = 0;
@@ -1119,7 +1119,7 @@
     {
       /* Fold a line only if AUTO_FILL is true.  */
       if (auto_fill && col >= 79)
-	grub_putchar ('\n');
+	putchar ('\n');
 
       col++;
     }
@@ -1142,7 +1142,7 @@
 
 #ifndef STAGE1_5
 void
-gotoxy (int x, int y)
+grub_gotoxy (int x, int y)
 {
   if (terminal & TERMINAL_CONSOLE)
     console_gotoxy (x, y);
@@ -1166,7 +1166,7 @@
 #endif /* SUPPORT_SERIAL */
 
 int
-getxy (void)
+grub_getxy (void)
 {
   int ret = 0;
   
@@ -1271,7 +1271,7 @@
 #endif /* SUPPORT_SERIAL */
 
 void
-cls (void)
+grub_cls (void)
 {
   if (terminal & TERMINAL_CONSOLE)
     console_cls ();
@@ -1292,7 +1292,7 @@
 {
   /* If the terminal is dumb, there is no way to clean the terminal.  */
   if (terminal & TERMINAL_DUMB)
-    grub_putchar ('\n');
+    putchar ('\n');
   else
     grub_printf ("\e[H\e[J");
 }
diff -urN grub-0.91/stage2/cmdline.c grub/stage2/cmdline.c
--- grub-0.91/stage2/cmdline.c	Wed Jan  2 18:23:30 2002
+++ grub/stage2/cmdline.c	Mon Jan 21 22:44:25 2002
@@ -125,7 +125,7 @@
   init_page ();
 #ifdef SUPPORT_DISKLESS
   print_network_configuration ();
-  grub_putchar ('\n');
+  putchar ('\n');
 #endif
   print_cmdline_message (forever);
 
diff -urN grub-0.91/stage2/disk_io.c grub/stage2/disk_io.c
--- grub-0.91/stage2/disk_io.c	Wed Nov 28 13:43:56 2001
+++ grub/stage2/disk_io.c	Mon Jan 21 22:44:25 2002
@@ -1267,7 +1267,7 @@
 	}
 
       if (! is_completion)
-	grub_putchar ('\n');
+	putchar ('\n');
       
       print_error ();
       do_completion = 0;
@@ -1334,7 +1334,7 @@
 		}
 
 	      if (! is_completion)
-		grub_putchar ('\n');
+		putchar ('\n');
 	    }
 	  else
 	    {
@@ -1408,7 +1408,7 @@
 	    }
 	  
 	  if (! is_completion)
-	    grub_putchar ('\n');
+	    putchar ('\n');
 	}
       else
 	errnum = ERR_BAD_FILENAME;
diff -urN grub-0.91/stage2/shared.h grub/stage2/shared.h
--- grub-0.91/stage2/shared.h	Mon Jan  7 21:57:36 2002
+++ grub/stage2/shared.h	Mon Jan 21 22:44:25 2002
@@ -44,6 +44,12 @@
 # define RAW_SEG(x) (x)
 #endif
 
+#if defined(VGA16)
+#if defined(GRUB_UTIL) || defined(STAGE1_5)
+#undef VGA16
+#endif
+#endif
+
 /*
  *  Integer sizes
  */
@@ -367,8 +373,10 @@
 #define isspace grub_isspace
 #define printf grub_printf
 #define sprintf grub_sprintf
+#ifndef VGA16
 #undef putchar
 #define putchar grub_putchar
+#endif
 #define strncat grub_strncat
 #define strstr grub_strstr
 #define memcmp grub_memcmp
@@ -383,6 +391,9 @@
 /*
  *  Below this should be ONLY defines and other constructs for C code.
  */
+#ifdef VGA16
+#define VIDEO		0xA0000
+#endif
 
 /* multiboot stuff */
 
@@ -773,26 +784,26 @@
 int currticks (void);
 
 /* Clear the screen. */
-void cls (void);
+void grub_cls (void);
 
 /* The console part of cls.  */
 void console_cls (void);
 
 #ifndef GRUB_UTIL
 /* Turn off cursor. */
-void nocursor (void);
+void grub_nocursor (void);
 #endif
 
 /* Get the current cursor position (where 0,0 is the top left hand
    corner of the screen).  Returns packed values, (RET >> 8) is x,
    (RET & 0xff) is y. */
-int getxy (void);
+int grub_getxy (void);
 
 /* The console part of getxy.  */
 int console_getxy (void);
 
 /* Set the cursor position. */
-void gotoxy (int x, int y);
+void grub_gotoxy (int x, int y);
 
 /* The console part of gotoxy.  */
 void console_gotoxy (int x, int y);
@@ -822,8 +833,64 @@
    constants defined above. */
 void set_attrib (int attr);
 
+extern int view_x0, view_y0, view_x1, view_y1;
+#ifdef VGA16
+#define MAX_DISPLAYS	2
+
+#define cls()		(display->Cls ? (*display->Cls)() : 0)
+#define gotoxy(x, y)	(display->Gotoxy ? (*display->Gotoxy)(x, y) : 0)
+#define putchar(c)	(display->Putchar ? (*display->Putchar)(c) : 0)
+#define console_set_attrib(a)	(display->SetAttrib ? (*display->SetAttrib)(a) : 0)
+#define getxy()		(display->Getxy ? (*display->Getxy)() : 0)
+#define nocursor()	(display->Nocursor ? (*display->Nocursor)() : 0)
+struct display_entry {
+    char *name;
+    int (*Begin)(void);
+    void (*End)(void);
+    void (*Cls)(void);
+    void (*Gotoxy)(int x, int y);
+    void (*Putchar)(int ch);
+    void (*SetAttrib)(int attr);
+    int (*Getxy)(void);
+    void (*Nocursor)(void);
+};
+struct display_entry display_entries[MAX_DISPLAYS + 1];
+extern struct display_entry *display;
+
+extern int vga_inited, foreground, background, shade, border;
+extern int display_idx, splash_set;
+extern short cursorX, cursorY, cursorWidth, cursorHeight;
+extern char cursorBuf[16], splashimage[64];
+
+int vga16_begin(void);
+void vga16_end(void);
+void vga16_cls(void);
+void vga16_gotoxy(int x, int y);
+void vga16_putchar(int ch);
+int vga16_getxy(void);
+void vga16_nocursor(void);
+void vga16_set_attrib(int attr);
+
+int read_image();
+void set_palette(int index, int red, int green, int blue);
+void *get_font(void);
+/* return previous video mode */
+int set_videomode(int mode);
+
+int hex(int);
+void set_int1c_handler();
+void unset_int1c_handler();
+void cursor(int state);
+#else
+#define cls		grub_cls
+#define gotoxy		grub_gotoxy
+#define console_set_attrib	grub_set_attrib
+#define getxy		grub_getxy
+#define nocursor	grub_nocursor
+#endif
+
 /* The console part of set_attrib.  */
-void console_set_attrib (int attr);
+void grub_set_attrib (int attr);
 
 /* Low-level disk I/O */
 int get_diskinfo (int drive, struct geometry *geometry);
diff -urN grub-0.91/stage2/stage2.c grub/stage2/stage2.c
--- grub-0.91/stage2/stage2.c	Mon Jan  7 21:56:45 2002
+++ grub/stage2/stage2.c	Mon Jan 21 22:45:49 2002
@@ -19,7 +19,12 @@
 
 #include "shared.h"
 
+int view_x0 = 0, view_y0 = 0, view_x1 = 80, view_y1 = 25;
 grub_jmp_buf restart_env;
+#ifdef VGA16
+int vga_disabled = 0, viewport_set = 0;
+int sx0, sy0, sx1, sy1;
+#endif
 
 #if defined(PRESET_MENU_STRING) || defined(SUPPORT_DISKLESS)
 
@@ -109,12 +114,12 @@
     }
 #endif /* SUPPORT_SERIAL */
   
-  gotoxy (77, y + 1);
+  gotoxy (view_x1 - 3, y + 1);
 
   if (first)
-    grub_putchar (disp_up);
+    putchar (disp_up);
   else
-    grub_putchar (' ');
+    putchar (' ');
 
   menu_entries = get_entry (menu_entries, first, 0);
 
@@ -122,13 +127,13 @@
     {
       int j = 0;
 
-      gotoxy (3, y + i);
+      gotoxy (view_x0 + 3, y + i);
 
       while (*menu_entries)
 	{
-	  if (j < 71)
+	  if (j < (view_x1 - view_x0) - 9)
 	    {
-	      grub_putchar (*menu_entries);
+	      putchar (*menu_entries);
 	      j++;
 	    }
 
@@ -138,16 +143,16 @@
       if (*(menu_entries - 1))
 	menu_entries++;
 
-      for (; j < 71; j++)
-	grub_putchar (' ');
+      for (; j < (view_x1 - view_x0) - 9; j++)
+	putchar (' ');
     }
 
-  gotoxy (77, y + size);
+  gotoxy (view_x0 + 3, y + size);
 
   if (*menu_entries)
-    grub_putchar (disp_down);
+    putchar (disp_down);
   else
-    grub_putchar (' ');
+    putchar (' ');
 }
 
 
@@ -211,10 +216,10 @@
       )
 # endif
     {
-      for (i = 0; i < 14; i++)
+      for (i = 0; i < 12; i++)
 	{
 	  int j;
-	  for (j = 0; j < 75; j++)
+	  for (j = view_x0; j < (view_x1 - view_x0) - 5; j++)
 	    {
 	      gotoxy (j + 1, i + y);
 	      set_attrib (normal_color);
@@ -223,33 +228,33 @@
     }
 #endif
 
-  gotoxy (1, y);
+  gotoxy (view_x0 + 1, y);
 
-  grub_putchar (disp_ul);
-  for (i = 0; i < 73; i++)
-    grub_putchar (disp_horiz);
-  grub_putchar (disp_ur);
+  putchar (disp_ul);
+  for (i = view_x0; i < view_x1 - 7; i++)
+    putchar (disp_horiz);
+  putchar (disp_ur);
 
   i = 1;
 
   while (1)
     {
-      gotoxy (1, y + i);
+      gotoxy (view_x0 + 1, y + i);
 
       if (i > size)
 	break;
 
-      grub_putchar (disp_vert);
-      gotoxy (75, y + i);
-      grub_putchar (disp_vert);
+      putchar (disp_vert);
+      gotoxy (view_x1 - 5, y + i);
+      putchar (disp_vert);
 
       i++;
     }
 
-  grub_putchar (disp_ll);
-  for (i = 0; i < 73; i++)
-    grub_putchar (disp_horiz);
-  grub_putchar (disp_lr);
+  putchar (disp_ll);
+  for (i = view_x0; i < view_x1 - 7; i++)
+    putchar (disp_horiz);
+  putchar (disp_lr);
 }
 
 static void
@@ -261,27 +266,27 @@
   if (terminal & TERMINAL_SERIAL)
     {
       menu_entries = get_entry (menu_entries, entryno, 0);
-      gotoxy (2, y);
-      grub_putchar (' ');
-      for (x = 3; x < 75; x++)
+      gotoxy (view_x0 + 2, y);
+      putchar (' ');
+      for (x = view_x0 + 3; x < view_x1 - 5; x++)
 	{
-	  if (*menu_entries && x < 71)
-	    grub_putchar (*menu_entries++);
+	  if (*menu_entries && x < view_x1 - 9)
+	    putchar (*menu_entries++);
 	  else
-	    grub_putchar (' ');
+	    putchar (' ');
 	}
     }
   else
 #endif /* SUPPORT_SERIAL */
     {
-      for (x = 2; x < 75; x++)
+      for (x = view_x0 + 2; x < view_x1 - 5; x++)
 	{
 	  gotoxy (x, y);
 	  set_attrib (attr);
 	}
     }
 
-  gotoxy (74, y);
+  gotoxy (view_x1 - 6, y);
 }
 
 /* Set the attribute of the line Y to normal state.  */
@@ -334,7 +339,8 @@
      invariant for TERMINAL_DUMB: first_entry == 0  */
   if (! (terminal & TERMINAL_DUMB))
     {
-      while (entryno > 11)
+      errnum = ERR_NONE;
+      while (entryno > 9)
 	{
 	  first_entry++;
 	  entryno--;
@@ -399,7 +405,7 @@
 #endif /* ! GRUB_UTIL */
 
       if (! (terminal & TERMINAL_DUMB))      
-	  print_border (3, 12);
+	  print_border (3 + view_y0, 12);
 
 #ifdef GRUB_UTIL
       /* In the grub shell, always use ACS_*.  */
@@ -455,10 +461,10 @@
 	grub_printf ("\n\nThe selected entry is %d ", entryno);
       else
       {
-	  print_entries (3, 12, first_entry, menu_entries);
+	  print_entries (view_y0 + 3, 12, first_entry, menu_entries);
 	  
 	  /* highlight initial line */
-	  set_line_highlight (4 + entryno, first_entry + entryno, 
+	  set_line_highlight (view_y0 + 4 + entryno, first_entry + entryno, 
 			      menu_entries);
       }
     }
@@ -487,9 +493,9 @@
 			   entryno, grub_timeout);
 	  else
 	  {
-	      gotoxy (3, 22);
+	      gotoxy (view_x0 + 3, view_y1 - 3);
 	      printf ("The highlighted entry will be booted automatically in %d seconds.    ", grub_timeout);
-	      gotoxy (74, 4 + entryno);
+	      gotoxy (view_x0 - 6, view_y0 + 4 + entryno);
 	  }
 	  
 	  grub_timeout--;
@@ -515,12 +521,12 @@
 	      if (terminal & TERMINAL_DUMB)
 		grub_putchar ('\r');
 	      else
-		gotoxy (3, 22);
+		gotoxy (view_x0 + 3, 22);
 	      printf ("                                                                    ");
 	      grub_timeout = -1;
 	      fallback_entry = -1;
 	      if (! (terminal & TERMINAL_DUMB))
-		gotoxy (74, 4 + entryno);
+		gotoxy (view_x1 - 6, view_x0 + 4 + entryno);
 	    }
 
 	  /* We told them above (at least in SUPPORT_SERIAL) to use
@@ -536,17 +542,17 @@
 		{
 		  if (entryno > 0)
 		    {
-		      set_line_normal (4 + entryno, first_entry + entryno,
+		      set_line_normal (view_y0 + 4 + entryno, first_entry + entryno,
 				       menu_entries);
 		      entryno--;
-		      set_line_highlight (4 + entryno, first_entry + entryno,
+		      set_line_highlight (view_y0 + 4 + entryno, first_entry + entryno,
 					  menu_entries);
 		    }
 		  else if (first_entry > 0)
 		    {
 		      first_entry--;
-		      print_entries (3, 12, first_entry, menu_entries);
-		      set_line_highlight (4, first_entry + entryno, 
+		      print_entries (view_y0 + 3, 12, first_entry, menu_entries);
+		      set_line_highlight (view_y0 + 4, first_entry + entryno, 
 					  menu_entries);
 		    }
 		}
@@ -558,17 +564,17 @@
 	      else
 		if (entryno < 11)
 		  {
-		    set_line_normal (4 + entryno, first_entry + entryno,
+		    set_line_normal (view_y0 + 4 + entryno, first_entry + entryno,
 				     menu_entries);
 		    entryno++;
-		    set_line_highlight (4 + entryno, first_entry + entryno,
+		    set_line_highlight (view_y0 + 4 + entryno, first_entry + entryno,
 					menu_entries);
 		  }
 		else if (num_entries > 12 + first_entry)
 		  {
 		    first_entry++;
-		    print_entries (3, 12, first_entry, menu_entries);
-		    set_line_highlight (15, first_entry + entryno, menu_entries);
+		    print_entries (view_y0 + 3, 12, first_entry, menu_entries);
+		    set_line_highlight (view_y0 + 15, first_entry + entryno, menu_entries);
 		  }
 	    }
 
@@ -582,7 +588,7 @@
 	      if ((c == 'd') || (c == 'o') || (c == 'O'))
 		{
 		  if (! (terminal & TERMINAL_DUMB))
-		    set_line_normal (4 + entryno, first_entry + entryno,
+		    set_line_normal (view_y0 + 4 + entryno, first_entry + entryno,
 				     menu_entries);
 
 		  /* insert after is almost exactly like insert before */
@@ -640,8 +646,8 @@
 		    }
 		  else
 		    {
-		      print_entries (3, 12, first_entry, menu_entries);
-		      set_line_highlight (4 + entryno, first_entry + entryno,
+		      print_entries (view_y0 + 3, 12, first_entry, menu_entries);
+		      set_line_highlight (view_y0 + 4 + entryno, first_entry + entryno,
 					  menu_entries);
 		    }
 		}
@@ -664,7 +670,7 @@
 		  if (terminal & TERMINAL_DUMB)
 		    grub_printf ("\r                                    ");
 		  else
-		    gotoxy (1, 21);
+		    gotoxy (view_x0 + 1, view_y1 + 21);
 
 		  /* Wipe out the previously entered password */
 		  memset (entered, 0, sizeof (entered));
@@ -811,6 +817,11 @@
   while (1)
     {
       cls ();
+#ifdef VGA16
+      if (display->End)
+	(*display->End)();
+      display = &display_entries[0];
+#endif
 
       if (config_entries)
 	printf ("  Booting \'%s\'\n\n",
@@ -840,6 +851,16 @@
 	break;
     }
 
+#ifdef VGA16
+      if (display_idx >= 0)
+	display = &display_entries[display_idx];
+      else if (!vga_disabled)
+	display = &display_entries[1];
+
+      if (!display->Begin || !(*display->Begin)())
+	display = &display_entries[0];
+#endif
+
   show_menu = 1;
   goto restart;
 }
@@ -904,6 +925,560 @@
   return pos;
 }
 
+#ifdef VGA16
+struct display_entry display_entries[MAX_DISPLAYS + 1] = {
+    {"text", 0, 0, grub_cls, grub_gotoxy, grub_putchar, grub_set_attrib,
+     grub_getxy, grub_nocursor},
+    {"vga16",
+     vga16_begin, vga16_end, vga16_cls, vga16_gotoxy, vga16_putchar,
+     vga16_set_attrib, vga16_getxy, vga16_nocursor},
+    {0, 0, 0, 0, 0, 0, 0, 0, 0}
+};
+struct display_entry *display;
+int display_idx = -1;
+
+/* default vga palette */
+char vga16pal[16][3] = {
+    { 0,  0,  0},
+    { 0,  0, 42},
+    { 0, 42,  0},
+    { 0, 42, 42},
+    {42,  0,  0},
+    {42,  0, 42},
+    {42, 21,  0},
+    {42, 42, 42},
+    {21, 21, 21},
+    {21, 21, 63},
+    {21, 63, 21},
+    {21, 63, 63},
+    {63, 21, 21},
+    {63, 21, 63},
+    {63, 63, 21},
+    {63, 63, 63},
+};
+
+int fontx, fonty;
+unsigned char *font8x16;
+int saved_videomode, no_scroll = 0, no_cursor = 0, shade = 1, vga_inited = 0;
+unsigned short text[80 * 30];
+int foreground = (63 << 16) | (63 << 8) | (63), background = 0, border = 0;
+int splash_set;
+char splashimage[64];
+#define VSHADOW VSHADOW1
+unsigned char VSHADOW1[38400];
+unsigned char VSHADOW2[38400];
+unsigned char VSHADOW4[38400];
+unsigned char VSHADOW8[38400];
+
+static inline void
+outb(unsigned short port, unsigned char val)
+{
+    __asm __volatile ("outb %0,%1"::"a" (val), "d" (port));
+}
+
+static void
+ModeReg(int value)
+{
+    outb(0x3ce, 5);
+    outb(0x3cf, value);
+}
+
+static void
+MapMask(int value)
+{
+    outb(0x3c4, 2);
+    outb(0x3c5, value);
+}
+
+/* set/reset register */
+static void
+SetRes(int value)
+{
+    outb(0x3ce, 0);
+    outb(0x3cf, value);
+}
+
+/* enable set/reset register */
+static void
+ESetRes(int value)
+{
+    outb(0x3ce, 1);
+    outb(0x3cf, value);
+}
+
+static void
+ReadMap(int value)
+{
+    outb(0x3ce, 4);
+    outb(0x3cf, value);
+}
+
+/* bit mask register */
+static void
+BitMask(int value)
+{
+    outb(0x3ce, 8);
+    outb(0x3cf, value);
+}
+
+void
+grub_memcpy(void *dest, const void *src, int len)
+{
+    int i;
+    register char *d = (char*)dest, *s = (char*)src;
+
+    for (i = 0; i < len; i++)
+	d[i] = s[i];
+}
+
+int
+hex(int v)
+{
+    if (v >= 'A' && v <= 'F')
+	return (v - 'A' + 10);
+    if (v >= 'a' && v <= 'f')
+	return (v - 'a' + 10);
+    return (v - '0');
+}
+
+static void
+SetXY(int col, int row)
+{
+    if (col >= view_x0 && col < view_x1) {
+	fontx = col;
+	cursorX = col << 3;
+    }
+    if (row >= view_y0 && row < view_y1) {
+	fonty = row;
+	cursorY = row << 4;
+    }
+}
+
+void
+cursor(int set)
+{
+    unsigned char *pat, *mem, *ptr, chr[16 << 2];
+    int i, ch, invert, offset;
+
+    if (set && (no_cursor || no_scroll))
+	return;
+
+    offset = cursorY * 80 + fontx;
+    ch = text[fonty * 80 + fontx] & 0xff;
+    invert = (text[fonty * 80 + fontx] & 0xff00) != 0;
+    pat = font8x16 + (ch << 4);
+
+    mem = (unsigned char*)VIDEO + offset;
+
+    if (!set) {
+	for (i = 0; i < 16; i++) {
+	    unsigned char mask = pat[i];
+
+	    if (!invert) {
+		chr[i	  ] = ((unsigned char*)VSHADOW1)[offset];
+		chr[16 + i] = ((unsigned char*)VSHADOW2)[offset];
+		chr[32 + i] = ((unsigned char*)VSHADOW4)[offset];
+		chr[48 + i] = ((unsigned char*)VSHADOW8)[offset];
+
+		if (shade) {
+		    if (ch == DISP_VERT || ch == DISP_LL ||
+			ch == DISP_UR || ch == DISP_LR) {
+			unsigned char pmask = ~(pat[i] >> 1);
+
+			chr[i     ] &= pmask;
+			chr[16 + i] &= pmask;
+			chr[32 + i] &= pmask;
+			chr[48 + i] &= pmask;
+		    }
+		    if (i > 0 && ch != DISP_VERT) {
+			unsigned char pmask = ~(pat[i - 1] >> 1);
+
+			chr[i	  ] &= pmask;
+			chr[16 + i] &= pmask;
+			chr[32 + i] &= pmask;
+			chr[48 + i] &= pmask;
+			if (ch == DISP_HORIZ || ch == DISP_UR || ch == DISP_LR) {
+			    pmask = ~pat[i - 1];
+
+			    chr[i     ] &= pmask;
+			    chr[16 + i] &= pmask;
+			    chr[32 + i] &= pmask;
+			    chr[48 + i] &= pmask;
+			}
+		    }
+		}
+		chr[i     ] |= mask;
+		chr[16 + i] |= mask;
+		chr[32 + i] |= mask;
+		chr[48 + i] |= mask;
+
+		offset += 80;
+	    }
+	    else {
+		chr[i	  ] = mask;
+		chr[16 + i] = mask;
+		chr[32 + i] = mask;
+		chr[48 + i] = mask;
+	    }
+	}
+    }
+    else {
+	MapMask(15);
+	ptr = mem;
+	for (i = 0; i < 16; i++, ptr += 80) {
+	    cursorBuf[i] = pat[i];
+	    *ptr = ~pat[i];
+	}
+	return;
+    }
+
+    offset = 0;
+    for (i = 1; i < 16; i <<= 1, offset += 16) {
+	int j;
+
+	MapMask(i);
+	ptr = mem;
+	for (j = 0; j < 16; j++, ptr += 80)
+	    *ptr = chr[j + offset];
+    }
+
+    MapMask(15);
+}
+
+int
+read_image(void)
+{
+    char buf[32], pal[16];
+    unsigned char c, base, mask, *s1, *s2, *s4, *s8;
+    unsigned i, len, idx, colors, x, y, width, height;
+
+    if (!grub_open(splashimage))
+	return (0);
+
+    /* read header */
+    if (!grub_read((char*)&buf, 10) || grub_memcmp(buf, "/* XPM */\n", 10)) {
+	grub_close();
+	return (0);
+    }
+
+    /* parse info */
+    while (grub_read(&c, 1)) {
+	if (c == '"')
+	    break;
+    }
+
+    while (grub_read(&c, 1) && (c == ' ' || c == '\t'))
+	;
+
+    i = 0;
+    width = c - '0';
+    while (grub_read(&c, 1)) {
+	if (c >= '0' && c <= '9')
+	    width = width * 10 + c - '0';
+	else
+	    break;
+    }
+    while (grub_read(&c, 1) && (c == ' ' || c == '\t'))
+	;
+
+    height = c - '0';
+    while (grub_read(&c, 1)) {
+	if (c >= '0' && c <= '9')
+	    height = height * 10 + c - '0';
+	else
+	    break;
+    }
+    while (grub_read(&c, 1) && (c == ' ' || c == '\t'))
+	;
+
+    colors = c - '0';
+    while (grub_read(&c, 1)) {
+	if (c >= '0' && c <= '9')
+	    colors = colors * 10 + c - '0';
+	else
+	    break;
+    }
+
+    base = 0;
+    while (grub_read(&c, 1) && c != '"')
+	;
+
+    /* palette */
+    for (i = 0, idx = 1; i < colors; i++) {
+	len = 0;
+
+	while (grub_read(&c, 1) && c != '"')
+	    ;
+	grub_read(&c, 1);	/* char */
+	base = c;
+	grub_read(buf, 4);	/* \t c # */
+
+	while (grub_read(&c, 1) && c != '"') {
+	    if (len < sizeof(buf))
+		buf[len++] = c;
+	}
+
+	if (len == 6 && idx < 15) {
+	    int r = ((hex(buf[0]) << 4) | hex(buf[1])) >> 2;
+	    int g = ((hex(buf[2]) << 4) | hex(buf[3])) >> 2;
+	    int b = ((hex(buf[4]) << 4) | hex(buf[5])) >> 2;
+
+	    pal[idx] = base;
+	    set_palette(idx, r, g, b);
+	    ++idx;
+	}
+    }
+
+    x = y = len = 0;
+
+    s1 = (unsigned char*)VSHADOW1;
+    s2 = (unsigned char*)VSHADOW2;
+    s4 = (unsigned char*)VSHADOW4;
+    s8 = (unsigned char*)VSHADOW8;
+
+    for (i = 0; i < 38400; i++)
+	s1[i] = s2[i] = s4[i] = s8[i] = 0;
+
+    /* parse xpm data */
+    while (y < height) {
+	while (1) {
+	    if (!grub_read(&c, 1)) {
+		grub_close();
+		return (0);
+	    }
+	    if (c == '"')
+		break;
+	}
+
+	while (grub_read(&c, 1) && c != '"') {
+	    for (i = 1; i < 15; i++)
+		if (pal[i] == c) {
+		    c = i;
+		    break;
+		}
+
+	    mask = 0x80 >> (x & 7);
+	    if (c & 1)
+		s1[len + (x >> 3)] |= mask;
+	    if (c & 2)
+		s2[len + (x >> 3)] |= mask;
+	    if (c & 4)
+		s4[len + (x >> 3)] |= mask;
+	    if (c & 8)
+		s8[len + (x >> 3)] |= mask;
+
+	    if (++x >= 640) {
+		x = 0;
+
+		if (y < 480)
+		    len += 80;
+		++y;
+	    }
+	}
+    }
+
+    grub_close();
+
+    set_palette(0, (background >> 16), (background >> 8) & 63, background & 63);
+    set_palette(15, (foreground >> 16), (foreground >> 8) & 63, foreground & 63);
+
+    set_palette(0x11, (border >> 16), (border >> 8) & 63, border & 63);
+
+    return (1);
+}
+
+int
+vga16_begin(void)
+{
+    if (vga_inited)
+	return (1);
+
+    if (!*splashimage)
+	grub_strcpy(splashimage, "/boot/grub/splash.xpm");
+
+    saved_videomode = set_videomode(0x12);
+    if (!read_image()) {
+	set_videomode(saved_videomode);
+	return (0);
+    }
+
+    font8x16 = (unsigned char*)get_font();
+
+    cursorWidth = 8;
+    cursorHeight = 16;
+
+    set_int1c_handler();
+
+    view_x0 = sx0;
+    view_y0 = sy0;
+    view_x1 = sx1;
+    view_y1 = sy1;
+
+    return (vga_inited = 1);
+}
+
+void
+vga16_end(void)
+{
+    if (vga_inited) {
+	unset_int1c_handler();
+	set_videomode(saved_videomode);
+	vga_inited = 0;
+	no_cursor = 0;
+    }
+
+    sx0 = view_x0;
+    sy0 = view_y0;
+    sx1 = view_x1;
+    sy1 = view_y1;
+    view_x0 = 0;
+    view_x1 = 80;
+    view_y0 = 0;
+    view_y1 = 25;
+}
+
+void
+vga16_cls(void)
+{
+    int i;
+    unsigned char *mem, *s1, *s2, *s4, *s8;
+
+    SetXY(view_x0, view_y0);
+
+    mem = (unsigned char*)VIDEO;
+    s1 = (unsigned char*)VSHADOW1;
+    s2 = (unsigned char*)VSHADOW2;
+    s4 = (unsigned char*)VSHADOW4;
+    s8 = (unsigned char*)VSHADOW8;
+
+    for (i = 0; i < 80 * 30; i++)
+	text[i] = ' ';
+
+    BitMask(0xff);
+
+    /* plano 1 */
+    MapMask(1);
+    grub_memcpy(mem, s1, 38400);
+
+    /* plano 2 */
+    MapMask(2);
+    grub_memcpy(mem, s2, 38400);
+
+    /* plano 3 */
+    MapMask(4);
+    grub_memcpy(mem, s4, 38400);
+
+    /* plano 4 */
+    MapMask(8);
+    grub_memcpy(mem, s8, 38400);
+
+    MapMask(15);
+
+    if (no_cursor) {
+	no_cursor = 0;
+	set_int1c_handler();
+    }
+}
+
+void
+vga16_gotoxy(int x, int y)
+{
+    cursor(0);
+
+    SetXY(x, y);
+
+    cursor(1);
+}
+
+static void
+scroll(void)
+{
+    int i, j;
+
+    if (no_scroll)
+	return;
+
+    no_scroll = 1;
+
+    for (j = view_y0 + 1; j < view_y1; j++) {
+	gotoxy(view_x0, j - 1);
+	for (i = view_x0; i < view_x1; i++)
+	    putchar(text[j * 80 + i]);
+    }
+
+    gotoxy(view_x0, view_y1 - 1);
+    for (i = view_x0; i < view_x1; i++)
+	putchar(' ');
+
+    SetXY(view_x0, view_y1 - 1);
+
+    no_scroll = 0;
+}
+
+void
+vga16_putchar(int ch)
+{
+    ch &= 0xff;
+
+    cursor(0);
+
+    if (ch == '\n') {
+	SetXY(view_x0, fonty);
+	if (fonty + 1 < view_y1)
+	    SetXY(view_x0, fonty + 1);
+	else
+	    scroll();
+	cursor(1);
+	return;
+    }
+    else if (ch == '\r') {
+	SetXY(view_x0, fonty);
+	cursor(1);
+	return;
+    }
+
+    text[fonty * 80 + fontx] = ch;
+
+    cursor(0);
+
+    if ((fontx + 1) >= view_x1) {
+	SetXY(view_x0, fonty);
+	if (fonty + 1 < view_y1)
+	    SetXY(view_x0, fonty + 1);
+	else
+	    scroll();
+    }
+    else
+	SetXY(fontx + 1, fonty);
+
+    cursor(1);
+}
+
+int
+vga16_getxy()
+{
+    return ((fontx << 8) | fonty);
+}
+
+void
+vga16_nocursor()
+{
+    if (!no_cursor) {
+	no_cursor = 1;
+	unset_int1c_handler();
+	cursor(0);
+    }
+}
+
+void
+vga16_set_attrib(int attrib)
+{
+    text[fonty * 80 + fontx] &= 0x00ff;
+    if (attrib & 0xf0)
+	text[fonty * 80 + fontx] |= 0x100;
+    cursor(0);
+}
+#endif
 
 /* This is the starting function in C.  */
 void
@@ -924,6 +1499,14 @@
       menu_entries = (char *) MENU_BUF;
       init_config ();
     }
+
+#ifdef VGA16
+  /* Make sure it points to a valid entry */
+  display = &display_entries[0];
+ 
+  if (ASCII_CHAR(checkkey()) == 0x1b)
+	  vga_disabled = 1;
+#endif
       
   /* Initialize the environment for restarting Stage 2.  */
   grub_setjmp (restart_env);
@@ -1069,6 +1652,29 @@
 	  while (is_preset);
 	}
 
+#ifdef VGA16
+      if (display_idx >= 0)
+	display = &display_entries[display_idx];
+      else if (!vga_disabled) {
+	display = &display_entries[1];
+      }
+      if (!viewport_set)
+	view_y1 = 30;
+      sx0 = view_x0;
+      sy0 = view_y0;
+      sx1 = view_x1;
+      sy1 = view_y1;
+
+      if (!display->Begin || !(*display->Begin)())
+	display = &display_entries[0];
+
+      if (!vga_inited) {
+	sx0 = sy0 = view_x0 = view_y0 = 0;
+	sx1 = view_x1 = 80;
+	sy1 = view_y1 = 25;	  
+      }
+#endif
+
       if (! num_entries)
 	{
 	  /* If no acceptable config file, goto command-line, starting