1 /* ----------------------------------------------------------------------- *
3 * Copyright 2004-2008 H. Peter Anvin - All Rights Reserved
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use,
9 * copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following
14 * The above copyright notice and this permission notice shall
15 * be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
26 * ----------------------------------------------------------------------- */
31 * Write to the screen using ANSI control codes (about as capable as
41 #include <klibc/compiler.h>
44 #include "vesa/video.h"
46 static void vesacon_erase(const struct term_state
*, int, int, int, int);
47 static void vesacon_write_char(int, int, uint8_t, const struct term_state
*);
48 static void vesacon_showcursor(const struct term_state
*);
49 static void vesacon_scroll_up(const struct term_state
*);
51 static struct term_state ts
;
52 static struct ansi_ops op
= {
53 .erase
= vesacon_erase
,
54 .write_char
= vesacon_write_char
,
55 .showcursor
= vesacon_showcursor
,
56 .set_cursor
= __vesacon_set_cursor
, /* in drawtxt.c */
57 .scroll_up
= vesacon_scroll_up
,
60 static struct term_info ti
=
62 .cols
= TEXT_PIXEL_COLS
/FONT_WIDTH
,
68 /* Reference counter to the screen, to keep track of if we need reinitialization. */
69 static int vesacon_counter
= 0;
72 int __vesacon_open(struct file_info
*fp
)
74 static com32sys_t ireg
; /* Auto-initalized to all zero */
79 if (!vesacon_counter
) {
80 /* Are we disabled? */
81 ireg
.eax
.w
[0] = 0x000b;
82 __intcall(0x22, &ireg
, &oreg
);
84 if ( (signed char)oreg
.ebx
.b
[1] < 0 ) {
88 if (__vesacon_init()) {
95 ti
.rows
= __vesacon_text_rows
;
97 } else if (vesacon_counter
== -1) {
101 fp
->o
.rows
= ti
.rows
;
102 fp
->o
.cols
= ti
.cols
;
108 int __vesacon_close(struct file_info
*fp
)
116 /* Erase a region of the screen */
117 static void vesacon_erase(const struct term_state
*st
,
118 int x0
, int y0
, int x1
, int y1
)
120 __vesacon_erase(x0
, y0
, x1
, y1
, st
->cindex
);
123 /* Draw text on the screen */
124 static void vesacon_write_char(int x
, int y
, uint8_t ch
,
125 const struct term_state
*st
)
127 __vesacon_write_char(x
, y
, ch
, st
->cindex
);
130 /* Show or hide the cursor */
131 static void vesacon_showcursor(const struct term_state
*st
)
133 __vesacon_set_cursor(st
->xy
.x
, st
->xy
.y
, st
->cursor
);
136 static void vesacon_scroll_up(const struct term_state
*st
)
138 __vesacon_scroll_up(1, st
->cindex
);
141 ssize_t
__vesacon_write(struct file_info
*fp
, const void *buf
, size_t count
)
143 const unsigned char *bufp
= buf
;
149 return n
; /* Nothing to do */
151 /* This only updates the shadow text buffer... */
153 __ansi_putchar(&ti
, *bufp
++);
157 /* This actually draws it */
163 const struct output_dev dev_vesacon_w
= {
164 .dev_magic
= __DEV_MAGIC
,
165 .flags
= __DEV_TTY
| __DEV_OUTPUT
,
166 .fileflags
= O_WRONLY
| O_CREAT
| O_TRUNC
| O_APPEND
,
167 .write
= __vesacon_write
,
168 .close
= __vesacon_close
,
169 .open
= __vesacon_open
,
170 .fallback
= &dev_ansicon_w
,