]> Joshua Wise's Git repositories - netwatch.git/blame_incremental - video/text.c
Add a first cut at text.
[netwatch.git] / video / text.c
... / ...
CommitLineData
1#include <io.h>
2#include <text.h>
3#include <paging.h>
4#include <minilib.h>
5#include <stdint.h>
6
7static unsigned char _font[256 * 32];
8
9/* Must be called from a firstrun context, where we don't care about saving
10 * 0x3CE state. */
11void text_init()
12{
13 unsigned char oldread;
14 outb(0x3CE, 0x05 /* Mode register */);
15 outb(0x3CF, inb(0x3CF) & ~(0x10 /* Odd/even */));
16 outb(0x3CE, 0x04 /* Read register */);
17 oldread = inb(0x3CF);
18 outb(0x3CF, 0x02 /* Font plane */);
19 memcpy(_font, p2v(0xB8000), sizeof(_font));
20 outb(0x3CF, oldread);
21}
22
23void text_render(unsigned char *buf, unsigned int x, unsigned int y, unsigned int w, unsigned int h)
24{
25 unsigned char *video = p2v(0xB8000);
26 unsigned int textx = x / 9;
27 unsigned int texty = y / 14;
28 unsigned int cx, cy;
29 unsigned char ch, at, font;
30
31 for (cy = y; cy < (y + h); cy++)
32 {
33 texty = cy / 14;
34 textx = cx / 9;
35 ch = video[texty * 50 + textx * 2];
36 at = video[texty * 50 + textx * 2 + 1];
37 font = _font[ch * 32 + cy % 14];
38 for (cx = x; cx < (x + w); cx++)
39 {
40 unsigned int pos = cx % 9;
41 if (pos == 0)
42 {
43 textx = cx / 9;
44 ch = video[texty * 50 + textx * 2];
45 at = video[texty * 50 + textx * 2 + 1];
46 font = _font[ch * 32 + cy % 14];
47 }
48 /* XXX always BGR888 */
49 if (pos == 8) /* 9th pixel is cloned */
50 pos = 7;
51 if ((font >> (7 - pos)) & 1)
52 {
53 *(buf++) = (at & 0x01) ? 0xFF : 0x00;
54 *(buf++) = (at & 0x02) ? 0xFF : 0x00;
55 *(buf++) = (at & 0x04) ? 0xFF : 0x00;
56 } else {
57 *(buf++) = (at & 0x10) ? 0xFF : 0x00;
58 *(buf++) = (at & 0x20) ? 0xFF : 0x00;
59 *(buf++) = (at & 0x40) ? 0xFF : 0x00;
60 }
61 }
62 }
63}
64
65uint32_t text_checksum(int x, int y, int w, int h)
66{
67 unsigned char *video = p2v(0xB8000);
68 unsigned int textx = x / 9;
69 unsigned int texty = y / 14;
70 int cx, cy;
71 unsigned char ch, at;
72 uint32_t cksm = 0;
73
74 for (cy = y; cy < (y + h); cy++)
75 {
76 texty = cy / 14;
77 textx = cx / 9;
78 ch = video[texty * 50 + textx * 2];
79 at = video[texty * 50 + textx * 2 + 1];
80 for (cx = x; cx < (x + w); cx++)
81 {
82 unsigned int pos = cx % 9;
83 if (pos == 0)
84 {
85 textx = cx / 9;
86 ch = video[texty * 50 + textx * 2];
87 at = video[texty * 50 + textx * 2 + 1];
88 }
89
90 cksm += ch + (at << 16);
91 }
92 }
93
94 return cksm;
95}
This page took 0.027561 seconds and 4 git commands to generate.