]>
Commit | Line | Data |
---|---|---|
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 | ||
11 | static char logents[LOGLEN][41] = {{0}}; | |
12 | static int prodptr = 0; | |
13 | static int flush_imm = 0; | |
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 | ||
22 | void vga_flush_imm(int imm) | |
23 | { | |
24 | flush_imm = imm; | |
25 | } | |
26 | ||
27 | static unsigned char vga_read(unsigned char idx) | |
28 | { | |
29 | outb(CRTC_IDX_REG, idx); | |
30 | return inb(CRTC_DATA_REG); | |
31 | } | |
32 | ||
33 | static char * vga_base() | |
34 | { | |
35 | return (char *) ( | |
36 | TEXT_CONSOLE_BASE | |
37 | + (((unsigned int) vga_read(CRTC_START_ADDR_MSB_IDX)) << 9) | |
38 | + (((unsigned int) vga_read(CRTC_START_ADDR_LSB_IDX)) << 1) | |
39 | ); | |
40 | } | |
41 | ||
42 | void strblit(char *src, int row, int col) | |
43 | { | |
44 | char *destp = vga_base() + row * 80 * 2 + col * 2; | |
45 | outb(0x80, 0x3C); | |
46 | smram_state_t old_state = smram_save_state(); | |
47 | outb(0x80, 0x3D); | |
48 | ||
49 | smram_aseg_set_state(SMRAM_ASEG_SMMCODE); | |
50 | outb(0x80, 0x3E); | |
51 | ||
52 | while (*src) | |
53 | { | |
54 | *(destp++) = *(src++); | |
55 | *(destp++) = COLOR; | |
56 | } | |
57 | ||
58 | outb(0x80, 0x3F); | |
59 | smram_restore_state(old_state); | |
60 | outb(0x80, 0x40); | |
61 | } | |
62 | ||
63 | void outlog() | |
64 | { | |
65 | int y, x; | |
66 | char *basep = vga_base(); | |
67 | ||
68 | smram_state_t old_state = smram_save_state(); | |
69 | ||
70 | smram_aseg_set_state(SMRAM_ASEG_SMMCODE); | |
71 | ||
72 | for (y = 0; y < LOG_ONSCREEN; y++) | |
73 | for (x = 40; x < 80; x++) | |
74 | { | |
75 | basep[y*80*2+x*2] = ' '; | |
76 | basep[y*80*2+x*2+1] = 0x1F; | |
77 | } | |
78 | ||
79 | smram_restore_state(old_state); | |
80 | ||
81 | for (y = -LOG_ONSCREEN; y < 0; y++) | |
82 | strblit(logents[(y + prodptr) % LOGLEN], y + LOG_ONSCREEN, 40); | |
83 | } | |
84 | ||
85 | void dolog(const char *s) | |
86 | { | |
87 | strcpy(logents[prodptr], s); | |
88 | prodptr = (prodptr + 1) % LOGLEN; | |
89 | if (flush_imm) | |
90 | outlog(); | |
91 | } | |
92 | void (*output)(const char *s) = dolog; | |
93 | ||
94 | void dologf(const char *fmt, ...) | |
95 | { | |
96 | } | |
97 | void (*outputf)(const char *s, ...) = dologf; | |
98 | ||
99 | void dump_log (char * target) { | |
100 | memcpy(target, logents, sizeof(logents)); | |
101 | } | |
102 |