OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [mw/] [src/] [drivers/] [romfont.c] - Blame information for rev 1773

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
/*
2
 * Copyright (c) 1999, 2000 Greg Haerr <greg@censoft.com>
3
 *
4
 * Screen Driver Utilities
5
 *
6
 * PC ROM Font Routine Header (PC ROM font format)
7
 *
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.
11
 *
12
 * The environment variable CHARHEIGHT if set will set the assumed rom
13
 * font character height, which defaults to 14.
14
 */
15
#include <stdlib.h>
16
#include "device.h"
17
#include "vgaplan4.h"
18
#include "romfont.h"
19
 
20
/* local data*/
21
int     ROM_CHAR_HEIGHT = 14;   /* number of scan lines in fonts in ROM */
22
FARADDR rom_char_addr;
23
 
24
/* handling routines for core rom fonts*/
25
static MWFONTPROCS fontprocs = {
26
        MWTF_ASCII,             /* routines expect ascii*/
27
        pcrom_getfontinfo,
28
        pcrom_gettextsize,
29
        pcrom_gettextbits,
30
        pcrom_unloadfont,
31
        corefont_drawtext,
32
        NULL,                   /* setfontsize*/
33
        NULL,                   /* setfontrotation*/
34
        NULL,                   /* setfontattr*/
35
};
36
 
37
/* first font is default font if no match*/
38
MWCOREFONT pcrom_fonts[NUMBER_FONTS] = {
39
        {&fontprocs, 0, 0, 0, MWFONT_OEM_FIXED, NULL}
40
};
41
 
42
/* init PC ROM routines, must be called in graphics mode*/
43
void
44
pcrom_init(PSD psd)
45
{
46
        char *  p;
47
 
48
        /* use INT 10h to get address of rom character table*/
49
        rom_char_addr = int10(FNGETROMADDR, GETROM8x14);
50
#if 0
51
        /* check bios data area for actual character height,
52
         * as the returned font isn't always 14 high
53
         */
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;
57
#endif
58
        p = getenv("CHARHEIGHT");
59
        if(p)
60
                ROM_CHAR_HEIGHT = atoi(p);
61
}
62
 
63
/*
64
 * PC ROM low level get font info routine.  This routine
65
 * returns info on a single bios ROM font.
66
 */
67
MWBOOL
68
pcrom_getfontinfo(PMWFONT pfont,PMWFONTINFO pfontinfo)
69
{
70
        int     i;
71
 
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;
80
        return TRUE;
81
}
82
 
83
/*
84
 * PC ROM low level routine to calc bounding box for text output.
85
 * Handles bios ROM font only.
86
 */
87
void
88
pcrom_gettextsize(PMWFONT pfont, const void *str, int cc,
89
        MWCOORD *pwidth, MWCOORD *pheight, MWCOORD *pbase)
90
{
91
        *pwidth = ROM_CHAR_WIDTH * cc;
92
        *pheight = ROM_CHAR_HEIGHT;
93
        *pbase = ROM_CHAR_HEIGHT;
94
}
95
 
96
/*
97
 * PC ROM low level routine to get the bitmap associated
98
 * with a character.  Handles bios ROM font only.
99
 */
100
void
101
pcrom_gettextbits(PMWFONT pfont, int ch, MWIMAGEBITS *retmap,
102
        MWCOORD *pwidth, MWCOORD *pheight, MWCOORD *pbase)
103
{
104
        FARADDR bits;
105
        int     n;
106
 
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;
111
 
112
        *pwidth = ROM_CHAR_WIDTH;
113
        *pheight = ROM_CHAR_HEIGHT;
114
        *pbase = ROM_CHAR_HEIGHT;
115
}
116
 
117
void
118
pcrom_unloadfont(PMWFONT pfont)
119
{
120
        /* rom fonts can't be unloaded*/
121
}
122
 
123
#if NOTUSED
124
/*
125
 * Low level text draw routine, called only if no clipping
126
 * is required.  This routine draws ROM font characters only.
127
 */
128
void
129
pcrom_drawtext(PMWFONT pfont, PSD psd, COORD x, COORD y,
130
        const void *text, int n, PIXELVAL fg)
131
{
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 */
136
 
137
        /* x,y is bottom left corner*/
138
        y -= (ROM_CHAR_HEIGHT - 1);
139
        while (n-- > 0) {
140
                pfont->GetTextBits(pfont, *s++, bitmap, &width, &height);
141
                gen_drawbitmap(psd, x, y, width, height, bitmap, fg);
142
                x += width;
143
        }
144
}
145
 
146
/*
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.
150
 */
151
void
152
gen_drawbitmap(PSD psd,COORD x, COORD y, COORD width, COORD height,
153
        IMAGEBITS *table, PIXELVAL fgcolor)
154
{
155
  COORD minx;
156
  COORD maxx;
157
  IMAGEBITS bitvalue;   /* bitmap word value */
158
  int bitcount;                 /* number of bits left in bitmap word */
159
 
160
  minx = x;
161
  maxx = x + width - 1;
162
  bitcount = 0;
163
  while (height > 0) {
164
        if (bitcount <= 0) {
165
                bitcount = IMAGE_BITSPERIMAGE;
166
                bitvalue = *table++;
167
        }
168
        if (IMAGE_TESTBIT(bitvalue))
169
                psd->DrawPixel(psd, x, y, fgcolor);
170
        bitvalue = IMAGE_SHIFTBIT(bitvalue);
171
        --bitcount;
172
        if (x++ == maxx) {
173
                x = minx;
174
                ++y;
175
                --height;
176
                bitcount = 0;
177
        }
178
  }
179
}
180
#endif /* NOTUSED*/

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.