]> Joshua Wise's Git repositories - netwatch.git/blame - aseg-paging/vga-overlay.c
Convert the transmitter to be a ring buffer, too.
[netwatch.git] / aseg-paging / vga-overlay.c
CommitLineData
9e2a82e4
JP
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>
bf47740a 7#include <serial.h>
9e2a82e4
JP
8
9#define LOGLEN 96
10#define LOG_ONSCREEN 4
11
12static char logents[LOGLEN][41] = {{0}};
13static int prodptr = 0;
14static 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
23void vga_flush_imm(int imm)
24{
25 flush_imm = imm;
26}
27
28static unsigned char vga_read(unsigned char idx)
29{
30 outb(CRTC_IDX_REG, idx);
31 return inb(CRTC_DATA_REG);
32}
33
34static 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
a02e8abd 43void strblit(char *src, int row, int col, int fill)
9e2a82e4
JP
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;
a02e8abd 57 col++;
9e2a82e4 58 }
a02e8abd
JW
59 if (fill)
60 while (col < 80)
61 {
62 *(destp++) = ' ';
63 *(destp++) = COLOR;
64 col++;
65 }
9e2a82e4
JP
66
67 outb(0x80, 0x3F);
68 smram_restore_state(old_state);
69 outb(0x80, 0x40);
70}
71
72void outlog()
73{
a02e8abd 74 int y;
9e2a82e4 75
9e2a82e4 76 for (y = -LOG_ONSCREEN; y < 0; y++)
a02e8abd 77 strblit(logents[(y + prodptr) % LOGLEN], y + LOG_ONSCREEN, 40, 1);
9e2a82e4
JP
78}
79
80void dolog(const char *s)
81{
82 strcpy(logents[prodptr], s);
83 prodptr = (prodptr + 1) % LOGLEN;
bf47740a 84 while (*s)
5a626f09 85 serial_tx(*(s++));
113df320
JW
86 serial_tx('\r');
87 serial_tx('\n');
9e2a82e4
JP
88 if (flush_imm)
89 outlog();
90}
91void (*output)(const char *s) = dolog;
92
93void dologf(const char *fmt, ...)
94{
113df320
JW
95 char *s;
96 va_list va;
97
98 va_start(va, fmt);
99 vsnprintf(logents[prodptr], 40, fmt, va);
100 s = logents[prodptr];
101 while (*s)
102 serial_tx(*(s++));
103 serial_tx('\r');
104 serial_tx('\n');
105 va_end(va);
106 prodptr = (prodptr + 1) % LOGLEN;
107 if (flush_imm)
108 outlog();
9e2a82e4
JP
109}
110void (*outputf)(const char *s, ...) = dologf;
111
112void dump_log (char * target) {
113 memcpy(target, logents, sizeof(logents));
114}
115
This page took 0.037346 seconds and 4 git commands to generate.