]> Joshua Wise's Git repositories - netwatch.git/commitdiff
Add a first cut at text.
authorJoshua Wise <joshua@rebirth.joshuawise.com>
Sun, 14 Dec 2008 00:50:39 +0000 (19:50 -0500)
committerJoshua Wise <joshua@rebirth.joshuawise.com>
Sun, 14 Dec 2008 00:50:39 +0000 (19:50 -0500)
aseg-paging/Makefile
aseg-paging/firstrun.c
include/fb.h
include/text.h [new file with mode: 0644]
video/text.c [new file with mode: 0644]
video/tnt2.c

index 73d7feb4d432e90f4f3d781a01b42bc012dc71b2..1eeee83eb8de2f5411eba421504b553c0b5e2c9e 100644 (file)
@@ -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 \
index 48a1ac04b076caf9d76b3723fe11561fbba2087b..0233a7c6ac334a8ff11a21c0eb54f79e329c6b91 100644 (file)
@@ -5,6 +5,7 @@
 #include <output.h>
 #include "vga-overlay.h"
 #include <smram.h>
+#include <text.h>
 #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);
index 19dae0bb65ee481814483f7e048d8ab38287c98a..dd868948071b823966d2d8af260838597b51ca9e 100644 (file)
@@ -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 (file)
index 0000000..9506d40
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef _TEXT_H
+
+#include <stdint.h>
+
+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 (file)
index 0000000..c9068b9
--- /dev/null
@@ -0,0 +1,95 @@
+#include <io.h>
+#include <text.h>
+#include <paging.h>
+#include <minilib.h>
+#include <stdint.h>
+
+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;
+}
index c79912ca9a435a893a32f27d66bd779ed05999c2..f23a9d7d86aced6f786d0232edaf2f6d2769a299 100644 (file)
@@ -4,6 +4,7 @@
 #include <output.h>
 #include <fb.h>
 #include <paging.h>
+#include <text.h>
 
 #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;
        }
This page took 0.028445 seconds and 4 git commands to generate.