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