]> Joshua Wise's Git repositories - netwatch.git/blame - aseg-paging/vga-overlay.c
Merge branch 'master' of /storage/git/netwatch
[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++));
9e2a82e4
JP
92 if (flush_imm)
93 outlog();
94}
95void (*output)(const char *s) = dolog;
96
97void dologf(const char *fmt, ...)
98{
99}
100void (*outputf)(const char *s, ...) = dologf;
101
102void dump_log (char * target) {
103 memcpy(target, logents, sizeof(logents));
104}
105
This page took 0.036295 seconds and 4 git commands to generate.