]> Joshua Wise's Git repositories - netwatch.git/blame - video/text.c
Modify crc32 users to behave better when crcing multiple things into one CRC.
[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>
74032dae
JW
6#include <output.h>
7#include <smram.h>
1deef7f3 8#include <crc32.h>
cdde55f5
JW
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;
74032dae 17 smram_state_t old_state = smram_save_state();
cdde55f5
JW
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 */);
74032dae 23 smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
cdde55f5 24 memcpy(_font, p2v(0xB8000), sizeof(_font));
74032dae 25 smram_restore_state(old_state);
cdde55f5
JW
26 outb(0x3CF, oldread);
27}
28
66cd7e82 29void text_render(char *buf, int x, int y, int w, int h)
cdde55f5 30{
74032dae 31 unsigned char *video = (unsigned char *)0xB8000;
cdde55f5
JW
32 unsigned int textx = x / 9;
33 unsigned int texty = y / 14;
34 unsigned int cx, cy;
35 unsigned char ch, at, font;
74032dae 36 smram_state_t old_state = smram_save_state();
cdde55f5 37
53b39ad0 38 outputf("text_render: (%d,%d),(%d,%d)", buf, x, y, w, h);
74032dae
JW
39
40 smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
cdde55f5
JW
41 for (cy = y; cy < (y + h); cy++)
42 {
77671f96 43 cx = x;
cdde55f5
JW
44 texty = cy / 14;
45 textx = cx / 9;
7364b727
JW
46 ch = video[texty * 160 + textx * 2];
47 at = video[texty * 160 + textx * 2 + 1];
cdde55f5
JW
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;
7364b727
JW
55 ch = video[texty * 160 + textx * 2];
56 at = video[texty * 160 + textx * 2 + 1];
cdde55f5
JW
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 }
66cd7e82 72 *(buf++) = 0;
cdde55f5
JW
73 }
74 }
74032dae 75 smram_restore_state(old_state);
cdde55f5
JW
76}
77
78uint32_t text_checksum(int x, int y, int w, int h)
79{
74032dae 80 unsigned char *video = (unsigned char *)0xB8000;
cdde55f5
JW
81 unsigned int textx = x / 9;
82 unsigned int texty = y / 14;
83 int cx, cy;
cdde55f5 84 uint32_t cksm = 0;
74032dae
JW
85 smram_state_t old_state = smram_save_state();
86
74032dae 87 smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
cdde55f5
JW
88
89 for (cy = y; cy < (y + h); cy++)
90 {
77671f96 91 cx = x;
cdde55f5
JW
92 texty = cy / 14;
93 textx = cx / 9;
f2da68c5 94 cksm = crc32(video + texty * 160 + textx * 2, (w / 9) * 2 + 2, cksm); /* Err on the side of 'too many'. */
cdde55f5
JW
95 }
96
74032dae
JW
97 smram_restore_state(old_state);
98
cdde55f5
JW
99 return cksm;
100}
This page took 0.032671 seconds and 4 git commands to generate.