]> Joshua Wise's Git repositories - netwatch.git/blame - aseg/vga-overlay.c
Add locks from time to time.
[netwatch.git] / aseg / vga-overlay.c
CommitLineData
91a6abf7
JP
1#include <io.h>
2#include <smram.h>
3#include <video_defines.h>
4#include <minilib.h>
d24901e6 5#include <stdarg.h>
efea5b4e 6#include <output.h>
91a6abf7 7
a3033282
JW
8#define LOGLEN 96
9#define LOG_ONSCREEN 4
10
11static char logents[LOGLEN][41] = {{0}};
12static int prodptr = 0;
6bd08bbc 13static int flush_imm = 0;
91a6abf7
JP
14
15#define VRAM_BASE 0xA0000UL
16#define TEXT_CONSOLE_OFFSET 0x18000UL
17
18#define TEXT_CONSOLE_BASE (VRAM_BASE + TEXT_CONSOLE_OFFSET)
19
20#define COLOR 0x1F
21
6bd08bbc
JW
22void vga_flush_imm(int imm)
23{
24 flush_imm = imm;
25}
26
91a6abf7
JP
27static unsigned char vga_read(unsigned char idx)
28{
29 outb(CRTC_IDX_REG, idx);
30 return inb(CRTC_DATA_REG);
31}
32
33static char * vga_base()
34{
35 return (char *) (
36 TEXT_CONSOLE_BASE
d24901e6
JW
37 + (((unsigned int) vga_read(CRTC_START_ADDR_MSB_IDX)) << 9)
38 + (((unsigned int) vga_read(CRTC_START_ADDR_LSB_IDX)) << 1)
91a6abf7
JP
39 );
40}
41
42void strblit(char *src, int row, int col)
43{
44 char *destp = vga_base() + row * 80 * 2 + col * 2;
45 smram_state_t old_state = smram_save_state();
46
47 smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
d5cffad7 48
91a6abf7
JP
49 while (*src)
50 {
51 *(destp++) = *(src++);
52 *(destp++) = COLOR;
53 }
54
55 smram_restore_state(old_state);
56}
57
58void outlog()
59{
60 int y, x;
61 char *basep = vga_base();
62
63 smram_state_t old_state = smram_save_state();
64
65 smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
66
a3033282 67 for (y = 0; y < LOG_ONSCREEN; y++)
91a6abf7
JP
68 for (x = 40; x < 80; x++)
69 {
70 basep[y*80*2+x*2] = ' ';
71 basep[y*80*2+x*2+1] = 0x1F;
72 }
73
74 smram_restore_state(old_state);
d24901e6 75
a3033282
JW
76 for (y = -LOG_ONSCREEN; y < 0; y++)
77 strblit(logents[(y + prodptr) % LOGLEN], y + LOG_ONSCREEN, 40);
91a6abf7
JP
78}
79
efea5b4e 80void dolog(const char *s)
91a6abf7 81{
a3033282
JW
82 strcpy(logents[prodptr], s);
83 prodptr = (prodptr + 1) % LOGLEN;
6bd08bbc
JW
84 if (flush_imm)
85 outlog();
91a6abf7 86}
efea5b4e 87void (*output)(const char *s) = dolog;
d24901e6 88
efea5b4e 89void dologf(const char *fmt, ...)
d24901e6
JW
90{
91 va_list va;
92
d24901e6 93 va_start(va, fmt);
a3033282 94 vsnprintf(logents[prodptr], 40, fmt, va);
d24901e6 95 va_end(va);
a3033282 96 prodptr = (prodptr + 1) % LOGLEN;
6bd08bbc
JW
97 if (flush_imm)
98 outlog();
d24901e6 99}
efea5b4e 100void (*outputf)(const char *s, ...) = dologf;
d5cffad7
JP
101
102void dump_log (char * target) {
103 memcpy(target, logents, sizeof(logents));
104}
This page took 0.037382 seconds and 4 git commands to generate.