]> Joshua Wise's Git repositories - netwatch.git/blame - netwatch/vga-overlay.c
remove log from vga overlay
[netwatch.git] / netwatch / 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{
835f2e85 74/*
a02e8abd 75 int y;
9e2a82e4 76
9e2a82e4 77 for (y = -LOG_ONSCREEN; y < 0; y++)
4a718391 78 strblit(logents[(y + prodptr + LOGLEN) % LOGLEN], y + LOG_ONSCREEN, 40, 1);
835f2e85 79*/
9e2a82e4
JP
80}
81
82void dolog(const char *s)
83{
84 strcpy(logents[prodptr], s);
85 prodptr = (prodptr + 1) % LOGLEN;
bf47740a 86 while (*s)
5a626f09 87 serial_tx(*(s++));
113df320
JW
88 serial_tx('\r');
89 serial_tx('\n');
9e2a82e4
JP
90 if (flush_imm)
91 outlog();
92}
93void (*output)(const char *s) = dolog;
94
95void dologf(const char *fmt, ...)
96{
113df320
JW
97 char *s;
98 va_list va;
99
100 va_start(va, fmt);
101 vsnprintf(logents[prodptr], 40, fmt, va);
102 s = logents[prodptr];
103 while (*s)
104 serial_tx(*(s++));
105 serial_tx('\r');
106 serial_tx('\n');
107 va_end(va);
108 prodptr = (prodptr + 1) % LOGLEN;
109 if (flush_imm)
110 outlog();
9e2a82e4
JP
111}
112void (*outputf)(const char *s, ...) = dologf;
113
114void dump_log (char * target) {
115 memcpy(target, logents, sizeof(logents));
116}
This page took 0.032777 seconds and 4 git commands to generate.