From: Joshua Wise Date: Sun, 14 Dec 2008 00:50:39 +0000 (-0500) Subject: Add a first cut at text. X-Git-Url: http://git.joshuawise.com/netwatch.git/commitdiff_plain/cdde55f54a0880bde5694fcdea8e386ada0cd5ce?ds=sidebyside;hp=b496c2b16e66ba34a8725fb49a1bf27f0588939c Add a first cut at text. --- diff --git a/aseg-paging/Makefile b/aseg-paging/Makefile index 73d7feb..1eeee83 100644 --- a/aseg-paging/Makefile +++ b/aseg-paging/Makefile @@ -47,6 +47,7 @@ OBJS = ../ich2/smi.o \ ../video/tnt2.o \ ../video/fb.o \ ../video/checksumrect.o \ + ../video/text.o \ drivers.o \ ../lib/minilib.o \ ../lib/doprnt.o \ diff --git a/aseg-paging/firstrun.c b/aseg-paging/firstrun.c index 48a1ac0..0233a7c 100644 --- a/aseg-paging/firstrun.c +++ b/aseg-paging/firstrun.c @@ -5,6 +5,7 @@ #include #include "vga-overlay.h" #include +#include #include "../net/net.h" extern int _bss, _bssend; @@ -43,6 +44,9 @@ void smi_init() { output("Found a card"); } outputf("Driver probe complete"); + + /* Load in fonts. */ + text_init(); smi_register_handler(SMI_EVENT_FAST_TIMER, timer_handler); smi_enable_event(SMI_EVENT_FAST_TIMER); diff --git a/include/fb.h b/include/fb.h index 19dae0b..dd86894 100644 --- a/include/fb.h +++ b/include/fb.h @@ -21,6 +21,7 @@ struct vmode { struct fbdevice { unsigned char *fbaddr; + unsigned char *textbase; /* A safe place to put a textfb. */ void *priv; getvmode_t getvmode; checksum_rect_t checksum_rect; diff --git a/include/text.h b/include/text.h new file mode 100644 index 0000000..9506d40 --- /dev/null +++ b/include/text.h @@ -0,0 +1,9 @@ +#ifndef _TEXT_H + +#include + +extern void text_init(); +extern void text_render(unsigned char *buf, unsigned int x, unsigned int y, unsigned int w, unsigned int h); +extern uint32_t text_checksum(int x, int y, int w, int h); + +#endif diff --git a/video/text.c b/video/text.c new file mode 100644 index 0000000..c9068b9 --- /dev/null +++ b/video/text.c @@ -0,0 +1,95 @@ +#include +#include +#include +#include +#include + +static unsigned char _font[256 * 32]; + +/* Must be called from a firstrun context, where we don't care about saving + * 0x3CE state. */ +void text_init() +{ + unsigned char oldread; + outb(0x3CE, 0x05 /* Mode register */); + outb(0x3CF, inb(0x3CF) & ~(0x10 /* Odd/even */)); + outb(0x3CE, 0x04 /* Read register */); + oldread = inb(0x3CF); + outb(0x3CF, 0x02 /* Font plane */); + memcpy(_font, p2v(0xB8000), sizeof(_font)); + outb(0x3CF, oldread); +} + +void text_render(unsigned char *buf, unsigned int x, unsigned int y, unsigned int w, unsigned int h) +{ + unsigned char *video = p2v(0xB8000); + unsigned int textx = x / 9; + unsigned int texty = y / 14; + unsigned int cx, cy; + unsigned char ch, at, font; + + for (cy = y; cy < (y + h); cy++) + { + texty = cy / 14; + textx = cx / 9; + ch = video[texty * 50 + textx * 2]; + at = video[texty * 50 + textx * 2 + 1]; + font = _font[ch * 32 + cy % 14]; + for (cx = x; cx < (x + w); cx++) + { + unsigned int pos = cx % 9; + if (pos == 0) + { + textx = cx / 9; + ch = video[texty * 50 + textx * 2]; + at = video[texty * 50 + textx * 2 + 1]; + font = _font[ch * 32 + cy % 14]; + } + /* XXX always BGR888 */ + if (pos == 8) /* 9th pixel is cloned */ + pos = 7; + if ((font >> (7 - pos)) & 1) + { + *(buf++) = (at & 0x01) ? 0xFF : 0x00; + *(buf++) = (at & 0x02) ? 0xFF : 0x00; + *(buf++) = (at & 0x04) ? 0xFF : 0x00; + } else { + *(buf++) = (at & 0x10) ? 0xFF : 0x00; + *(buf++) = (at & 0x20) ? 0xFF : 0x00; + *(buf++) = (at & 0x40) ? 0xFF : 0x00; + } + } + } +} + +uint32_t text_checksum(int x, int y, int w, int h) +{ + unsigned char *video = p2v(0xB8000); + unsigned int textx = x / 9; + unsigned int texty = y / 14; + int cx, cy; + unsigned char ch, at; + uint32_t cksm = 0; + + for (cy = y; cy < (y + h); cy++) + { + texty = cy / 14; + textx = cx / 9; + ch = video[texty * 50 + textx * 2]; + at = video[texty * 50 + textx * 2 + 1]; + for (cx = x; cx < (x + w); cx++) + { + unsigned int pos = cx % 9; + if (pos == 0) + { + textx = cx / 9; + ch = video[texty * 50 + textx * 2]; + at = video[texty * 50 + textx * 2 + 1]; + } + + cksm += ch + (at << 16); + } + } + + return cksm; +} diff --git a/video/tnt2.c b/video/tnt2.c index c79912c..f23a9d7 100644 --- a/video/tnt2.c +++ b/video/tnt2.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "checksumrect.h" @@ -33,11 +34,11 @@ static void tnt2_getvmode(void *priv) break; case 0: tnt2_fb.curmode.text = 1; - tnt2_fb.checksum_rect = (checksum_rect_t) 0; + tnt2_fb.checksum_rect = (checksum_rect_t) text_checksum; break; default: tnt2_fb.curmode.text = 1; - tnt2_fb.checksum_rect = (checksum_rect_t) 0; + tnt2_fb.checksum_rect = (checksum_rect_t) text_checksum; outputf("Unknown TNT2 format %x", vgard(0x28)); break; }