]> Joshua Wise's Git repositories - netwatch.git/blob - aseg-paging/vga-overlay.c
Working serial output in pagingland. Continues to run, too.
[netwatch.git] / aseg-paging / vga-overlay.c
1 #include <io.h>
2 #include <smram.h>
3 #include <video_defines.h>
4 #include <minilib.h>
5 #include <stdarg.h>
6 #include <output.h>
7 #include <serial.h>
8
9 #define LOGLEN 96
10 #define LOG_ONSCREEN 4
11
12 static char logents[LOGLEN][41] = {{0}};
13 static int prodptr = 0;
14 static int flush_imm = 0;
15
16 #define VRAM_BASE               0xA0000UL
17 #define TEXT_CONSOLE_OFFSET     0x18000UL 
18
19 #define TEXT_CONSOLE_BASE       (VRAM_BASE + TEXT_CONSOLE_OFFSET)
20
21 #define COLOR                   0x1F
22
23 void vga_flush_imm(int imm)
24 {
25         flush_imm = imm;
26 }
27
28 static unsigned char vga_read(unsigned char idx)
29 {
30         outb(CRTC_IDX_REG, idx);
31         return inb(CRTC_DATA_REG);
32 }
33
34 static char * vga_base()
35 {
36         return (char *) (
37                 TEXT_CONSOLE_BASE
38                 + (((unsigned int) vga_read(CRTC_START_ADDR_MSB_IDX)) << 9)
39                 + (((unsigned int) vga_read(CRTC_START_ADDR_LSB_IDX)) << 1)
40         );
41 }
42
43 void strblit(char *src, int row, int col)
44 {
45         char *destp = vga_base() + row * 80 * 2 + col * 2;
46         outb(0x80, 0x3C);
47         smram_state_t old_state = smram_save_state();
48         outb(0x80, 0x3D);
49
50         smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
51         outb(0x80, 0x3E);
52
53         while (*src)
54         {
55                 *(destp++) = *(src++);
56                 *(destp++) = COLOR;
57         }
58
59         outb(0x80, 0x3F);
60         smram_restore_state(old_state);
61         outb(0x80, 0x40);
62 }
63
64 void outlog()
65 {
66         int y, x;
67         char *basep = vga_base();
68
69         smram_state_t old_state = smram_save_state();
70
71         smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
72
73         for (y = 0; y < LOG_ONSCREEN; y++)
74                 for (x = 40; x < 80; x++)
75                 {
76                         basep[y*80*2+x*2] = ' ';
77                         basep[y*80*2+x*2+1] = 0x1F;
78                 }
79
80         smram_restore_state(old_state);
81         
82         for (y = -LOG_ONSCREEN; y < 0; y++)
83                 strblit(logents[(y + prodptr) % LOGLEN], y + LOG_ONSCREEN, 40);
84 }
85
86 void dolog(const char *s)
87 {
88         strcpy(logents[prodptr], s);
89         prodptr = (prodptr + 1) % LOGLEN;
90         while (*s)
91                 serial_tx(*(s++));
92         serial_tx('\r');
93         serial_tx('\n');
94         if (flush_imm)
95                 outlog();
96 }
97 void (*output)(const char *s) = dolog;
98
99 void dologf(const char *fmt, ...)
100 {
101         char *s;
102         va_list va;
103         
104         va_start(va, fmt);
105         vsnprintf(logents[prodptr], 40, fmt, va);
106         s = logents[prodptr];
107         while (*s)
108                 serial_tx(*(s++));
109         serial_tx('\r');
110         serial_tx('\n');
111         va_end(va);
112         prodptr = (prodptr + 1) % LOGLEN;
113         if (flush_imm)
114                 outlog();
115 }
116 void (*outputf)(const char *s, ...) = dologf;
117
118 void dump_log (char * target) {
119         memcpy(target, logents, sizeof(logents));
120 }
121
This page took 0.029486 seconds and 4 git commands to generate.