]> Joshua Wise's Git repositories - netwatch.git/blame - aseg-paging/vga-overlay.c
Add a FB access layer.
[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
43void 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
64void 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
86void dolog(const char *s)
87{
88 strcpy(logents[prodptr], s);
89 prodptr = (prodptr + 1) % LOGLEN;
bf47740a 90 while (*s)
5a626f09 91 serial_tx(*(s++));
113df320
JW
92 serial_tx('\r');
93 serial_tx('\n');
9e2a82e4
JP
94 if (flush_imm)
95 outlog();
96}
97void (*output)(const char *s) = dolog;
98
99void dologf(const char *fmt, ...)
100{
113df320
JW
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();
9e2a82e4
JP
115}
116void (*outputf)(const char *s, ...) = dologf;
117
118void dump_log (char * target) {
119 memcpy(target, logents, sizeof(logents));
120}
121
This page took 0.03893 seconds and 4 git commands to generate.