]> Joshua Wise's Git repositories - netwatch.git/blame_incremental - aseg/vga-overlay.c
Fix 'i r retard' bug in timer
[netwatch.git] / aseg / vga-overlay.c
... / ...
CommitLineData
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>
7
8#define LOGLEN 96
9#define LOG_ONSCREEN 4
10
11static char logents[LOGLEN][41] = {{0}};
12static int prodptr = 0;
13
14#define VRAM_BASE 0xA0000UL
15#define TEXT_CONSOLE_OFFSET 0x18000UL
16
17#define TEXT_CONSOLE_BASE (VRAM_BASE + TEXT_CONSOLE_OFFSET)
18
19#define COLOR 0x1F
20
21static unsigned char vga_read(unsigned char idx)
22{
23 outb(CRTC_IDX_REG, idx);
24 return inb(CRTC_DATA_REG);
25}
26
27static char * vga_base()
28{
29 return (char *) (
30 TEXT_CONSOLE_BASE
31 + (((unsigned int) vga_read(CRTC_START_ADDR_MSB_IDX)) << 9)
32 + (((unsigned int) vga_read(CRTC_START_ADDR_LSB_IDX)) << 1)
33 );
34}
35
36void strblit(char *src, int row, int col)
37{
38 char *destp = vga_base() + row * 80 * 2 + col * 2;
39 smram_state_t old_state = smram_save_state();
40
41 smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
42
43 while (*src)
44 {
45 *(destp++) = *(src++);
46 *(destp++) = COLOR;
47 }
48
49 smram_restore_state(old_state);
50}
51
52void outlog()
53{
54 int y, x;
55 char *basep = vga_base();
56
57 smram_state_t old_state = smram_save_state();
58
59 smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
60
61 for (y = 0; y < LOG_ONSCREEN; y++)
62 for (x = 40; x < 80; x++)
63 {
64 basep[y*80*2+x*2] = ' ';
65 basep[y*80*2+x*2+1] = 0x1F;
66 }
67
68 smram_restore_state(old_state);
69
70 for (y = -LOG_ONSCREEN; y < 0; y++)
71 strblit(logents[(y + prodptr) % LOGLEN], y + LOG_ONSCREEN, 40);
72}
73
74void dolog(const char *s)
75{
76 strcpy(logents[prodptr], s);
77 prodptr = (prodptr + 1) % LOGLEN;
78}
79void (*output)(const char *s) = dolog;
80
81void dologf(const char *fmt, ...)
82{
83 va_list va;
84
85 va_start(va, fmt);
86 vsnprintf(logents[prodptr], 40, fmt, va);
87 va_end(va);
88 prodptr = (prodptr + 1) % LOGLEN;
89}
90void (*outputf)(const char *s, ...) = dologf;
91
92void dump_log (char * target) {
93 memcpy(target, logents, sizeof(logents));
94}
This page took 0.026601 seconds and 4 git commands to generate.