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.
34 * $FreeBSD: src/usr.sbin/pcvt/loadfont/loadfont.c,v 1.6.6.1 2001/05/12 10:11:42 kris Exp $
35 * $DragonFly: src/usr.sbin/pcvt/loadfont/Attic/loadfont.c,v 1.3 2004/03/24 17:46:23 cpressey Exp $
39 "@(#)loadfont.c, 3.20, Last Edit-Date: [Fri Apr 7 10:13:16 1995]";
41 /*---------------------------------------------------------------------------*
43 * load a font into vga character font memory
45 * -hm removing explicit HGC support (same as MDA ..)
46 * -hm new pcvt_ioctl.h SIZ_xxROWS
49 *---------------------------------------------------------------------------*/
54 #include <sys/types.h>
56 #include <machine/pcvt_ioctl.h>
58 #define FONT8X8 2048 /* filesize for 8x8 font */
59 #define HEIGHT8X8 8 /* 8 scan lines char cell height */
60 #define SSCAN8X8 143 /* 400 scan lines on screen - 256 - 1 */
62 #define FONT8X10 2560 /* filesize for 8x10 font */
63 #define HEIGHT8X10 10 /* 10 scan lines char cell height */
64 #define SSCAN8X10 143 /* 400 scan lines on screen - 256 - 1 */
66 #define FONT8X14 3584 /* filesize for 8x14 font */
67 #define HEIGHT8X14 14 /* 14 scan lines char cell height */
68 #define SSCAN8X14 135 /* 392 scan lines on screen - 256 - 1 */
70 #define FONT8X16 4096 /* filesize for 8x16 font */
71 #define HEIGHT8X16 16 /* 16 scan lines char cell height */
72 #define SSCAN8X16 143 /* 400 scan lines on screen - 256 - 1 */
74 struct screeninfo screeninfo;
79 static void setfont(int, int, int, int, int);
80 static void loadfont(int, int, const unsigned char *);
81 static void printvgafontattr(int);
82 static void printheader(void);
83 static void usage(void);
86 main(int argc, char **argv)
93 struct stat sbuf, *sbp;
94 unsigned char *fonttab;
107 while( (c = getopt(argc, argv, "c:d:f:i")) != -1)
112 chr_set = atoi(optarg);
136 if(chr_set == -1 || fflag == -1)
141 if((fd = open(device, O_RDWR)) == -1)
142 err(1, "ERROR opening %s", device);
153 if(ioctl(fd, VGAGETSCREEN, &screeninfo) == -1)
154 err(1, "ioctl VGAGETSCREEN failed");
156 switch(screeninfo.adaptor_type)
158 case UNKNOWN_ADAPTOR:
161 printf("Adaptor does not support Downloadable Fonts!\n");
181 if(chr_set < 0 || chr_set > 7)
186 if((in = fopen(filename, "r")) == NULL)
187 err(1, "cannot open file %s for reading", filename);
189 if((fstat(fileno(in), sbp)) != 0)
190 err(1, "cannot fstat file %s", filename);
195 chr_height = HEIGHT8X8;
197 scr_rows = SIZ_50ROWS;
201 chr_height = HEIGHT8X10;
202 scr_scan = SSCAN8X10;
203 scr_rows = SIZ_40ROWS;
207 chr_height = HEIGHT8X14;
208 scr_scan = SSCAN8X14;
209 scr_rows = SIZ_28ROWS;
213 chr_height = HEIGHT8X16;
214 scr_scan = SSCAN8X16;
215 scr_rows = SIZ_25ROWS;
219 errx(1, "error, file %s is no valid font file, size=%d", argv[1], sbp->st_size);
222 if((fonttab = (unsigned char *)malloc((size_t)sbp->st_size)) == NULL)
223 errx(1, "error, malloc failed");
225 if((ret = fread(fonttab, sizeof(*fonttab), sbp->st_size, in)) != sbp->st_size)
226 errx(1, "error reading file %s, size = %d, read = is no valid font file, size=%d",
227 argv[1], sbp->st_size, ret);
229 loadfont(chr_set, chr_height, fonttab);
230 setfont(chr_set, 1, chr_height - 1, scr_scan, scr_rows);
236 setfont(int charset, int fontloaded, int charscan, int scrscan, int scrrow)
238 struct vgafontattr vfattr;
240 vfattr.character_set = charset;
241 vfattr.font_loaded = fontloaded;
242 vfattr.character_scanlines = charscan;
243 vfattr.screen_scanlines = scrscan;
244 vfattr.screen_size = scrrow;
246 if(ioctl(fd, VGASETFONTATTR, &vfattr) == -1)
247 err(1, "ioctl VGASETFONTATTR failed, error");
252 loadfont(int fontset, int charscanlines, const unsigned char *font_table)
255 struct vgaloadchar vlc;
257 vlc.character_set = fontset;
258 vlc.character_scanlines = charscanlines;
260 for(i = 0; i < 256; i++)
263 for (j = 0; j < charscanlines; j++)
265 vlc.char_table[j] = font_table[j];
267 font_table += charscanlines;
268 if(ioctl(fd, VGALOADCHAR, &vlc) == -1)
269 err(1, "ioctl VGALOADCHAR failed, error");
274 printvgafontattr(int charset)
276 struct vgafontattr vfattr;
277 static int sizetab[] = { 25, 28, 35, 40, 43, 50 };
279 vfattr.character_set = charset;
281 if(ioctl(fd, VGAGETFONTATTR, &vfattr) == -1)
282 err(1, "ioctl VGAGETFONTATTR failed, error");
283 printf(" %d ",charset);
284 if(vfattr.font_loaded)
288 printf(" %2.2d ", sizetab[vfattr.screen_size]);
290 (((int)vfattr.character_scanlines) & 0x1f) + 1);
292 ((int)vfattr.screen_scanlines+0x101));
304 printf("\nEGA/VGA Charactersets Status Info:\n\n");
305 printf("Set Status Lines CharScanLines ScreenScanLines\n");
306 printf("--- ------ ----- ------------- ---------------\n");
312 fprintf(stderr,"\nloadfont - load font into ega/vga font ram for pcvt video driver\n");
313 fprintf(stderr,"usage: loadfont -c <cset> -d <dev> -f <name> -i\n");
314 fprintf(stderr," -c <cset> characterset to load (ega 0..3, vga 0..7)\n");
315 fprintf(stderr," -d <dev> specify device\n");
316 fprintf(stderr," -f <name> filename containing binary font data\n");
317 fprintf(stderr," -i print status and types of loaded fonts (default)\n");