]>
Commit | Line | Data |
---|---|---|
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 | |
8 | static 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 | ||
17 | static unsigned char vga_read(unsigned char idx) | |
18 | { | |
19 | outb(CRTC_IDX_REG, idx); | |
20 | return inb(CRTC_DATA_REG); | |
21 | } | |
22 | ||
23 | static 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 | ||
32 | void 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); | |
d5cffad7 | 38 | |
91a6abf7 JP |
39 | while (*src) |
40 | { | |
41 | *(destp++) = *(src++); | |
42 | *(destp++) = COLOR; | |
43 | } | |
44 | ||
45 | smram_restore_state(old_state); | |
46 | } | |
47 | ||
48 | void 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 | 70 | void dolog(const char *s) |
91a6abf7 JP |
71 | { |
72 | memmove(logents[0], logents[1], sizeof(logents[0])*3); | |
73 | strcpy(logents[3], s); | |
74 | } | |
efea5b4e | 75 | void (*output)(const char *s) = dolog; |
d24901e6 | 76 | |
efea5b4e | 77 | void 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 | 86 | void (*outputf)(const char *s, ...) = dologf; |
d5cffad7 JP |
87 | |
88 | void dump_log (char * target) { | |
89 | memcpy(target, logents, sizeof(logents)); | |
90 | } |