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