2 * Copyright 2005-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
6 * Distributed under the terms of the NewOS License.
10 #include <KernelExport.h>
19 #define SCREEN_START 0xb8000
20 #define SCREEN_END 0xc0000
24 #define TEXT_INDEX 0x3d4
25 #define TEXT_DATA 0x3d5
27 #define TEXT_CURSOR_LO 0x0f
28 #define TEXT_CURSOR_HI 0x0e
30 static uint16
*sOrigin
;
31 static isa_module_info
*sISA
;
39 if (get_module(B_ISA_MODULE_NAME
, (module_info
**)&sISA
) < 0) {
40 dprintf("text module_init: no isa bus found..\n");
44 map_physical_memory("video_mem", SCREEN_START
, SCREEN_END
- SCREEN_START
,
45 B_ANY_KERNEL_ADDRESS
, B_KERNEL_READ_AREA
| B_KERNEL_WRITE_AREA
, (void *)&sOrigin
);
46 dprintf("console/text: mapped vid mem to virtual address %p\n", sOrigin
);
48 /* pre-touch all of the memory so that we dont fault while deep inside the kernel and displaying something */
49 for (i
= (addr_t
)sOrigin
; i
< (addr_t
)sOrigin
+ (SCREEN_END
- SCREEN_START
);
51 uint16 val
= *(volatile uint16
*)i
;
52 *(volatile uint16
*)i
= val
;
61 put_module(B_ISA_MODULE_NAME
);
63 // ToDo: unmap video memory (someday)
69 get_size(int32
*width
, int32
*height
)
78 move_cursor(int32 x
, int32 y
)
83 pos
= LINES
* COLUMNS
+ 1;
85 pos
= y
* COLUMNS
+ x
;
87 sISA
->write_io_8(TEXT_INDEX
, TEXT_CURSOR_LO
);
88 sISA
->write_io_8(TEXT_DATA
, (char)pos
);
89 sISA
->write_io_8(TEXT_INDEX
, TEXT_CURSOR_HI
);
90 sISA
->write_io_8(TEXT_DATA
, (char)(pos
>> 8));
95 put_glyph(int32 x
, int32 y
, uint8 glyph
, uint8 attr
)
97 uint16 pair
= ((uint16
)attr
<< 8) | (uint16
)glyph
;
98 uint16
*p
= sOrigin
+ (y
* COLUMNS
) + x
;
104 fill_glyph(int32 x
, int32 y
, int32 width
, int32 height
, uint8 glyph
, uint8 attr
)
106 uint16 pair
= ((uint16
)attr
<< 8) | (uint16
)glyph
;
107 int32 y_limit
= y
+ height
;
109 while (y
< y_limit
) {
110 uint16
*p
= sOrigin
+ (y
* COLUMNS
) + x
;
111 uint16
*p_limit
= p
+ width
;
112 while (p
< p_limit
) *p
++ = pair
;
119 blit(int32 srcx
, int32 srcy
, int32 width
, int32 height
, int32 destx
, int32 desty
)
121 if ((srcx
== 0) && (width
== COLUMNS
)) {
123 memmove(sOrigin
+ (desty
* COLUMNS
), sOrigin
+ (srcy
* COLUMNS
), height
* COLUMNS
* 2);
133 uint16
*base
= (uint16
*)sOrigin
;
136 for (i
= 0; i
< COLUMNS
* LINES
; i
++)
137 base
[i
] = (attr
<< 8) | 0x20;
142 text_std_ops(int32 op
, ...)
147 case B_MODULE_UNINIT
:
148 return text_uninit();
156 static console_module_info sVGATextConsole
= {
158 "console/vga_text/v1",
170 module_info
*modules
[] = {
171 (module_info
*)&sVGATextConsole
,