2 * Copyright (c) 1992, 1995 Hellmuth Michaelis
4 * Copyright (c) 1992, 1994 Brian Dunford-Shore
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by
19 * Hellmuth Michaelis and Brian Dunford-Shore
20 * 4. The name authors may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 /*---------------------------------------------------------------------------*
37 * load a font into VGA character font memory
38 * ------------------------------------------
40 * Last Edit-Date: [Mon Mar 27 17:09:25 2000];
44 *---------------------------------------------------------------------------*/
50 #include <sys/types.h>
52 #include <machine/pcvt_ioctl.h>
54 #define FONT8X8 2048 /* filesize for 8x8 font */
55 #define HEIGHT8X8 8 /* 8 scan lines char cell height */
56 #define SSCAN8X8 143 /* 400 scan lines on screen - 256 - 1 */
58 #define FONT8X10 2560 /* filesize for 8x10 font */
59 #define HEIGHT8X10 10 /* 10 scan lines char cell height */
60 #define SSCAN8X10 143 /* 400 scan lines on screen - 256 - 1 */
62 #define FONT8X14 3584 /* filesize for 8x14 font */
63 #define HEIGHT8X14 14 /* 14 scan lines char cell height */
64 #define SSCAN8X14 135 /* 392 scan lines on screen - 256 - 1 */
66 #define FONT8X16 4096 /* filesize for 8x16 font */
67 #define HEIGHT8X16 16 /* 16 scan lines char cell height */
68 #define SSCAN8X16 143 /* 400 scan lines on screen - 256 - 1 */
70 struct screeninfo screeninfo;
81 struct stat sbuf, *sbp;
82 unsigned char *fonttab;
95 while( (c = getopt(argc, argv, "c:d:f:i")) != -1)
100 chr_set = atoi(optarg);
124 if(chr_set == -1 || fflag == -1)
129 if((fd = open(device, O_RDWR)) == -1)
130 err(1, "ERROR opening %s", device);
141 if(ioctl(fd, VGAGETSCREEN, &screeninfo) == -1)
142 err(1, "ioctl VGAGETSCREEN failed");
144 switch(screeninfo.adaptor_type)
146 case UNKNOWN_ADAPTOR:
149 printf("Adaptor does not support Downloadable Fonts!\n");
169 if(chr_set < 0 || chr_set > 7)
174 if((in = fopen(filename, "r")) == NULL)
175 err(1, "cannot open file %s for reading", filename);
177 if((fstat(fileno(in), sbp)) != 0)
178 err(1, "cannot fstat file %s", filename);
183 chr_height = HEIGHT8X8;
185 scr_rows = SIZ_50ROWS;
189 chr_height = HEIGHT8X10;
190 scr_scan = SSCAN8X10;
191 scr_rows = SIZ_40ROWS;
195 chr_height = HEIGHT8X14;
196 scr_scan = SSCAN8X14;
197 scr_rows = SIZ_28ROWS;
201 chr_height = HEIGHT8X16;
202 scr_scan = SSCAN8X16;
203 scr_rows = SIZ_25ROWS;
207 errx(1, "error, file %s is no valid font file, size=%d", argv[1], sbp->st_size);
210 if((fonttab = (unsigned char *)malloc((size_t)sbp->st_size)) == NULL)
211 errx(1, "error, malloc failed");
213 if((ret = fread(fonttab, sizeof(*fonttab), sbp->st_size, in)) != sbp->st_size)
214 errx(1, "error reading file %s, size = %d, read = is no valid font file, size=%d",
215 argv[1], sbp->st_size, ret);
217 loadfont(chr_set, chr_height, fonttab);
218 setfont(chr_set, 1, chr_height - 1, scr_scan, scr_rows);
223 setfont(charset, fontloaded, charscan, scrscan, scrrow)
224 int charset, fontloaded, charscan, scrscan, scrrow;
226 struct vgafontattr vfattr;
228 vfattr.character_set = charset;
229 vfattr.font_loaded = fontloaded;
230 vfattr.character_scanlines = charscan;
231 vfattr.screen_scanlines = scrscan;
232 vfattr.screen_size = scrrow;
234 if(ioctl(fd, VGASETFONTATTR, &vfattr) == -1)
235 err(1, "ioctl VGASETFONTATTR failed, error");
238 loadfont(fontset,charscanlines,font_table)
241 unsigned char *font_table;
244 struct vgaloadchar vlc;
246 vlc.character_set = fontset;
247 vlc.character_scanlines = charscanlines;
249 for(i = 0; i < 256; i++)
252 for (j = 0; j < charscanlines; j++)
254 vlc.char_table[j] = font_table[j];
256 font_table += charscanlines;
257 if(ioctl(fd, VGALOADCHAR, &vlc) == -1)
258 err(1, "ioctl VGALOADCHAR failed, error");
262 printvgafontattr(charset)
265 struct vgafontattr vfattr;
266 static int sizetab[] = { 25, 28, 35, 40, 43, 50 };
268 vfattr.character_set = charset;
270 if(ioctl(fd, VGAGETFONTATTR, &vfattr) == -1)
271 err(1, "ioctl VGAGETFONTATTR failed, error");
272 printf(" %d ",charset);
273 if(vfattr.font_loaded)
277 printf(" %2.2d ", sizetab[vfattr.screen_size]);
279 (((int)vfattr.character_scanlines) & 0x1f) + 1);
281 ((int)vfattr.screen_scanlines+0x101));
292 printf("\nEGA/VGA Charactersets Status Info:\n\n");
293 printf("Set Status Lines CharScanLines ScreenScanLines\n");
294 printf("--- ------ ----- ------------- ---------------\n");
299 fprintf(stderr,"\nloadfont - load font into ega/vga font ram for pcvt video driver\n");
300 fprintf(stderr,"usage: loadfont -c <cset> -d <dev> -f <name> -i\n");
301 fprintf(stderr," -c <cset> characterset to load (ega 0..3, vga 0..7)\n");
302 fprintf(stderr," -d <dev> specify device\n");
303 fprintf(stderr," -f <name> filename containing binary font data\n");
304 fprintf(stderr," -i print status and types of loaded fonts (default)\n");