/* * fontload: load a font into a VGA or EGA monitor * * Written December 1991 by Orc (david parsons) for the public domain, except * as detailed below. * * Derived in part from Usefont, by Boon Song - copyright notice reproduced * below: * ----------------------------- * Copyright (C) 1991 Boon Song * P.O. Box 2013, OIT * Klamath Falls, OR 97601 * * TERMS & CONDITIONS: * * May be used and/or distributed for non-profitable purposes only * ----------------------------- * */ #define INCL_VIO #include #include #include #include #define VIO 0 #define EGA 2 #define VGA 3 VIOMODEINFO vmode; VIOCONFIGINFO vcfg; VIOFONTINFO vfont; char bfr[4096]; getscreeninfo() { vmode.cb = sizeof vmode; VioGetMode(&vmode, 0); } main(argc, argv) char **argv; { register long size; int pointsize; int ffd; int row; char fname[200]; char *ext; vcfg.cb = sizeof vcfg; if (VioGetConfig(0, &vcfg, VIO)) { fprintf(stderr, "Hello? I can't stat the display subsystem\n"); exit(1); } if (vcfg.adapter != VGA && vcfg.adapter != EGA) { fprintf(stderr, "You're not a VGA or EGA monitor\n"); exit(2); } getscreeninfo(); if (argc != 2) { vfont.type = VGFI_GETCURFONT; vfont.cb = sizeof vfont; VioGetFont(&vfont, VIO); printf("current font: cxCell=%d,cyCell=%d\n", vfont.cxCell, vfont.cyCell); exit(0); } if ((ffd=open(argv[1], O_RDONLY|O_BINARY)) < 0) { sprintf(fname, "%s.f16", argv[1]); if ((ffd=open(fname, O_RDONLY|O_BINARY)) < 0) { fprintf(stderr, "Can't read font %s\n", fname); exit(4); } } size = read(ffd, bfr, 4096); pointsize = size/256; switch (pointsize) { case 14:if(vcfg.adapter!=EGA) { fprintf(stderr, "Can't load an 8x14 font onto a VGA monitor\n"); exit(5); } vfont.cxCell = 8; vfont.cyCell = 14; row = 25; break; case 8: if(vcfg.adapter==EGA) { vfont.cxCell = 8; vfont.cyCell = 8; row = 43; } else { vfont.cxCell = 9; vfont.cyCell = 8; row = 50; } break; case 16:if(vcfg.adapter!=VGA) { fprintf(stderr, "Can't load an 8x16 font onto an EGA monitor\n"); exit(6); } else { vfont.cxCell = 9; vfont.cyCell = 16; row = 25; } break; default:fprintf(stderr, "Can't grok this font\n"); exit(7); } if (vmode.row != row) { /* need to change monitor resolution to fit the font. */ vmode.row = row; if (VioSetMode(&vmode, VIO) != 0) { fprintf(stderr, "Can't reset monitor to fit font\n"); exit(8); } } vfont.cb = sizeof vfont; vfont.type = 0; vfont.cbData = size; vfont.pbData = bfr; VioSetFont(&vfont, VIO); exit(0); } /* main */