2 * Copyright (c) 1999, 2000 Greg Haerr <greg@censoft.com>
4 * Screen Driver Utilities
6 * PC ROM Font Routine Header (PC ROM font format)
8 * This file contains the PC ROM format low-level font/text
9 * drawing routines. Only fixed pitch fonts are supported.
10 * The ROM character matrix is used for the text bitmaps.
12 * The environment variable CHARHEIGHT if set will set the assumed rom
13 * font character height, which defaults to 14.
21 int ROM_CHAR_HEIGHT = 14; /* number of scan lines in fonts in ROM */
22 FARADDR rom_char_addr;
24 /* handling routines for core rom fonts*/
25 static MWFONTPROCS fontprocs = {
26 MWTF_ASCII, /* routines expect ascii*/
32 NULL, /* setfontsize*/
33 NULL, /* setfontrotation*/
34 NULL, /* setfontattr*/
37 /* first font is default font if no match*/
38 MWCOREFONT pcrom_fonts[NUMBER_FONTS] = {
39 {&fontprocs, 0, 0, 0, MWFONT_OEM_FIXED, NULL}
42 /* init PC ROM routines, must be called in graphics mode*/
48 /* use INT 10h to get address of rom character table*/
49 rom_char_addr = int10(FNGETROMADDR, GETROM8x14);
51 /* check bios data area for actual character height,
52 * as the returned font isn't always 14 high
54 ROM_CHAR_HEIGHT = GETBYTE_FP(MK_FP(0x0040, 0x0085));
55 if(ROM_CHAR_HEIGHT > MAX_ROM_HEIGHT)
56 ROM_CHAR_HEIGHT = MAX_ROM_HEIGHT;
58 p = getenv("CHARHEIGHT");
60 ROM_CHAR_HEIGHT = atoi(p);
64 * PC ROM low level get font info routine. This routine
65 * returns info on a single bios ROM font.
68 pcrom_getfontinfo(PMWFONT pfont,PMWFONTINFO pfontinfo)
72 pfontinfo->maxwidth = ROM_CHAR_WIDTH;
73 pfontinfo->height = ROM_CHAR_HEIGHT;
74 pfontinfo->baseline = ROM_CHAR_HEIGHT;
75 pfontinfo->firstchar = 0;
76 pfontinfo->lastchar = 255;
77 pfontinfo->fixed = TRUE;
78 for (i = 0; i < 256; i++)
79 pfontinfo->widths[i] = ROM_CHAR_WIDTH;
84 * PC ROM low level routine to calc bounding box for text output.
85 * Handles bios ROM font only.
88 pcrom_gettextsize(PMWFONT pfont, const void *str, int cc,
89 MWCOORD *pwidth, MWCOORD *pheight, MWCOORD *pbase)
91 *pwidth = ROM_CHAR_WIDTH * cc;
92 *pheight = ROM_CHAR_HEIGHT;
93 *pbase = ROM_CHAR_HEIGHT;
97 * PC ROM low level routine to get the bitmap associated
98 * with a character. Handles bios ROM font only.
101 pcrom_gettextbits(PMWFONT pfont, int ch, MWIMAGEBITS *retmap,
102 MWCOORD *pwidth, MWCOORD *pheight, MWCOORD *pbase)
107 /* read character bits from rom*/
108 bits = rom_char_addr + ch * ROM_CHAR_HEIGHT;
109 for(n=0; n<ROM_CHAR_HEIGHT; ++n)
110 *retmap++ = GETBYTE_FP(bits++) << 8;
112 *pwidth = ROM_CHAR_WIDTH;
113 *pheight = ROM_CHAR_HEIGHT;
114 *pbase = ROM_CHAR_HEIGHT;
118 pcrom_unloadfont(PMWFONT pfont)
120 /* rom fonts can't be unloaded*/
125 * Low level text draw routine, called only if no clipping
126 * is required. This routine draws ROM font characters only.
129 pcrom_drawtext(PMWFONT pfont, PSD psd, COORD x, COORD y,
130 const void *text, int n, PIXELVAL fg)
132 const unsigned char * str = text;
133 COORD width; /* width of character */
134 COORD height; /* height of character */
135 IMAGEBITS bitmap[MAX_ROM_HEIGHT]; /* bitmap for character */
137 /* x,y is bottom left corner*/
138 y -= (ROM_CHAR_HEIGHT - 1);
140 pfont->GetTextBits(pfont, *s++, bitmap, &width, &height);
141 gen_drawbitmap(psd, x, y, width, height, bitmap, fg);
147 * Generalized low level bitmap output routine, called
148 * only if no clipping is required. Only the set bits
149 * in the bitmap are drawn, in the foreground color.
152 gen_drawbitmap(PSD psd,COORD x, COORD y, COORD width, COORD height,
153 IMAGEBITS *table, PIXELVAL fgcolor)
157 IMAGEBITS bitvalue; /* bitmap word value */
158 int bitcount; /* number of bits left in bitmap word */
161 maxx = x + width - 1;
165 bitcount = IMAGE_BITSPERIMAGE;
168 if (IMAGE_TESTBIT(bitvalue))
169 psd->DrawPixel(psd, x, y, fgcolor);
170 bitvalue = IMAGE_SHIFTBIT(bitvalue);