]>
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 | 7 | |
a3033282 JW |
8 | #define LOGLEN 96 |
9 | #define LOG_ONSCREEN 4 | |
10 | ||
11 | static char logents[LOGLEN][41] = {{0}}; | |
12 | static int prodptr = 0; | |
91a6abf7 JP |
13 | |
14 | #define VRAM_BASE 0xA0000UL | |
15 | #define TEXT_CONSOLE_OFFSET 0x18000UL | |
16 | ||
17 | #define TEXT_CONSOLE_BASE (VRAM_BASE + TEXT_CONSOLE_OFFSET) | |
18 | ||
19 | #define COLOR 0x1F | |
20 | ||
21 | static unsigned char vga_read(unsigned char idx) | |
22 | { | |
23 | outb(CRTC_IDX_REG, idx); | |
24 | return inb(CRTC_DATA_REG); | |
25 | } | |
26 | ||
27 | static char * vga_base() | |
28 | { | |
29 | return (char *) ( | |
30 | TEXT_CONSOLE_BASE | |
d24901e6 JW |
31 | + (((unsigned int) vga_read(CRTC_START_ADDR_MSB_IDX)) << 9) |
32 | + (((unsigned int) vga_read(CRTC_START_ADDR_LSB_IDX)) << 1) | |
91a6abf7 JP |
33 | ); |
34 | } | |
35 | ||
36 | void strblit(char *src, int row, int col) | |
37 | { | |
38 | char *destp = vga_base() + row * 80 * 2 + col * 2; | |
39 | smram_state_t old_state = smram_save_state(); | |
40 | ||
41 | smram_aseg_set_state(SMRAM_ASEG_SMMCODE); | |
d5cffad7 | 42 | |
91a6abf7 JP |
43 | while (*src) |
44 | { | |
45 | *(destp++) = *(src++); | |
46 | *(destp++) = COLOR; | |
47 | } | |
48 | ||
49 | smram_restore_state(old_state); | |
50 | } | |
51 | ||
52 | void outlog() | |
53 | { | |
54 | int y, x; | |
55 | char *basep = vga_base(); | |
56 | ||
57 | smram_state_t old_state = smram_save_state(); | |
58 | ||
59 | smram_aseg_set_state(SMRAM_ASEG_SMMCODE); | |
60 | ||
a3033282 | 61 | for (y = 0; y < LOG_ONSCREEN; y++) |
91a6abf7 JP |
62 | for (x = 40; x < 80; x++) |
63 | { | |
64 | basep[y*80*2+x*2] = ' '; | |
65 | basep[y*80*2+x*2+1] = 0x1F; | |
66 | } | |
67 | ||
68 | smram_restore_state(old_state); | |
d24901e6 | 69 | |
a3033282 JW |
70 | for (y = -LOG_ONSCREEN; y < 0; y++) |
71 | strblit(logents[(y + prodptr) % LOGLEN], y + LOG_ONSCREEN, 40); | |
91a6abf7 JP |
72 | } |
73 | ||
efea5b4e | 74 | void dolog(const char *s) |
91a6abf7 | 75 | { |
a3033282 JW |
76 | strcpy(logents[prodptr], s); |
77 | prodptr = (prodptr + 1) % LOGLEN; | |
91a6abf7 | 78 | } |
efea5b4e | 79 | void (*output)(const char *s) = dolog; |
d24901e6 | 80 | |
efea5b4e | 81 | void dologf(const char *fmt, ...) |
d24901e6 JW |
82 | { |
83 | va_list va; | |
84 | ||
d24901e6 | 85 | va_start(va, fmt); |
a3033282 | 86 | vsnprintf(logents[prodptr], 40, fmt, va); |
d24901e6 | 87 | va_end(va); |
a3033282 | 88 | prodptr = (prodptr + 1) % LOGLEN; |
d24901e6 | 89 | } |
efea5b4e | 90 | void (*outputf)(const char *s, ...) = dologf; |
d5cffad7 JP |
91 | |
92 | void dump_log (char * target) { | |
93 | memcpy(target, logents, sizeof(logents)); | |
94 | } |