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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [mw/] [src/] [fonts/] [convrom.c] - Blame information for rev 1782

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
 * PC Bios ROM font extractor
5
 * Note: ascent field of produced C file must be hand-editted
6
 */
7
#include "../../device.h"
8
#include "../vga.h"
9
 
10
/* rom font constants*/
11
int     ROM_CHAR_HEIGHT = 16;   /* number of scan lines in fonts in ROM */
12
#define ROM_CHAR_WIDTH  8       /* number of pixels for character width */
13
#define MAX_ROM_HEIGHT  16      /* max rom character height*/
14
#define FONT_CHARS      256     /* number of characters in font tables */
15
 
16
/* int10 functions*/
17
#define FNGR640x480     0x0012  /* function for graphics mode 640x480x16*/
18
#define FNGR640x350     0x0010  /* function for graphics mode 640x350x16*/
19
#define FNTEXT          0x0003  /* function for 80x25 text mode*/
20
#define FNGETROMADDR    0x1130  /* function for address of rom character table*/
21
#define GETROM8x14      0x0200  /* want address of ROM 8x14 char table*/
22
#define GETROM8x8       0x0300  /* want address of ROM 8x8 char table*/
23
#define GETROM8x16      0x0600  /* want address of ROM 8x16 char table*/
24
 
25
 
26
#define GRMODE          FNGR640x350
27
 
28
/* local data*/
29
FARADDR                 rom_char_addr;
30
 
31
void print_rom_table(void);
32
void print_char(int ch,MWIMAGEBITS *b, int w, int h);
33
void print_bits(MWIMAGEBITS *bits, int width, int height);
34
 
35
main()
36
{
37
        /* init bios graphics mode*/
38
        int10(GRMODE, 0);
39
 
40
        /* get address of rom character table*/
41
        rom_char_addr = int10(FNGETROMADDR, GETROM8x14);
42
 
43
        /* check bios data area for actual character height,
44
         * as the returned font isn't always 14 high
45
         */
46
#if 0
47
        ROM_CHAR_HEIGHT = GETBYTE_FP(MK_FP(0x0040, 0x0085));
48
#else
49
        ROM_CHAR_HEIGHT = 16;
50
#endif
51
 
52
        printf("/* Generated by convrom.exe*/\n");
53
        printf("#include \"device.h\"\n\n");
54
        printf("/* ROM %dx%d Font bios mode %x */\n\n",
55
                ROM_CHAR_WIDTH, ROM_CHAR_HEIGHT, GRMODE);
56
        printf("static MWIMAGEBITS rom%dx%d_bits[] = {\n\n",
57
                ROM_CHAR_WIDTH, ROM_CHAR_HEIGHT);
58
 
59
        print_rom_table();
60
 
61
        printf("};\n\n");
62
        printf("/* Exported structure definition. */\n"
63
                "MWCFONT font_rom%dx%d = {\n",
64
                ROM_CHAR_WIDTH, ROM_CHAR_HEIGHT);
65
        printf("\t\"rom%dx%d\",\n", ROM_CHAR_WIDTH, ROM_CHAR_HEIGHT);
66
        printf("\t%d,\n", ROM_CHAR_WIDTH);
67
        printf("\t%d,\n", ROM_CHAR_HEIGHT);
68
        printf("\t%d,\n", ROM_CHAR_HEIGHT);     /* ascent*/
69
        printf("\t0,\n\t256,\n");
70
        printf("\trom%dx%d_bits,\n", ROM_CHAR_WIDTH, ROM_CHAR_HEIGHT);
71
        printf("\t0,\n\t0\n");
72
        printf("};\n");
73
 
74
        /* init bios 80x25 text mode*/
75
        int10(FNTEXT, 0);
76
}
77
 
78
void
79
print_rom_table(void)
80
{
81
        FARADDR         bits;
82
        int             n;
83
        int             ch;
84
        MWIMAGEBITS *   p;
85
        MWIMAGEBITS     image[MAX_ROM_HEIGHT];
86
 
87
        for(ch=0; ch < 256; ++ch) {
88
                bits = rom_char_addr + ch * ROM_CHAR_HEIGHT;
89
                p = image;
90
                for(n=0; n<ROM_CHAR_HEIGHT; ++n)
91
                    *p++ = GETBYTE_FP(bits++) << 8;
92
                print_char(ch, image, ROM_CHAR_WIDTH, ROM_CHAR_HEIGHT);
93
                print_bits(image, ROM_CHAR_WIDTH, ROM_CHAR_HEIGHT);
94
                printf("\n");
95
        }
96
}
97
 
98
/* Character ! (0x21):
99
   ht=16, width=8
100
   +----------------+
101
   |                |
102
   |                |
103
   | *              |
104
   | *              |
105
   | *              |
106
   | *              |
107
   | *              |
108
   | *              |
109
   |                |
110
   | *              |
111
   |                |
112
   |                |
113
   +----------------+ */
114
 
115
void
116
print_char(int ch,MWIMAGEBITS *bits, int width, int height)
117
{
118
        COORD           x;
119
        int             bitcount;       /* number of bits left in bitmap word */
120
        MWIMAGEBITS     bitvalue;       /* bitmap word value */
121
 
122
        printf("/* Character %c (0x%02x):\n", ch? ch: ' ', ch);
123
        printf("   ht=%d, width=%d\n", height, width);
124
        printf("   +");
125
        for(x=0; x<width; ++x)
126
                printf("-");
127
        printf("+\n");
128
        x = 0;
129
        bitcount = 0;
130
        while (height > 0) {
131
            if (bitcount <= 0) {
132
                    printf("   |");
133
                    bitcount = MWIMAGE_BITSPERIMAGE;
134
                    bitvalue = *bits++;
135
            }
136
                if (MWIMAGE_TESTBIT(bitvalue))
137
                            printf("*");
138
                else printf(" ");
139
            bitvalue = MWIMAGE_SHIFTBIT(bitvalue);
140
            --bitcount;
141
            if (x++ == width-1) {
142
                    x = 0;
143
                    --height;
144
                    bitcount = 0;
145
                    printf("|\n");
146
            }
147
        }
148
        printf("   +");
149
        for(x=0; x<width; ++x)
150
                printf("-");
151
        printf("+ */\n");
152
}
153
 
154
#define MWIMAGE_GETBIT4(m)      (((m) & 0xf000) >> 12)
155
#define MWIMAGE_SHIFTBIT4(m)    ((IMAGEBITS) ((m) << 4))
156
 
157
void
158
print_bits(MWIMAGEBITS *bits, int width, int height)
159
{
160
        COORD           x;
161
        int             bitcount;       /* number of bits left in bitmap word */
162
        MWIMAGEBITS     bitvalue;       /* bitmap word value */
163
 
164
        x = 0;
165
        bitcount = 0;
166
        while (height > 0) {
167
            if (bitcount <= 0) {
168
                    printf("0x");
169
                    bitcount = MWIMAGE_BITSPERIMAGE;
170
                    bitvalue = *bits++;
171
            }
172
                printf("%x", MWIMAGE_GETBIT4(bitvalue));
173
            bitvalue = MWIMAGE_SHIFTBIT4(bitvalue);
174
            bitcount -= 4;
175
                x += 4;
176
            if (x >= width-1) {
177
                        if(MWIMAGE_BITSPERIMAGE > width)
178
                                for(x=MWIMAGE_BITSPERIMAGE-width; x>0; ) {
179
                                        printf("0");
180
                                        x -= 4;
181
                                }
182
                    x = 0;
183
                    --height;
184
                    bitcount = 0;
185
                    printf(",\n");
186
            }
187
        }
188
}

powered by: WebSVN 2.1.0

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