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