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