9 #include <video_defines.h>
11 static unsigned char _font[256 * 32];
13 /* XXX reunify this with vga-overlay? */
14 #define VRAM_BASE 0xA0000UL
15 #define TEXT_CONSOLE_OFFSET 0x18000UL
17 #define TEXT_CONSOLE_BASE (VRAM_BASE + TEXT_CONSOLE_OFFSET)
19 static unsigned char vga_read(unsigned char idx)
21 outb(CRTC_IDX_REG, idx);
22 return inb(CRTC_DATA_REG);
25 static char * vga_base()
29 + (((unsigned int) vga_read(CRTC_START_ADDR_MSB_IDX)) << 9)
30 + (((unsigned int) vga_read(CRTC_START_ADDR_LSB_IDX)) << 1)
34 /* Must be called from a firstrun context, where we don't care about saving
38 unsigned char oldread;
40 smram_state_t old_state = smram_save_state();
41 outb(0x3CE, 0x06 /* Miscellaneous */);
43 outb(0x3C4, 0x04 /* Seq memory mode */);
44 outb(0x3C5, inb(0x3C5) | 0x04);
45 outb(0x3CE, 0x05 /* Mode */);
46 outb(0x3CF, inb(0x3CF) & ~0x10);
47 outb(0x3CE, 0x04 /* Read register */);
49 outb(0x3CF, 0x02 /* Font plane */);
51 smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
52 memcpy(_font, p2v(0xB8000), sizeof(_font));
53 smram_restore_state(old_state);
56 outb(0x3CE, 0x06 /* Miscellaneous */);
58 outb(0x3CE, 0x05 /* Mode */);
59 outb(0x3CF, inb(0x3CF) | 0x10);
60 outb(0x3C4, 0x04 /* Seq memory mode */);
61 outb(0x3C5, inb(0x3C5) & ~0x04);
64 void text_render(char *buf, int x, int y, int w, int h)
66 unsigned char *video = (unsigned char *)vga_base();
67 unsigned int textx = x / 9;
68 unsigned int texty = y / 16;
70 unsigned char ch, at, font;
71 smram_state_t old_state = smram_save_state();
73 outputf("text_render: (%d,%d),(%d,%d)", x, y, w, h);
75 smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
76 for (cy = y; cy < (y + h); cy++)
81 ch = video[texty * 160 + textx * 2];
82 at = video[texty * 160 + textx * 2 + 1];
83 font = _font[ch * 32 + cy % 16];
84 for (cx = x; cx < (x + w); cx++)
86 unsigned int pos = cx % 8;
90 ch = video[texty * 160 + textx * 2];
91 at = video[texty * 160 + textx * 2 + 1];
92 font = _font[ch * 32 + cy % 16];
94 /* XXX always BGR888 */
95 if (pos == 8) /* 9th pixel is cloned */
97 if ((font >> (7 - pos)) & 1)
99 *(buf++) = (at & 0x01) ? 0xFF : 0x00;
100 *(buf++) = (at & 0x02) ? 0xFF : 0x00;
101 *(buf++) = (at & 0x04) ? 0xFF : 0x00;
103 *(buf++) = (at & 0x10) ? 0xFF : 0x00;
104 *(buf++) = (at & 0x20) ? 0xFF : 0x00;
105 *(buf++) = (at & 0x40) ? 0xFF : 0x00;
110 smram_restore_state(old_state);
113 uint32_t text_checksum(int x, int y, int w, int h)
115 unsigned char *video = (unsigned char *)vga_base();
116 unsigned int textx = x / 8;
117 unsigned int texty = y / 16;
120 smram_state_t old_state = smram_save_state();
122 smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
124 for (cy = y; cy < (y + h); cy++)
129 cksm = crc32(video + texty * 160 + textx * 2, (w / 8) * 2 + 2, cksm); /* Err on the side of 'too many'. */
132 smram_restore_state(old_state);