]> Joshua Wise's Git repositories - netwatch.git/blame - video/text.c
Link text into copy_pixels.
[netwatch.git] / video / text.c
CommitLineData
cdde55f5
JW
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
66cd7e82 23void text_render(char *buf, int x, int y, int w, int h)
cdde55f5
JW
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 }
66cd7e82 61 *(buf++) = 0;
cdde55f5
JW
62 }
63 }
64}
65
66uint32_t text_checksum(int x, int y, int w, int h)
67{
68 unsigned char *video = p2v(0xB8000);
69 unsigned int textx = x / 9;
70 unsigned int texty = y / 14;
71 int cx, cy;
72 unsigned char ch, at;
73 uint32_t cksm = 0;
74
75 for (cy = y; cy < (y + h); cy++)
76 {
77 texty = cy / 14;
78 textx = cx / 9;
79 ch = video[texty * 50 + textx * 2];
80 at = video[texty * 50 + textx * 2 + 1];
81 for (cx = x; cx < (x + w); cx++)
82 {
83 unsigned int pos = cx % 9;
84 if (pos == 0)
85 {
86 textx = cx / 9;
87 ch = video[texty * 50 + textx * 2];
88 at = video[texty * 50 + textx * 2 + 1];
89 }
90
91 cksm += ch + (at << 16);
92 }
93 }
94
95 return cksm;
96}
This page took 0.030672 seconds and 4 git commands to generate.