]>
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 | smram_state_t old_state = smram_save_state(); | |
46 | ||
47 | smram_aseg_set_state(SMRAM_ASEG_SMMCODE); | |
48 | ||
49 | while (*src) | |
50 | { | |
51 | *(destp++) = *(src++); | |
52 | *(destp++) = COLOR; | |
53 | } | |
54 | ||
55 | smram_restore_state(old_state); | |
56 | } | |
57 | ||
58 | void 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 | ||
67 | for (y = 0; y < LOG_ONSCREEN; y++) | |
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); | |
75 | ||
76 | for (y = -LOG_ONSCREEN; y < 0; y++) | |
77 | strblit(logents[(y + prodptr) % LOGLEN], y + LOG_ONSCREEN, 40); | |
78 | } | |
79 | ||
80 | void dolog(const char *s) | |
81 | { | |
82 | strcpy(logents[prodptr], s); | |
83 | prodptr = (prodptr + 1) % LOGLEN; | |
84 | if (flush_imm) | |
85 | outlog(); | |
86 | } | |
87 | void (*output)(const char *s) = dolog; | |
88 | ||
89 | void dologf(const char *fmt, ...) | |
90 | { | |
91 | va_list va; | |
92 | ||
93 | va_start(va, fmt); | |
94 | vsnprintf(logents[prodptr], 40, fmt, va); | |
95 | va_end(va); | |
96 | prodptr = (prodptr + 1) % LOGLEN; | |
97 | if (flush_imm) | |
98 | outlog(); | |
99 | } | |
100 | void (*outputf)(const char *s, ...) = dologf; | |
101 | ||
102 | void dump_log (char * target) { | |
103 | memcpy(target, logents, sizeof(logents)); | |
104 | } |