* [Qemu-devel] Re: qemu curses driver
2005-12-10 8:17 [Qemu-devel] " andrzej zaborowski
@ 2005-12-12 6:58 ` andrzej zaborowski
2005-12-12 10:46 ` Johannes Schindelin
2008-01-10 16:50 ` andrzej zaborowski
1 sibling, 1 reply; 7+ messages in thread
From: andrzej zaborowski @ 2005-12-12 6:58 UTC (permalink / raw)
To: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 969 bytes --]
Hi there,
This is a slightly corrected version of the previous patch.
The changes are:
- fixed the terminal resize event handling, now it should work
regardless of the curses library implementation,
- some keyboard input details,
- and changed the Makefile to compile the curses driver for all
targets that use the VGA emulator (from hw/vga.c) - that means all
targets except Sparc and ARM - I think it is also possible to make
this work for Sparc and ARM but I don't know anything about these
architectures and wouldn't have any way to perform any testing and I
also don't know how useful this would be.
Any comments are welcome, especially if someone encounters any further
bugs or malfunctioning of the interface. What do you think about
including the curses interface in QEMU?
cheers,
Andrzej Zaborowski
--
balrog 2oo5
Dear Outlook users: Please remove me from your address books
http://www.newsforge.com/article.pl?sid=03/08/21/143258
[-- Attachment #2: qemu-curses-ui.patch --]
[-- Type: application/octet-stream, Size: 32533 bytes --]
diff -Naur qemu/Makefile.target qemu-curses/Makefile.target
--- qemu/Makefile.target 2005-12-06 21:42:17.000000000 +0000
+++ qemu-curses/Makefile.target 2005-12-12 02:47:58.000000000 +0000
@@ -341,6 +341,9 @@
ifdef CONFIG_SDL
VL_OBJS+=sdl.o
endif
+ifdef CONFIG_CURSES
+VL_OBJS+=curses.o
+endif
ifdef CONFIG_COCOA
VL_OBJS+=cocoa.o
COCOA_LIBS=-F/System/Library/Frameworks -framework Cocoa -framework IOKit
@@ -383,7 +386,7 @@
endif
$(QEMU_SYSTEM): $(VL_OBJS) libqemu.a
- $(CC) $(VL_LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(COCOA_LIBS) $(VL_LIBS)
+ $(CC) $(VL_LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(COCOA_LIBS) $(CURSES_LIBS) $(VL_LIBS)
cocoa.o: cocoa.m
$(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
@@ -394,6 +397,9 @@
sdlaudio.o: sdlaudio.c
$(CC) $(CFLAGS) $(DEFINES) $(SDL_CFLAGS) -c -o $@ $<
+curses.o: curses.c
+ $(CC) $(CFLAGS) $(DEFINES) $(CURSES_CFLAGS) -c -o $@ $<
+
depend: $(SRCS)
$(CC) -MM $(CFLAGS) $(DEFINES) $^ 1>.depend
diff -Naur qemu/configure qemu-curses/configure
--- qemu/configure 2005-12-06 21:42:55.000000000 +0000
+++ qemu-curses/configure 2005-12-12 05:11:14.000000000 +0000
@@ -181,6 +181,8 @@
;;
--enable-dsound) dsound="yes"
;;
+ --disable-curses) curses="no"
+ ;;
--enable-fmod) fmod="yes"
;;
--fmod-lib=*) fmod_lib=${opt#--fmod-lib=}
@@ -348,6 +350,24 @@
fi # cross compilation
fi # -z $sdl
+##########################################
+# curses probe
+
+if test -z "$curses" ; then
+
+curses=no
+
+cat > $TMPC << EOF
+#include <curses.h>
+int main( void ) { return curses_version (); }
+EOF
+
+if $cc -o $TMPE -lcurses $TMPC 2> /dev/null ; then
+curses=yes
+fi
+
+fi # -z $curses
+
if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
cat << EOF
@@ -469,6 +489,7 @@
if test "$sdl" != "no" ; then
echo "SDL static link $sdl_static"
fi
+echo "curses support $curses"
echo "mingw32 support $mingw32"
echo "Adlib support $adlib"
echo "CoreAudio support $coreaudio"
@@ -680,7 +701,8 @@
-a "$sdl" = "no" -a "$cocoa" = "no" ; then
echo "ERROR: QEMU requires SDL or Cocoa for graphical output"
echo "To build QEMU with graphical output configure with --disable-gfx-check"
- echo "Note that this will disable all output from the virtual graphics card."
+ echo "Note that this will disable all output from the virtual graphics card"
+ echo "except for the curses interface."
exit 1;
fi
@@ -798,6 +820,15 @@
echo "CONFIG_COCOA=yes" >> $config_mak
fi
+if test "$curses" = "yes" ; then
+ if test "$target_cpu" != "sparc" -a "$target_cpu" != "arm" ; then
+ echo "#define CONFIG_CURSES 1" >> $config_h
+ echo "CONFIG_CURSES=yes" >> $config_mak
+ echo "CURSES_LIBS=-lcurses" >> $config_mak
+ echo "CURSES_CFLAGS=" >> $config_mak
+ fi
+fi
+
done # for target in $targets
# build tree in object directory if source path is different from current one
diff -Naur qemu/console.c qemu-curses/console.c
--- qemu/console.c 2004-10-09 17:32:58.000000000 +0000
+++ qemu-curses/console.c 2005-12-08 18:59:24.000000000 +0000
@@ -21,52 +21,11 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#include "vl.h"
+#include "console.h"
#define DEFAULT_BACKSCROLL 512
#define MAX_CONSOLES 12
-#define RGBA(r, g, b, a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
-#define RGB(r, g, b) RGBA(r, g, b, 0xff)
-
-typedef struct TextCell {
- uint8_t ch;
- uint8_t bgcol:4;
- uint8_t fgcol:4;
-} TextCell;
-
-#define MAX_ESC_PARAMS 3
-
-enum TTYState {
- TTY_STATE_NORM,
- TTY_STATE_ESC,
- TTY_STATE_CSI,
-};
-
-struct TextConsole {
- int text_console; /* true if text console */
- DisplayState *ds;
- int g_width, g_height;
- int width;
- int height;
- int total_height;
- int backscroll_height;
- int fgcol;
- int bgcol;
- int x, y;
- int y_displayed;
- int y_base;
- TextCell *cells;
-
- enum TTYState state;
- int esc_params[MAX_ESC_PARAMS];
- int nb_esc_params;
-
- /* kbd read handler */
- IOReadHandler *fd_read;
- void *fd_opaque;
-};
-
static TextConsole *active_console;
static TextConsole *consoles[MAX_CONSOLES];
static int nb_consoles = 0;
@@ -729,3 +688,8 @@
return chr;
}
+
+TextConsole *get_active_console()
+{
+ return active_console;
+}
diff -Naur qemu/console.h qemu-curses/console.h
--- qemu/console.h 1970-01-01 00:00:00.000000000 +0000
+++ qemu-curses/console.h 2005-12-08 18:59:24.000000000 +0000
@@ -0,0 +1,70 @@
+/*
+ * QEMU graphical console definitions
+ *
+ * Copyright (c) 2004 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef CONSOLE_H
+#define CONSOLE_H
+
+#include "vl.h"
+
+#define RGBA(r, g, b, a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
+#define RGB(r, g, b) RGBA(r, g, b, 0xff)
+
+typedef struct TextCell {
+ uint8_t ch;
+ uint8_t bgcol:4;
+ uint8_t fgcol:4;
+} TextCell;
+
+#define MAX_ESC_PARAMS 3
+
+enum TTYState {
+ TTY_STATE_NORM,
+ TTY_STATE_ESC,
+ TTY_STATE_CSI,
+};
+
+struct TextConsole {
+ int text_console; /* true if text console */
+ DisplayState *ds;
+ int g_width, g_height;
+ int width;
+ int height;
+ int total_height;
+ int backscroll_height;
+ int fgcol;
+ int bgcol;
+ int x, y;
+ int y_displayed;
+ int y_base;
+ TextCell *cells;
+
+ enum TTYState state;
+ int esc_params[MAX_ESC_PARAMS];
+ int nb_esc_params;
+
+ /* kbd read handler */
+ IOReadHandler *fd_read;
+ void *fd_opaque;
+};
+
+#endif /* CONSOLE_H */
diff -Naur qemu/curses.c qemu-curses/curses.c
--- qemu/curses.c 1970-01-01 00:00:00.000000000 +0000
+++ qemu-curses/curses.c 2005-12-12 04:45:50.000000000 +0000
@@ -0,0 +1,319 @@
+/*
+ * QEMU curses/ncurses display driver
+ *
+ * Copyright (c) 2005 Andrzej Zaborowski <balrog@zabor.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "vl.h"
+#include "console.h"
+
+#include <curses.h>
+
+#ifndef _WIN32
+#include <signal.h>
+#include <sys/ioctl.h>
+#include <termios.h>
+#endif
+
+#include "curses_keys.h"
+
+static char screen[160 * 100];
+static WINDOW *screenpad = NULL;
+static int width, height, invalidate;
+static int px, py, sminx, sminy, smaxx, smaxy;
+
+static void curses_update(DisplayState *ds, int x, int y, int w, int h)
+{
+ int i, j, mw, mh;
+ chtype *line;
+ TextConsole *s;
+
+ if (is_active_console(vga_console)) {
+ line = ((chtype *) screen) + y * width;
+ for (h += y; y < h; y ++, line += width)
+ mvwaddchnstr(screenpad, y, 0, line, width);
+
+ pnoutrefresh(screenpad, py, px, sminy, sminx, smaxy - 1, smaxx - 1);
+ } else {
+ s = get_active_console();
+ if (!s->text_console)
+ return;
+
+ mw = s->width;
+ if (mw > COLS)
+ mw = COLS;
+ mh = s->height;
+ if (mh > LINES)
+ mh = LINES;
+
+ for (i = 0; i < mh; i ++)
+ for (j = 0; j < mw; j ++)
+ mvaddch(i, j, s->cells[
+ (i + s->y_base + s->height - mh) * s->width + j].ch);
+ move(s->y + mh - s->height, s->x);
+ curs_set(2);
+ }
+ refresh();
+}
+
+static void curses_calc_pad()
+{
+ if (width > COLS) {
+ px = (width - COLS) / 2;
+ sminx = 0;
+ smaxx = COLS;
+ } else {
+ px = 0;
+ sminx = (COLS - width) / 2;
+ smaxx = sminx + width;
+ }
+
+ if (height > LINES) {
+ py = (height - LINES) / 2;
+ sminy = 0;
+ smaxy = LINES;
+ } else {
+ py = 0;
+ sminy = (LINES - height) / 2;
+ smaxy = sminy + height;
+ }
+}
+
+static void curses_resize(DisplayState *ds, int w, int h)
+{
+ if (w == width && h == height)
+ return;
+
+ if (screenpad)
+ delwin(screenpad);
+
+ clear();
+ refresh();
+
+ screenpad = newpad(h, w);
+ width = w;
+ height = h;
+
+ curses_calc_pad();
+}
+
+#ifndef _WIN32
+#ifdef SIGWINCH
+static void curses_winch_handler(int signum)
+{
+ struct winsize {
+ unsigned short ws_row;
+ unsigned short ws_col;
+ unsigned short ws_xpixel; /* unused */
+ unsigned short ws_ypixel; /* unused */
+ } ws;
+
+ /* terminal size changed */
+ if (ioctl(1, TIOCGWINSZ, &ws) == -1)
+ return;
+
+ resize_term(ws.ws_row, ws.ws_col);
+ curses_calc_pad();
+ invalidate = 1;
+
+ /* some systems require this */
+ signal(SIGWINCH, curses_winch_handler);
+}
+#endif
+#endif
+
+static void curses_cursor_position(DisplayState *ds, int x, int y)
+{
+ if (x >= 0) {
+ x = sminx + x - px;
+ y = sminy + y - py;
+
+ if (x >= 0 && y >= 0 && x < COLS && y < LINES) {
+ move(y, x);
+ curs_set(1);
+ return;
+ }
+ }
+
+ curs_set(0);
+}
+
+static void curses_refresh(DisplayState *ds)
+{
+ int chr, nextchr, keysym, keycode;
+
+ if (invalidate) {
+ clear();
+ refresh();
+ if (is_active_console(vga_console))
+ vga_invalidate_display();
+ else
+ curses_update(ds, 0, 0, width, height);
+
+ invalidate = 0;
+ }
+
+ if (is_active_console(vga_console))
+ vga_update_text(screen, curses_cursor_position);
+
+ nextchr = ERR;
+ while (1) {
+ /* while there are any pending key strokes to process */
+ if (nextchr == ERR)
+ chr = getch();
+ else {
+ chr = nextchr;
+ nextchr = ERR;
+ }
+
+ if (chr == ERR)
+ break;
+
+ /* this shouldn't occur when we use a custom SIGWINCH handler */
+ if (chr == KEY_RESIZE) {
+ clear();
+ refresh();
+ curses_calc_pad();
+ curses_update(ds, 0, 0, width, height);
+ continue;
+ }
+
+ keycode = curses2keycode[chr];
+ if (keycode == -1)
+ continue;
+
+ /* alt key */
+ if (keycode == 1) {
+ nextchr = getch();
+
+ if (nextchr != ERR) {
+ keycode = curses2keycode[nextchr];
+ nextchr = ERR;
+ if (keycode == -1)
+ continue;
+
+ keycode |= ALT;
+
+ /* process keys reserved for qemu */
+ if (keycode >= QEMU_KEY_CONSOLE0 &&
+ keycode < QEMU_KEY_CONSOLE0 + 9) {
+ erase();
+ wnoutrefresh(stdscr);
+ console_select(keycode - QEMU_KEY_CONSOLE0);
+
+ invalidate = 1;
+ continue;
+ }
+ }
+ }
+
+ if (is_active_console(vga_console)) {
+ /* since terminals don't know about key press and release
+ * events, we need to emit both for each key received */
+ if (keycode & SHIFT)
+ kbd_put_keycode(SHIFT_CODE);
+ if (keycode & CNTRL)
+ kbd_put_keycode(CNTRL_CODE);
+ if (keycode & ALT)
+ kbd_put_keycode(ALT_CODE);
+ if (keycode & GREY)
+ kbd_put_keycode(GREY_CODE);
+ kbd_put_keycode(keycode & KEY_MASK);
+ if (keycode & GREY)
+ kbd_put_keycode(GREY_CODE);
+ kbd_put_keycode((keycode & KEY_MASK) | KEY_RELEASE);
+ if (keycode & ALT)
+ kbd_put_keycode(ALT_CODE | KEY_RELEASE);
+ if (keycode & CNTRL)
+ kbd_put_keycode(CNTRL_CODE | KEY_RELEASE);
+ if (keycode & SHIFT)
+ kbd_put_keycode(SHIFT_CODE | KEY_RELEASE);
+ } else {
+ keysym = curses2keysym[chr];
+ if (keysym == -1)
+ keysym = chr;
+
+ kbd_put_keysym(keysym);
+ }
+ }
+}
+
+static void curses_cleanup(void)
+{
+ endwin();
+}
+
+static void curses_setup(void)
+{
+ int i, colour_default[8] = {
+ COLOR_BLACK, COLOR_BLUE, COLOR_GREEN, COLOR_CYAN,
+ COLOR_RED, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE,
+ };
+
+ /* input as raw as possible, let everything be interpreted
+ * by the guest system */
+ initscr(); noecho(); intrflush(stdscr, FALSE);
+ nonl(); keypad(stdscr, TRUE); start_color();
+ raw(); scrollok(stdscr, FALSE);
+
+ for (i = 0; i < 64; i ++)
+ init_pair(i, colour_default[i & 7], colour_default[i >> 3]);
+}
+
+void curses_display_init(DisplayState *ds, int full_screen)
+{
+ /* the terminal deals with keyboard layouts so we don't need to */
+
+#ifndef _WIN32
+ if (!isatty(1)) {
+ fprintf(stderr, "We need a terminal output\n");
+ exit(1);
+ }
+#endif
+
+ curses_setup();
+
+#ifndef _WIN32
+ signal(SIGINT, SIG_DFL);
+ signal(SIGQUIT, SIG_DFL);
+#ifdef SIGWINCH
+ /* some curses implementations provide a handler, but we
+ * want to be sure this is handled regardless of the library */
+ signal(SIGWINCH, curses_winch_handler);
+#endif
+#endif
+
+ ds->data = screen;
+ ds->linesize = 0;
+ ds->depth = 0;
+ ds->width = 640;
+ ds->height = 400;
+ ds->dpy_update = curses_update;
+ ds->dpy_resize = curses_resize;
+ ds->dpy_refresh = curses_refresh;
+
+ invalidate = 0;
+
+ /* Standard VGA initial text mode dimensions */
+ curses_resize(ds, 80, 25);
+
+ atexit(curses_cleanup);
+}
+/* vim: set ai ts=4 sw=4 et: */
diff -Naur qemu/curses_keys.h qemu-curses/curses_keys.h
--- qemu/curses_keys.h 1970-01-01 00:00:00.000000000 +0000
+++ qemu-curses/curses_keys.h 2005-12-12 05:28:52.000000000 +0000
@@ -0,0 +1,241 @@
+/*
+ * Keycode and keysyms conversion tables for curses
+ *
+ * Copyright (c) 2005 Andrzej Zaborowski <balrog@zabor.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#define KEY_RELEASE 128
+#define KEY_MASK 127
+#define SHIFT_CODE 42
+#define SHIFT 128
+#define GREY_CODE 224
+#define GREY 256
+#define CNTRL_CODE 29
+#define CNTRL 512
+#define ALT_CODE 56
+#define ALT 1024
+
+/* curses won't detect a Control + Alt + 1, so use Alt + 1 */
+#define QEMU_KEY_CONSOLE0 (2 | ALT) /* (curses2keycode['1'] | ALT) */
+
+#define CURSES_KEYS KEY_MAX /* KEY_MAX defined in <curses.h> */
+
+int curses2keycode[CURSES_KEYS] = {
+ [0 ... (CURSES_KEYS - 1)] = -1,
+
+ [27] = 1, /* Escape */
+ ['1'] = 2,
+ ['2'] = 3,
+ ['3'] = 4,
+ ['4'] = 5,
+ ['5'] = 6,
+ ['6'] = 7,
+ ['7'] = 8,
+ ['8'] = 9,
+ ['9'] = 10,
+ ['0'] = 11,
+ ['-'] = 12,
+ ['='] = 13,
+ [127] = 14, /* Backspace */
+ [263] = 14, /* Backspace */
+
+ ['\t'] = 15, /* Tab */
+ ['q'] = 16,
+ ['w'] = 17,
+ ['e'] = 18,
+ ['r'] = 19,
+ ['t'] = 20,
+ ['y'] = 21,
+ ['u'] = 22,
+ ['i'] = 23,
+ ['o'] = 24,
+ ['p'] = 25,
+ ['['] = 26,
+ [']'] = 27,
+ ['\n'] = 28, /* Return */
+ ['\r'] = 28, /* Return */
+ [343] = 28, /* Return */
+
+ ['a'] = 30,
+ ['s'] = 31,
+ ['d'] = 32,
+ ['f'] = 33,
+ ['g'] = 34,
+ ['h'] = 35,
+ ['j'] = 36,
+ ['k'] = 37,
+ ['l'] = 38,
+ [';'] = 39,
+ ['\''] = 40, /* Single quote */
+ ['`'] = 41,
+ ['\\'] = 43, /* Backslash */
+
+ ['z'] = 44,
+ ['x'] = 45,
+ ['c'] = 46,
+ ['v'] = 47,
+ ['b'] = 48,
+ ['n'] = 49,
+ ['m'] = 50,
+ [','] = 51,
+ ['.'] = 52,
+ ['/'] = 53,
+
+ [' '] = 57,
+
+ [265] = 59, /* Function Key 1 */
+ [266] = 60, /* Function Key 2 */
+ [267] = 61, /* Function Key 3 */
+ [268] = 62, /* Function Key 4 */
+ [269] = 63, /* Function Key 5 */
+ [270] = 64, /* Function Key 6 */
+ [271] = 65, /* Function Key 7 */
+ [272] = 66, /* Function Key 8 */
+ [273] = 67, /* Function Key 9 */
+ [274] = 68, /* Function Key 10 */
+ [275] = 87, /* Function Key 11 */
+ [276] = 88, /* Function Key 12 */
+
+ [262] = 71 | GREY, /* Home */
+ [259] = 72 | GREY, /* Up Arrow */
+ [339] = 73 | GREY, /* Page Up */
+ [260] = 75 | GREY, /* Left Arrow */
+ [261] = 77 | GREY, /* Right Arrow */
+ [360] = 79 | GREY, /* End */
+ [258] = 80 | GREY, /* Down Arrow */
+ [338] = 81 | GREY, /* Page Down */
+ [331] = 82 | GREY, /* Insert */
+ [330] = 83 | GREY, /* Delete */
+
+ ['!'] = 2 | SHIFT,
+ ['@'] = 3 | SHIFT,
+ ['#'] = 4 | SHIFT,
+ ['$'] = 5 | SHIFT,
+ ['%'] = 6 | SHIFT,
+ ['^'] = 7 | SHIFT,
+ ['&'] = 8 | SHIFT,
+ ['*'] = 9 | SHIFT,
+ ['('] = 10 | SHIFT,
+ [')'] = 11 | SHIFT,
+ ['_'] = 12 | SHIFT,
+ ['+'] = 13 | SHIFT,
+
+ [353] = 15 | SHIFT, /* Shift + Tab */
+ ['Q'] = 16 | SHIFT,
+ ['W'] = 17 | SHIFT,
+ ['E'] = 18 | SHIFT,
+ ['R'] = 19 | SHIFT,
+ ['T'] = 20 | SHIFT,
+ ['Y'] = 21 | SHIFT,
+ ['U'] = 22 | SHIFT,
+ ['I'] = 23 | SHIFT,
+ ['O'] = 24 | SHIFT,
+ ['P'] = 25 | SHIFT,
+ ['{'] = 26 | SHIFT,
+ ['}'] = 27 | SHIFT,
+
+ ['A'] = 30 | SHIFT,
+ ['S'] = 31 | SHIFT,
+ ['D'] = 32 | SHIFT,
+ ['F'] = 33 | SHIFT,
+ ['G'] = 34 | SHIFT,
+ ['H'] = 35 | SHIFT,
+ ['J'] = 36 | SHIFT,
+ ['K'] = 37 | SHIFT,
+ ['L'] = 38 | SHIFT,
+ [':'] = 39 | SHIFT,
+ ['"'] = 40 | SHIFT,
+ ['~'] = 41 | SHIFT,
+ ['|'] = 43 | SHIFT,
+
+ ['Z'] = 44 | SHIFT,
+ ['X'] = 45 | SHIFT,
+ ['C'] = 46 | SHIFT,
+ ['V'] = 47 | SHIFT,
+ ['B'] = 48 | SHIFT,
+ ['N'] = 49 | SHIFT,
+ ['M'] = 50 | SHIFT,
+ ['<'] = 51 | SHIFT,
+ ['>'] = 52 | SHIFT,
+ ['?'] = 53 | SHIFT,
+
+ [277] = 59 | SHIFT, /* Shift + Function Key 1 */
+ [278] = 60 | SHIFT, /* Shift + Function Key 2 */
+ [279] = 61 | SHIFT, /* Shift + Function Key 3 */
+ [280] = 62 | SHIFT, /* Shift + Function Key 4 */
+ [281] = 63 | SHIFT, /* Shift + Function Key 5 */
+ [282] = 64 | SHIFT, /* Shift + Function Key 6 */
+ [283] = 65 | SHIFT, /* Shift + Function Key 7 */
+ [284] = 66 | SHIFT, /* Shift + Function Key 8 */
+
+ [17] = 16 | CNTRL, /* Control + q */
+ [23] = 17 | CNTRL, /* Control + w */
+ [5] = 18 | CNTRL, /* Control + e */
+ [18] = 19 | CNTRL, /* Control + r */
+ [20] = 20 | CNTRL, /* Control + t */
+ [25] = 21 | CNTRL, /* Control + y */
+ [21] = 22 | CNTRL, /* Control + u */
+ [9] = 23 | CNTRL, /* Control + i */
+ [15] = 24 | CNTRL, /* Control + o */
+ [16] = 25 | CNTRL, /* Control + p */
+
+ [1] = 30 | CNTRL, /* Control + a */
+ [19] = 31 | CNTRL, /* Control + s */
+ [4] = 32 | CNTRL, /* Control + d */
+ [6] = 33 | CNTRL, /* Control + f */
+ [7] = 34 | CNTRL, /* Control + g */
+ [8] = 35 | CNTRL, /* Control + h */
+ [10] = 36 | CNTRL, /* Control + j */
+ [11] = 37 | CNTRL, /* Control + k */
+ [12] = 38 | CNTRL, /* Control + l */
+
+ [26] = 44 | CNTRL, /* Control + z */
+ [24] = 45 | CNTRL, /* Control + x */
+ [3] = 46 | CNTRL, /* Control + c */
+ [22] = 47 | CNTRL, /* Control + v */
+ [2] = 48 | CNTRL, /* Control + b */
+ [14] = 49 | CNTRL, /* Control + n */
+ /* Control + m collides with the keycode for Enter */
+
+};
+
+int curses2keysym[CURSES_KEYS] = {
+ [0 ... (CURSES_KEYS - 1)] = -1,
+
+ ['\n'] = '\n',
+ ['\r'] = '\n',
+
+ [127] = QEMU_KEY_BACKSPACE,
+
+ [258] = QEMU_KEY_DOWN,
+ [259] = QEMU_KEY_UP,
+ [260] = QEMU_KEY_LEFT,
+ [261] = QEMU_KEY_RIGHT,
+ [262] = QEMU_KEY_HOME,
+ [263] = QEMU_KEY_BACKSPACE,
+
+ [330] = QEMU_KEY_DELETE,
+ [338] = QEMU_KEY_PAGEDOWN,
+ [339] = QEMU_KEY_PAGEUP,
+ [343] = '\n',
+ [360] = QEMU_KEY_END,
+
+};
+/* vim: set ai ts=4 sw=4 et: */
diff -Naur qemu/hw/vga.c qemu-curses/hw/vga.c
--- qemu/hw/vga.c 2005-07-03 14:00:51.000000000 +0000
+++ qemu-curses/hw/vga.c 2005-12-09 03:59:45.000000000 +0000
@@ -1100,14 +1100,14 @@
s->cursor_end = s->cr[0xb];
}
cursor_ptr = s->vram_ptr + (s->start_addr + cursor_offset) * 4;
-
+
depth_index = get_depth_index(s->ds->depth);
if (cw == 16)
vga_draw_glyph8 = vga_draw_glyph16_table[depth_index];
else
vga_draw_glyph8 = vga_draw_glyph8_table[depth_index];
vga_draw_glyph9 = vga_draw_glyph9_table[depth_index];
-
+
dest = s->ds->data;
linesize = s->ds->linesize;
ch_attr_ptr = s->last_ch_attr;
@@ -1505,7 +1505,7 @@
s->rgb_to_pixel = rgb_to_pixel32_dup;
break;
}
-
+
full_update = 0;
if (!(s->ar_index & 0x20)) {
graphic_mode = GMODE_BLANK;
@@ -1880,3 +1880,165 @@
}
s->ds = saved_ds;
}
+
+#define TEXTMODE_X(x) ((x) % width)
+#define TEXTMODE_Y(x) ((x) / width)
+#define VMEM2CHTYPE(v) ((v & 0xff0007ff) | \
+ ((v & 0x00000800) << 10) | ((v & 0x00007000) >> 1))
+/* relay text rendering to given functions (i.e curses driver)
+ * instead of doing full vga_update_display() */
+void vga_update_text(uint8_t *chardata, void (*dpy_cursor)(DisplayState *s,
+ int x, int y))
+{
+ VGAState *s = vga_state;
+ int graphic_mode, i, cursor_offset, cursor_visible;
+ int cw, cheight, width, height, size, c_min, c_max;
+ uint32_t *src, *dst, val;
+ char msg_buffer[80];
+ int full_update;
+ full_update = 0;
+
+ if (!(s->ar_index & 0x20)) {
+ graphic_mode = GMODE_BLANK;
+ } else {
+ graphic_mode = s->gr[6] & 1;
+ }
+ if (graphic_mode != s->graphic_mode) {
+ s->graphic_mode = graphic_mode;
+ full_update = 1;
+ }
+ if (s->last_width == -1) {
+ s->last_width = 0;
+ full_update = 1;
+ }
+
+ switch(graphic_mode) {
+ case GMODE_TEXT:
+ /* TODO: update palette */
+ full_update |= update_basic_params(s);
+
+ /* total width & height */
+ cheight = (s->cr[9] & 0x1f) + 1;
+ cw = 8;
+ if (!(s->sr[1] & 0x01))
+ cw = 9;
+ if (s->sr[1] & 0x08)
+ cw = 16; /* NOTE: no 18 pixel wide */
+ width = (s->cr[0x01] + 1);
+ if (s->cr[0x06] == 100) {
+ /* ugly hack for CGA 160x100x16 - explain me the logic */
+ height = 100;
+ } else {
+ height = s->cr[0x12] |
+ ((s->cr[0x07] & 0x02) << 7) |
+ ((s->cr[0x07] & 0x40) << 3);
+ height = (height + 1) / cheight;
+ }
+
+ size = (height * width);
+ if (size > CH_ATTR_SIZE) {
+ if (!full_update)
+ return;
+
+ sprintf(msg_buffer, "%i x %i Text mode", width, height);
+ break;
+ }
+
+ if (width != s->last_width || height != s->last_height ||
+ cw != s->last_cw || cheight != s->last_ch) {
+ s->last_scr_width = width * cw;
+ s->last_scr_height = height * cheight;
+ dpy_resize(s->ds, width, height);
+ s->last_width = width;
+ s->last_height = height;
+ s->last_ch = cheight;
+ s->last_cw = cw;
+ full_update = 1;
+ }
+
+ /* Update "hardware" cursor */
+ cursor_offset = ((s->cr[0x0e] << 8) | s->cr[0x0f]) - s->start_addr;
+ if (cursor_offset != s->cursor_offset ||
+ s->cr[0xa] != s->cursor_start ||
+ s->cr[0xb] != s->cursor_end || full_update) {
+ cursor_visible = !(s->cr[0xa] & 0x20);
+ if (cursor_visible && cursor_offset < size && cursor_offset >= 0)
+ dpy_cursor(s->ds,
+ TEXTMODE_X(cursor_offset),
+ TEXTMODE_Y(cursor_offset));
+ else
+ dpy_cursor(s->ds, -1, -1);
+ s->cursor_offset = cursor_offset;
+ s->cursor_start = s->cr[0xa];
+ s->cursor_end = s->cr[0xb];
+ }
+
+ src = (uint32_t *) s->vram_ptr + s->start_addr;
+ dst = (uint32_t *) chardata;
+
+ if (full_update) {
+ for (i = 0; i < size; src ++, dst ++, i ++) {
+ val = VMEM2CHTYPE(*src);
+ *dst = val;
+ }
+
+ dpy_update(s->ds, 0, 0, width, height);
+ } else {
+ c_max = 0;
+
+ for (i = 0; i < size; src ++, dst ++, i ++) {
+ val = VMEM2CHTYPE(*src);
+ if (*dst != val) {
+ *dst = val;
+ c_max = i;
+ break;
+ }
+ }
+ c_min = i;
+ for (; i < size; src ++, dst ++, i ++) {
+ val = VMEM2CHTYPE(*src);
+ if (*dst != val) {
+ *dst = val;
+ c_max = i;
+ }
+ }
+
+ if (c_min <= c_max) {
+ i = TEXTMODE_Y(c_min);
+ dpy_update(s->ds, 0, i, width, TEXTMODE_Y(c_max) - i + 1);
+ }
+ }
+
+ return;
+ case GMODE_GRAPH:
+ if (!full_update)
+ return;
+
+ s->get_resolution(s, &width, &height);
+ sprintf(msg_buffer, "%i x %i Graphic mode", width, height);
+ break;
+ case GMODE_BLANK:
+ default:
+ if (!full_update)
+ return;
+
+ sprintf(msg_buffer, "VGA Blank mode");
+ break;
+ }
+
+ /* Display a message */
+ dpy_cursor(s->ds, -1, -1);
+ dpy_resize(s->ds, 60, 3);
+ memset(chardata, 0, 60 * 3 * 4);
+ size = strlen(msg_buffer);
+ width = (60 - size) / 2;
+ for (i = 0; i < 60 * 3 * 4; i += 4)
+ chardata[i] = ' ';
+ for (i = 0; i < size; i ++) {
+ chardata[(60 + width + i) * 4] = msg_buffer[i];
+ chardata[(60 + width + i) * 4 + 1] = 0x01; /* colour */
+ chardata[(60 + width + i) * 4 + 2] = 0x20; /* colour */
+ }
+ dpy_update(s->ds, 0, 0, 60, 3);
+}
+/* vim: set ai ts=4 sw=4 et: */
diff -Naur qemu/vl.c qemu-curses/vl.c
--- qemu/vl.c 2005-12-05 20:31:52.000000000 +0000
+++ qemu-curses/vl.c 2005-12-08 19:00:57.000000000 +0000
@@ -115,6 +115,7 @@
int bios_size;
static DisplayState display_state;
int nographic;
+int curses;
const char* keyboard_layout = NULL;
int64_t ticks_per_sec;
int boot_device = 'c';
@@ -3840,6 +3841,9 @@
"-hdachs c,h,s[,t] force hard disk 0 physical geometry and the optional BIOS\n"
" translation (t=none or lba) (usually qemu can guess them)\n"
"-L path set the directory for the BIOS and VGA BIOS\n"
+#ifdef CONFIG_CURSES
+ "-curses use a curses/ncurses interface instead of SDL\n"
+#endif
#ifdef USE_KQEMU
"-no-kqemu disable KQEMU kernel module usage\n"
#endif
@@ -3934,6 +3938,7 @@
QEMU_OPTION_usb,
QEMU_OPTION_usbdevice,
QEMU_OPTION_smp,
+ QEMU_OPTION_curses,
};
typedef struct QEMUOption {
@@ -3984,6 +3989,9 @@
{ "hdachs", HAS_ARG, QEMU_OPTION_hdachs },
{ "L", HAS_ARG, QEMU_OPTION_L },
{ "no-code-copy", 0, QEMU_OPTION_no_code_copy },
+#ifdef CONFIG_CURSES
+ { "curses", 0, QEMU_OPTION_curses },
+#endif
#ifdef USE_KQEMU
{ "no-kqemu", 0, QEMU_OPTION_no_kqemu },
#endif
@@ -4202,6 +4210,7 @@
#endif
snapshot = 0;
nographic = 0;
+ curses = 0;
kernel_filename = NULL;
kernel_cmdline = "";
#ifdef TARGET_PPC
@@ -4335,7 +4344,16 @@
pstrcpy(monitor_device, sizeof(monitor_device), "stdio");
pstrcpy(serial_devices[0], sizeof(serial_devices[0]), "stdio");
nographic = 1;
+ curses = 0;
+ break;
+#ifdef CONFIG_CURSES
+ case QEMU_OPTION_curses:
+ pstrcpy(monitor_device, sizeof(monitor_device), "vc");
+ pstrcpy(serial_devices[0], sizeof(serial_devices[0]), "vc");
+ curses = 1;
+ nographic = 0;
break;
+#endif
case QEMU_OPTION_kernel:
kernel_filename = optarg;
break;
@@ -4714,7 +4732,13 @@
/* terminal init */
if (nographic) {
dumb_display_init(ds);
- } else {
+ } else
+#if defined(CONFIG_CURSES)
+ if (curses) {
+ curses_display_init(ds, full_screen);
+ } else
+#endif
+ {
#if defined(CONFIG_SDL)
sdl_display_init(ds, full_screen);
#elif defined(CONFIG_COCOA)
@@ -4725,7 +4749,7 @@
}
vga_console = graphic_console_init(ds);
-
+
monitor_hd = qemu_chr_open(monitor_device);
if (!monitor_hd) {
fprintf(stderr, "qemu: could not open monitor device '%s'\n", monitor_device);
diff -Naur qemu/vl.h qemu-curses/vl.h
--- qemu/vl.h 2005-12-05 20:31:52.000000000 +0000
+++ qemu-curses/vl.h 2005-12-08 18:59:24.000000000 +0000
@@ -265,6 +265,7 @@
int is_active_console(TextConsole *s);
CharDriverState *text_console_init(DisplayState *ds);
void console_select(unsigned int index);
+TextConsole *get_active_console();
/* serial ports */
@@ -652,6 +653,8 @@
void vga_update_display(void);
void vga_invalidate_display(void);
void vga_screen_dump(const char *filename);
+void vga_update_text(uint8_t *chardata, void (*dpy_cursor)
+ (DisplayState *s, int x, int y));
/* cirrus_vga.c */
void pci_cirrus_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base,
@@ -665,6 +668,9 @@
/* cocoa.m */
void cocoa_display_init(DisplayState *ds, int full_screen);
+/* curses.c */
+void curses_display_init(DisplayState *ds, int full_screen);
+
/* ide.c */
#define MAX_DISKS 4
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] Re: qemu curses driver
2005-12-12 6:58 ` [Qemu-devel] " andrzej zaborowski
@ 2005-12-12 10:46 ` Johannes Schindelin
2005-12-12 22:53 ` andrzej zaborowski
0 siblings, 1 reply; 7+ messages in thread
From: Johannes Schindelin @ 2005-12-12 10:46 UTC (permalink / raw)
To: qemu-devel
Hi,
thank you for your quick reply!
On Mon, 12 Dec 2005, andrzej zaborowski wrote:
> - fixed the terminal resize event handling, now it should work
> regardless of the curses library implementation,
Unfortunately, it does not work here. ATM I am using a cygwin rxvt, and
run qemu via SSH. I don't know if rxvt can resize, or if I have to allow
it... Ideas?
> - some keyboard input details,
I usually test QEmu with a floppy image of Injector Linux. When I
want to delete a word, I use Escape+d or Escape+BackSpace. I still do not
get the desired result.
> - and changed the Makefile to compile the curses driver for all
> targets that use the VGA emulator (from hw/vga.c) - that means all
> targets except Sparc and ARM - I think it is also possible to make
> this work for Sparc and ARM but I don't know anything about these
> architectures and wouldn't have any way to perform any testing and I
> also don't know how useful this would be.
That is very good!
> Any comments are welcome, especially if someone encounters any further
> bugs or malfunctioning of the interface. What do you think about
> including the curses interface in QEMU?
I like it very much. It makes it especially easy to copy text from the
guest. I am very much in favor of inclusion. Now let's see what our BDFL
says ;-)
Ciao,
Dscho
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Qemu-devel] Re: qemu curses driver
@ 2005-12-12 16:39 Blue Swirl
2005-12-12 23:19 ` andrzej zaborowski
0 siblings, 1 reply; 7+ messages in thread
From: Blue Swirl @ 2005-12-12 16:39 UTC (permalink / raw)
To: balrogg; +Cc: qemu-devel
Hi,
Sparc32 graphics cards are just frame buffers without a text mode. Sparc64
uses PCI cards, including VGA, so any text mode enhancements could be useful
there.
If you have a VGA test program, I could try to port it to Sparc64.
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] Re: qemu curses driver
2005-12-12 10:46 ` Johannes Schindelin
@ 2005-12-12 22:53 ` andrzej zaborowski
0 siblings, 0 replies; 7+ messages in thread
From: andrzej zaborowski @ 2005-12-12 22:53 UTC (permalink / raw)
To: qemu-devel
Hi there,
On 12/12/05, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> > - fixed the terminal resize event handling, now it should work
> > regardless of the curses library implementation,
>
> Unfortunately, it does not work here. ATM I am using a cygwin rxvt, and
> run qemu via SSH. I don't know if rxvt can resize, or if I have to allow
> it... Ideas?
I have never tried Cygwin, but the terminal resizing relies entirely
on signals, which Ms Windows doesn't have but I suppose Cygwin should
emulate signals somehow. Also I think SSH passes the WINCH signal
correctly (Cygwin uses OpenSSH, right?). I now installed mrxvt and
rxvt and indeed the terminal starts up with 80x24 characters by
default, but the window is resizable and QEMU reacts correctly to
resizing (good thing is that everything seems to work even much faster
than in xterm or gnome-terminal - what I don't like is that the cursor
is in one colour only and thus invisible on some backgrounds). It also
works over "ssh localhost" on my Linux.
So I guess one of the elements between your terminal emulator and qemu
is failing to pass the signal further, because there may be quite some
elements working there:
- The terminal emulator (that initially should emit the signal),
- The shell in that terminal (that is the direct child process of the rxvt),
- The SSH client (direct child process of the shell),
- The SSH server (that should receive the signal over the network),
- The shell that is the direct child process of the server-side SSH,
- Finally QEMU that is a child process of the remote shell.
Can you check if for example Midnight Commander (mc) ran in the same
configuration (outside QEMU) resizes correctly?
Is the current behaviour such that when you make the terminal window
bigger than 80x24 while QEMU is running, the virtual machine's screen
stays at only 80x24 characters and stays in the top-left corner of the
terminal?
> > - some keyboard input details,
>
> I usually test QEmu with a floppy image of Injector Linux. When I
> want to delete a word, I use Escape+d or Escape+BackSpace. I still do not
> get the desired result.
O.o
Again I don't know why this might not work. Again can you check how MC
would cope with it? Make sure that the TERM shell variable is set to
"rxvt" or the correct value. I find MC very useful for this kind of
testing (not only for this, ofcourse), with its "Learn keys" option.
Do other programs running in your rxvt react to Escape+d and
Escape+BackSpace?
> I like it very much. It makes it especially easy to copy text from the
> guest. I am very much in favor of inclusion. Now let's see what our BDFL
> says ;-)
Thanks for positive opinion! :)
greetings,
--
balrog 2oo5
Dear Outlook users: Please remove me from your address books
http://www.newsforge.com/article.pl?sid=03/08/21/143258
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Qemu-devel] Re: qemu curses driver
2005-12-12 16:39 [Qemu-devel] Re: qemu curses driver Blue Swirl
@ 2005-12-12 23:19 ` andrzej zaborowski
2005-12-13 18:53 ` Blue Swirl
0 siblings, 1 reply; 7+ messages in thread
From: andrzej zaborowski @ 2005-12-12 23:19 UTC (permalink / raw)
To: Blue Swirl; +Cc: qemu-devel
Hiya,
On 12/12/05, Blue Swirl <blueswir1@hotmail.com> wrote:
> Sparc32 graphics cards are just frame buffers without a text mode. Sparc64
> uses PCI cards, including VGA, so any text mode enhancements could be useful
> there.
I just noticed that there's a Sparc64 architecture, and it is there
quite separate from Sparc32. I only didn't see it before because it
doesn't appear in the output of "./configure --help" together with
other targets.
Indeed the "qemu-system-sparc64" executable, unlinke
qemu-system-sparc, is linked with "vga.o", the normal PCI card VGA
emulator.
Fortunately I disabled compiling with Curses only for "sparc" and
"arm", so when I reran ./configure with "sparc64" in the targets list
it compiled just fine with curses support built into
qemu-system-sparc64.
I only have no way to see whether everything works because I didn't
even find a working BIOS image for Sparc 64, but it should be fine.
Do the video adapters used in Sparc 32 machines really have nothing
like a text mode?
Cheers,
--
balrog 2oo5
Dear Outlook users: Please remove me from your address books
http://www.newsforge.com/article.pl?sid=03/08/21/143258
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Qemu-devel] Re: qemu curses driver
2005-12-12 23:19 ` andrzej zaborowski
@ 2005-12-13 18:53 ` Blue Swirl
0 siblings, 0 replies; 7+ messages in thread
From: Blue Swirl @ 2005-12-13 18:53 UTC (permalink / raw)
To: balrogg; +Cc: qemu-devel
>I only have no way to see whether everything works because I didn't
>even find a working BIOS image for Sparc 64, but it should be fine.
>Do the video adapters used in Sparc 32 machines really have nothing
>like a text mode?
No, they are just frame buffers converting pixel data to RGB. For example, a
machine would start directly in 1024x768x24bit mode. Boot prom provides some
primitive text output functions, but Linux very early starts to use its own
frame buffer drivers.
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Qemu-devel] Re: qemu curses driver
2005-12-10 8:17 [Qemu-devel] " andrzej zaborowski
2005-12-12 6:58 ` [Qemu-devel] " andrzej zaborowski
@ 2008-01-10 16:50 ` andrzej zaborowski
1 sibling, 0 replies; 7+ messages in thread
From: andrzej zaborowski @ 2008-01-10 16:50 UTC (permalink / raw)
To: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 662 bytes --]
Hi,
here's an iteration of the curses UI patch, for 0.9.1. This time it
takes into account "such modern concepts" ;) like endianness and
64-bits, so it should work on PPC and on amd64, as opposed to previous
versions. (ncurses apparently chose to not make a seamless transition
to 64-bits).
I would like to merge this patch at some point if there's no
objection. It was in Debian until now and recently broke and a number
of users got annoyed.
The runtime UI switching trick is not included. The monitor history
saving is not included but it is in the svn.openmoko.org tree and
should apply ok. Switching between VCs is still done with
<alt>+<number>.
Regards
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: curses.patch --]
[-- Type: text/x-patch; name=curses.patch, Size: 53243 bytes --]
diff --git a/Makefile b/Makefile
index e76d617..b823bfa 100644
--- a/Makefile
+++ b/Makefile
@@ -90,6 +90,9 @@ OBJS+=$(addprefix audio/, $(AUDIO_OBJS))
ifdef CONFIG_SDL
OBJS+=sdl.o x_keymap.o
endif
+ifdef CONFIG_CURSES
+OBJS+=curses.o
+endif
OBJS+=vnc.o d3des.o
ifdef CONFIG_COCOA
@@ -113,6 +116,9 @@ sdl.o: sdl.c keymaps.c sdl_keysym.h
vnc.o: vnc.c keymaps.c sdl_keysym.h vnchextile.h d3des.c d3des.h
$(CC) $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) $(CONFIG_VNC_TLS_CFLAGS) -c -o $@ $<
+curses.o: curses.c keymaps.c curses_keys.h
+ $(CC) $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) -c -o $@ $<
+
audio/sdlaudio.o: audio/sdlaudio.c
$(CC) $(CFLAGS) $(CPPFLAGS) $(SDL_CFLAGS) $(BASE_CFLAGS) -c -o $@ $<
diff --git a/Makefile.target b/Makefile.target
index acd6cda..caad4f0 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -569,7 +569,7 @@ SDL_LIBS := $(filter-out -mwindows, $(SDL_LIBS)) -mconsole
endif
$(QEMU_SYSTEM): $(VL_OBJS) ../libqemu_common.a libqemu.a
- $(CC) $(VL_LDFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(COCOA_LIBS) $(VL_LIBS)
+ $(CC) $(VL_LDFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(COCOA_LIBS) $(CURSES_LIBS) $(VL_LIBS)
depend: $(SRCS)
$(CC) -MM $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) $^ 1>.depend
diff --git a/configure b/configure
index d86020e..94b5e78 100755
--- a/configure
+++ b/configure
@@ -105,6 +105,7 @@ linux_user="no"
darwin_user="no"
build_docs="no"
uname_release=""
+curses="yes"
# OS specific
targetos=`uname -s`
@@ -316,6 +317,8 @@ for opt do
;;
--disable-werror) werror="no"
;;
+ --disable-curses) curses="no"
+ ;;
*) echo "ERROR: unknown option $opt"; show_help="yes"
;;
esac
@@ -662,6 +665,20 @@ EOF
fi
fi
+##########################################
+# curses probe
+
+if test "$curses" = "yes" ; then
+ curses=no
+ cat > $TMPC << EOF
+#include <curses.h>
+int main(void) { return curses_version(); }
+EOF
+ if $cc -o $TMPE $TMPC -lcurses 2> /dev/null ; then
+ curses=yes
+ fi
+fi # test "$curses"
+
# Check if tools are available to build documentation.
if [ -x "`which texi2html 2>/dev/null`" ] && \
[ -x "`which pod2man 2>/dev/null`" ]; then
@@ -712,6 +729,7 @@ echo "SDL support $sdl"
if test "$sdl" != "no" ; then
echo "SDL static link $sdl_static"
fi
+echo "curses support $curses"
echo "mingw32 support $mingw32"
echo "Adlib support $adlib"
echo "CoreAudio support $coreaudio"
@@ -949,8 +967,13 @@ if test "$sdl1" = "yes" ; then
fi
fi
if test "$cocoa" = "yes" ; then
- echo "#define CONFIG_COCOA 1" >> $config_h
- echo "CONFIG_COCOA=yes" >> $config_mak
+ echo "#define CONFIG_COCOA 1" >> $config_h
+ echo "CONFIG_COCOA=yes" >> $config_mak
+fi
+if test "$curses" = "yes" ; then
+ echo "#define CONFIG_CURSES 1" >> $config_h
+ echo "CONFIG_CURSES=yes" >> $config_mak
+ echo "CURSES_LIBS=-lcurses" >> $config_mak
fi
# XXX: suppress that
@@ -1015,7 +1038,8 @@ if test "$target_user_only" = "no" -a "$check_gfx" = "yes" \
-a "$sdl" = "no" -a "$cocoa" = "no" ; then
echo "ERROR: QEMU requires SDL or Cocoa for graphical output"
echo "To build QEMU without graphical output configure with --disable-gfx-check"
- echo "Note that this will disable all output from the virtual graphics card."
+ echo "Note that this will disable all output from the virtual graphics card"
+ echo "except through VNC or curses."
exit 1;
fi
diff --git a/console.c b/console.c
index e7c00ec..880ac83 100644
--- a/console.c
+++ b/console.c
@@ -121,6 +121,7 @@ struct TextConsole {
vga_hw_update_ptr hw_update;
vga_hw_invalidate_ptr hw_invalidate;
vga_hw_screen_dump_ptr hw_screen_dump;
+ vga_hw_text_update_ptr hw_text_update;
void *hw;
int g_width, g_height;
@@ -135,6 +136,7 @@ struct TextConsole {
TextAttributes t_attrib_default; /* default text attributes */
TextAttributes t_attrib; /* currently active text attributes */
TextCell *cells;
+ int text_x[2], text_y[2], cursor_invalidate;
enum TTYState state;
int esc_params[MAX_ESC_PARAMS];
@@ -171,6 +173,12 @@ void vga_hw_screen_dump(const char *filename)
consoles[0]->hw_screen_dump(consoles[0]->hw, filename);
}
+void vga_hw_text_update(console_ch_t *chardata)
+{
+ if (active_console && active_console->hw_text_update)
+ active_console->hw_text_update(active_console->hw, chardata);
+}
+
/* convert a RGBA color to a color index usable in graphic primitives */
static unsigned int vga_get_color(DisplayState *ds, unsigned int rgba)
{
@@ -515,12 +523,25 @@ static void text_console_resize(TextConsole *s)
s->cells = cells;
}
+static inline void text_update_xy(TextConsole *s, int x, int y)
+{
+ s->text_x[0] = MIN(s->text_x[0], x);
+ s->text_x[1] = MAX(s->text_x[1], x);
+ s->text_y[0] = MIN(s->text_y[0], y);
+ s->text_y[1] = MAX(s->text_y[1], y);
+}
+
static void update_xy(TextConsole *s, int x, int y)
{
TextCell *c;
int y1, y2;
if (s == active_console) {
+ if (!s->ds->depth) {
+ text_update_xy(s, x, y);
+ return;
+ }
+
y1 = (s->y_base + y) % s->total_height;
y2 = y1 - s->y_displayed;
if (y2 < 0)
@@ -542,6 +563,12 @@ static void console_show_cursor(TextConsole *s, int show)
if (s == active_console) {
int x = s->x;
+
+ if (!s->ds->depth) {
+ s->cursor_invalidate = 1;
+ return;
+ }
+
if (x >= s->width) {
x = s->width - 1;
}
@@ -571,6 +598,14 @@ static void console_refresh(TextConsole *s)
if (s != active_console)
return;
+ if (!s->ds->depth) {
+ s->text_x[0] = 0;
+ s->text_y[0] = 0;
+ s->text_x[1] = s->width - 1;
+ s->text_y[1] = s->height - 1;
+ s->cursor_invalidate = 1;
+ return;
+ }
vga_fill_rect(s->ds, 0, 0, s->ds->width, s->ds->height,
color_table[0][COLOR_BLACK]);
@@ -648,6 +683,14 @@ static void console_put_lf(TextConsole *s)
c++;
}
if (s == active_console && s->y_displayed == s->y_base) {
+ if (!s->ds->depth) {
+ s->text_x[0] = 0;
+ s->text_y[0] = 0;
+ s->text_x[1] = s->width - 1;
+ s->text_y[1] = s->height - 1;
+ return;
+ }
+
vga_bitblt(s->ds, 0, FONT_HEIGHT, 0, 0,
s->width * FONT_WIDTH,
(s->height - 1) * FONT_HEIGHT);
@@ -998,21 +1041,7 @@ void console_select(unsigned int index)
s = consoles[index];
if (s) {
active_console = s;
- if (s->console_type != GRAPHIC_CONSOLE) {
- if (s->g_width != s->ds->width ||
- s->g_height != s->ds->height) {
- if (s->console_type == TEXT_CONSOLE_FIXED_SIZE) {
- dpy_resize(s->ds, s->g_width, s->g_height);
- } else {
- s->g_width = s->ds->width;
- s->g_height = s->ds->height;
- text_console_resize(s);
- }
- }
- console_refresh(s);
- } else {
- vga_hw_invalidate();
- }
+ vga_hw_invalidate();
}
}
@@ -1116,6 +1145,52 @@ void kbd_put_keysym(int keysym)
}
}
+static void text_console_invalidate(void *opaque)
+{
+ TextConsole *s = (TextConsole *) opaque;
+
+ if (s->console_type != GRAPHIC_CONSOLE) {
+ if (s->g_width != s->ds->width ||
+ s->g_height != s->ds->height) {
+ if (s->console_type == TEXT_CONSOLE_FIXED_SIZE)
+ dpy_resize(s->ds, s->g_width, s->g_height);
+ else {
+ s->g_width = s->ds->width;
+ s->g_height = s->ds->height;
+ text_console_resize(s);
+ }
+ }
+ }
+ console_refresh(s);
+}
+
+static void text_console_update(void *opaque, console_ch_t *chardata)
+{
+ TextConsole *s = (TextConsole *) opaque;
+ int i, j, src;
+
+ if (s->text_x[0] <= s->text_x[1]) {
+ src = (s->y_base + s->text_y[0]) * s->width;
+ chardata += s->text_y[0] * s->width;
+ for (i = s->text_y[0]; i <= s->text_y[1]; i ++)
+ for (j = 0; j < s->width; j ++, src ++)
+ console_write_ch(chardata ++, s->cells[src].ch |
+ (s->cells[src].t_attrib.fgcol << 12) |
+ (s->cells[src].t_attrib.bgcol << 8) |
+ (s->cells[src].t_attrib.bold << 21));
+ dpy_update(s->ds, s->text_x[0], s->text_y[0],
+ s->text_x[1] - s->text_x[0], i - s->text_y[0]);
+ s->text_x[0] = s->width;
+ s->text_y[0] = s->height;
+ s->text_x[1] = 0;
+ s->text_y[1] = 0;
+ }
+ if (s->cursor_invalidate) {
+ dpy_cursor(s->ds, s->x, s->y);
+ s->cursor_invalidate = 0;
+ }
+}
+
static TextConsole *new_console(DisplayState *ds, console_type_t console_type)
{
TextConsole *s;
@@ -1150,6 +1225,7 @@ static TextConsole *new_console(DisplayState *ds, console_type_t console_type)
TextConsole *graphic_console_init(DisplayState *ds, vga_hw_update_ptr update,
vga_hw_invalidate_ptr invalidate,
vga_hw_screen_dump_ptr screen_dump,
+ vga_hw_text_update_ptr text_update,
void *opaque)
{
TextConsole *s;
@@ -1160,13 +1236,14 @@ TextConsole *graphic_console_init(DisplayState *ds, vga_hw_update_ptr update,
s->hw_update = update;
s->hw_invalidate = invalidate;
s->hw_screen_dump = screen_dump;
+ s->hw_text_update = text_update;
s->hw = opaque;
return s;
}
int is_graphic_console(void)
{
- return active_console->console_type == GRAPHIC_CONSOLE;
+ return active_console && active_console->console_type == GRAPHIC_CONSOLE;
}
void console_color_init(DisplayState *ds)
@@ -1234,6 +1311,10 @@ CharDriverState *text_console_init(DisplayState *ds, const char *p)
s->g_width = width;
s->g_height = height;
+ s->hw_invalidate = text_console_invalidate;
+ s->hw_text_update = text_console_update;
+ s->hw = s;
+
/* Set text attribute defaults */
s->t_attrib_default.bold = 0;
s->t_attrib_default.uline = 0;
diff --git a/console.h b/console.h
index 1ac74fa..b8a5c6d 100644
--- a/console.h
+++ b/console.h
@@ -79,6 +79,7 @@ struct DisplayState {
int dst_x, int dst_y, int w, int h);
void (*dpy_fill)(struct DisplayState *s, int x, int y,
int w, int h, uint32_t c);
+ void (*dpy_text_cursor)(struct DisplayState *s, int x, int y);
void (*mouse_set)(int x, int y, int on);
void (*cursor_define)(int width, int height, int bpp, int hot_x, int hot_y,
uint8_t *image, uint8_t *mask);
@@ -94,17 +95,32 @@ static inline void dpy_resize(DisplayState *s, int w, int h)
s->dpy_resize(s, w, h);
}
+static inline void dpy_cursor(DisplayState *s, int x, int y)
+{
+ if (s->dpy_text_cursor)
+ s->dpy_text_cursor(s, x, y);
+}
+
+typedef unsigned long console_ch_t;
+static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
+{
+ cpu_to_le32wu((uint32_t *) dest, ch);
+}
+
typedef void (*vga_hw_update_ptr)(void *);
typedef void (*vga_hw_invalidate_ptr)(void *);
typedef void (*vga_hw_screen_dump_ptr)(void *, const char *);
+typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *);
TextConsole *graphic_console_init(DisplayState *ds, vga_hw_update_ptr update,
vga_hw_invalidate_ptr invalidate,
vga_hw_screen_dump_ptr screen_dump,
+ vga_hw_text_update_ptr text_update,
void *opaque);
void vga_hw_update(void);
void vga_hw_invalidate(void);
void vga_hw_screen_dump(const char *filename);
+void vga_hw_text_update(console_ch_t *chardata);
int is_graphic_console(void);
CharDriverState *text_console_init(DisplayState *ds, const char *p);
@@ -124,6 +140,9 @@ int vnc_display_open(DisplayState *ds, const char *display);
int vnc_display_password(DisplayState *ds, const char *password);
void do_info_vnc(void);
+/* curses.c */
+void curses_display_init(DisplayState *ds, int full_screen);
+
/* x_keymap.c */
extern uint8_t _translate_keycode(const int key);
diff --git a/curses.c b/curses.c
new file mode 100644
index 0000000..a0f3b73
--- /dev/null
+++ b/curses.c
@@ -0,0 +1,370 @@
+/*
+ * QEMU curses/ncurses display driver
+ *
+ * Copyright (c) 2005 Andrzej Zaborowski <balrog@zabor.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "qemu-common.h"
+#include "console.h"
+#include "sysemu.h"
+
+#include <curses.h>
+
+#ifndef _WIN32
+#include <signal.h>
+#include <sys/ioctl.h>
+#include <termios.h>
+#endif
+
+#define FONT_HEIGHT 16
+#define FONT_WIDTH 8
+
+static console_ch_t screen[160 * 100];
+static WINDOW *screenpad = NULL;
+static int width, height, gwidth, gheight, invalidate;
+static int px, py, sminx, sminy, smaxx, smaxy;
+
+static void curses_update(DisplayState *ds, int x, int y, int w, int h)
+{
+ chtype *line;
+
+ line = ((chtype *) screen) + y * width;
+ for (h += y; y < h; y ++, line += width)
+ mvwaddchnstr(screenpad, y, 0, line, width);
+
+ pnoutrefresh(screenpad, py, px, sminy, sminx, smaxy - 1, smaxx - 1);
+ refresh();
+}
+
+static void curses_calc_pad(void)
+{
+ if (is_graphic_console()) {
+ width = gwidth;
+ height = gheight;
+ } else {
+ width = COLS;
+ height = LINES;
+ }
+
+ if (screenpad)
+ delwin(screenpad);
+
+ clear();
+ refresh();
+
+ screenpad = newpad(height, width);
+
+ if (width > COLS) {
+ px = (width - COLS) / 2;
+ sminx = 0;
+ smaxx = COLS;
+ } else {
+ px = 0;
+ sminx = (COLS - width) / 2;
+ smaxx = sminx + width;
+ }
+
+ if (height > LINES) {
+ py = (height - LINES) / 2;
+ sminy = 0;
+ smaxy = LINES;
+ } else {
+ py = 0;
+ sminy = (LINES - height) / 2;
+ smaxy = sminy + height;
+ }
+}
+
+static void curses_resize(DisplayState *ds, int w, int h)
+{
+ if (w == gwidth && h == gheight)
+ return;
+
+ gwidth = w;
+ gheight = h;
+
+ curses_calc_pad();
+}
+
+#ifndef _WIN32
+#ifdef SIGWINCH
+static void curses_winch_handler(int signum)
+{
+ struct winsize {
+ unsigned short ws_row;
+ unsigned short ws_col;
+ unsigned short ws_xpixel; /* unused */
+ unsigned short ws_ypixel; /* unused */
+ } ws;
+
+ /* terminal size changed */
+ if (ioctl(1, TIOCGWINSZ, &ws) == -1)
+ return;
+
+ resize_term(ws.ws_row, ws.ws_col);
+ curses_calc_pad();
+ invalidate = 1;
+
+ /* some systems require this */
+ signal(SIGWINCH, curses_winch_handler);
+}
+#endif
+#endif
+
+static void curses_cursor_position(DisplayState *ds, int x, int y)
+{
+ if (x >= 0) {
+ x = sminx + x - px;
+ y = sminy + y - py;
+
+ if (x >= 0 && y >= 0 && x < COLS && y < LINES) {
+ move(y, x);
+ curs_set(1);
+ /* it seems that curs_set(1) must always be called before
+ * curs_set(2) for the latter to have effect */
+ if (!is_graphic_console())
+ curs_set(2);
+ return;
+ }
+ }
+
+ curs_set(0);
+}
+
+/* generic keyboard conversion */
+
+#include "curses_keys.h"
+#include "keymaps.c"
+
+static kbd_layout_t *kbd_layout = 0;
+static int keycode2keysym[CURSES_KEYS];
+
+static void curses_refresh(DisplayState *ds)
+{
+ int chr, nextchr, keysym, keycode;
+
+ if (invalidate) {
+ clear();
+ refresh();
+ curses_calc_pad();
+ ds->width = FONT_WIDTH * width;
+ ds->height = FONT_HEIGHT * height;
+ vga_hw_invalidate();
+ invalidate = 0;
+ }
+
+ vga_hw_text_update(screen);
+
+ nextchr = ERR;
+ while (1) {
+ /* while there are any pending key strokes to process */
+ if (nextchr == ERR)
+ chr = getch();
+ else {
+ chr = nextchr;
+ nextchr = ERR;
+ }
+
+ if (chr == ERR)
+ break;
+
+ /* this shouldn't occur when we use a custom SIGWINCH handler */
+ if (chr == KEY_RESIZE) {
+ clear();
+ refresh();
+ curses_calc_pad();
+ curses_update(ds, 0, 0, width, height);
+ ds->width = FONT_WIDTH * width;
+ ds->height = FONT_HEIGHT * height;
+ continue;
+ }
+
+ keycode = curses2keycode[chr];
+ if (keycode == -1)
+ continue;
+
+ /* alt key */
+ if (keycode == 1) {
+ nextchr = getch();
+
+ if (nextchr != ERR) {
+ keycode = curses2keycode[nextchr];
+ nextchr = ERR;
+ if (keycode == -1)
+ continue;
+
+ keycode |= ALT;
+
+ /* process keys reserved for qemu */
+ if (keycode >= QEMU_KEY_CONSOLE0 &&
+ keycode < QEMU_KEY_CONSOLE0 + 9) {
+ erase();
+ wnoutrefresh(stdscr);
+ console_select(keycode - QEMU_KEY_CONSOLE0);
+
+ invalidate = 1;
+ continue;
+ }
+ }
+ }
+
+ if (kbd_layout && !(keycode & GREY)) {
+ keysym = keycode2keysym[keycode & KEY_MASK];
+ if (keysym == -1)
+ keysym = chr;
+
+ keycode &= ~KEY_MASK;
+ keycode |= keysym2scancode(kbd_layout, keysym);
+ }
+
+ if (is_graphic_console()) {
+ /* since terminals don't know about key press and release
+ * events, we need to emit both for each key received */
+ if (keycode & SHIFT)
+ kbd_put_keycode(SHIFT_CODE);
+ if (keycode & CNTRL)
+ kbd_put_keycode(CNTRL_CODE);
+ if (keycode & ALT)
+ kbd_put_keycode(ALT_CODE);
+ if (keycode & GREY)
+ kbd_put_keycode(GREY_CODE);
+ kbd_put_keycode(keycode & KEY_MASK);
+ if (keycode & GREY)
+ kbd_put_keycode(GREY_CODE);
+ kbd_put_keycode((keycode & KEY_MASK) | KEY_RELEASE);
+ if (keycode & ALT)
+ kbd_put_keycode(ALT_CODE | KEY_RELEASE);
+ if (keycode & CNTRL)
+ kbd_put_keycode(CNTRL_CODE | KEY_RELEASE);
+ if (keycode & SHIFT)
+ kbd_put_keycode(SHIFT_CODE | KEY_RELEASE);
+ } else {
+ keysym = curses2keysym[chr];
+ if (keysym == -1)
+ keysym = chr;
+
+ kbd_put_keysym(keysym);
+ }
+ }
+}
+
+static void curses_cleanup(void *opaque)
+{
+ endwin();
+}
+
+static void curses_atexit(void)
+{
+ curses_cleanup(NULL);
+}
+
+static void curses_setup(void)
+{
+ int i, colour_default[8] = {
+ COLOR_BLACK, COLOR_BLUE, COLOR_GREEN, COLOR_CYAN,
+ COLOR_RED, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE,
+ };
+
+ /* input as raw as possible, let everything be interpreted
+ * by the guest system */
+ initscr(); noecho(); intrflush(stdscr, FALSE);
+ nodelay(stdscr, TRUE); nonl(); keypad(stdscr, TRUE);
+ start_color(); raw(); scrollok(stdscr, FALSE);
+
+ for (i = 0; i < 64; i ++)
+ init_pair(i, colour_default[i & 7], colour_default[i >> 3]);
+}
+
+static void curses_keyboard_setup(void)
+{
+ int i, keycode, keysym;
+
+#if defined(__APPLE__)
+ /* always use generic keymaps */
+ if (!keyboard_layout)
+ keyboard_layout = "en-us";
+#endif
+ if(keyboard_layout) {
+ kbd_layout = init_keyboard_layout(keyboard_layout);
+ if (!kbd_layout)
+ exit(1);
+ }
+
+ for (i = 0; i < CURSES_KEYS; i ++)
+ keycode2keysym[i] = -1;
+
+ for (i = 0; i < CURSES_KEYS; i ++) {
+ if (curses2keycode[i] == -1)
+ continue;
+
+ keycode = curses2keycode[i] & KEY_MASK;
+ if (keycode2keysym[keycode] >= 0)
+ continue;
+
+ for (keysym = 0; keysym < CURSES_KEYS; keysym ++)
+ if (curses2keycode[keysym] == keycode) {
+ keycode2keysym[keycode] = keysym;
+ break;
+ }
+
+ if (keysym >= CURSES_KEYS)
+ keycode2keysym[keycode] = i;
+ }
+}
+
+void curses_display_init(DisplayState *ds, int full_screen)
+{
+#ifndef _WIN32
+ if (!isatty(1)) {
+ fprintf(stderr, "We need a terminal output\n");
+ exit(1);
+ }
+#endif
+
+ curses_setup();
+ curses_keyboard_setup();
+ atexit(curses_atexit);
+
+#ifndef _WIN32
+ signal(SIGINT, SIG_DFL);
+ signal(SIGQUIT, SIG_DFL);
+#ifdef SIGWINCH
+ /* some curses implementations provide a handler, but we
+ * want to be sure this is handled regardless of the library */
+ signal(SIGWINCH, curses_winch_handler);
+#endif
+#endif
+
+ ds->data = screen;
+ ds->linesize = 0;
+ ds->depth = 0;
+ ds->width = 640;
+ ds->height = 400;
+ ds->dpy_update = curses_update;
+ ds->dpy_resize = curses_resize;
+ ds->dpy_refresh = curses_refresh;
+ ds->dpy_text_cursor = curses_cursor_position;
+
+ invalidate = 1;
+
+ /* Standard VGA initial text mode dimensions */
+ curses_resize(ds, 80, 25);
+}
diff --git a/curses_keys.h b/curses_keys.h
new file mode 100644
index 0000000..613e5f6
--- /dev/null
+++ b/curses_keys.h
@@ -0,0 +1,484 @@
+/*
+ * Keycode and keysyms conversion tables for curses
+ *
+ * Copyright (c) 2005 Andrzej Zaborowski <balrog@zabor.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#define KEY_RELEASE 0x80
+#define KEY_MASK 0x7f
+#define SHIFT_CODE 0x2a
+#define SHIFT 0x0080
+#define GREY_CODE 0xe0
+#define GREY 0x0100
+#define CNTRL_CODE 0x1d
+#define CNTRL 0x0200
+#define ALT_CODE 0x38
+#define ALT 0x0400
+
+/* curses won't detect a Control + Alt + 1, so use Alt + 1 */
+#define QEMU_KEY_CONSOLE0 (2 | ALT) /* (curses2keycode['1'] | ALT) */
+
+#define CURSES_KEYS KEY_MAX /* KEY_MAX defined in <curses.h> */
+
+int curses2keycode[CURSES_KEYS] = {
+ [0 ... (CURSES_KEYS - 1)] = -1,
+
+ [0x01b] = 1, /* Escape */
+ ['1'] = 2,
+ ['2'] = 3,
+ ['3'] = 4,
+ ['4'] = 5,
+ ['5'] = 6,
+ ['6'] = 7,
+ ['7'] = 8,
+ ['8'] = 9,
+ ['9'] = 10,
+ ['0'] = 11,
+ ['-'] = 12,
+ ['='] = 13,
+ [0x07f] = 14, /* Backspace */
+ [0x107] = 14, /* Backspace */
+
+ ['\t'] = 15, /* Tab */
+ ['q'] = 16,
+ ['w'] = 17,
+ ['e'] = 18,
+ ['r'] = 19,
+ ['t'] = 20,
+ ['y'] = 21,
+ ['u'] = 22,
+ ['i'] = 23,
+ ['o'] = 24,
+ ['p'] = 25,
+ ['['] = 26,
+ [']'] = 27,
+ ['\n'] = 28, /* Return */
+ ['\r'] = 28, /* Return */
+ [0x157] = 28, /* Return */
+
+ ['a'] = 30,
+ ['s'] = 31,
+ ['d'] = 32,
+ ['f'] = 33,
+ ['g'] = 34,
+ ['h'] = 35,
+ ['j'] = 36,
+ ['k'] = 37,
+ ['l'] = 38,
+ [';'] = 39,
+ ['\''] = 40, /* Single quote */
+ ['`'] = 41,
+ ['\\'] = 43, /* Backslash */
+
+ ['z'] = 44,
+ ['x'] = 45,
+ ['c'] = 46,
+ ['v'] = 47,
+ ['b'] = 48,
+ ['n'] = 49,
+ ['m'] = 50,
+ [','] = 51,
+ ['.'] = 52,
+ ['/'] = 53,
+
+ [' '] = 57,
+
+ [0x109] = 59, /* Function Key 1 */
+ [0x10a] = 60, /* Function Key 2 */
+ [0x10b] = 61, /* Function Key 3 */
+ [0x10c] = 62, /* Function Key 4 */
+ [0x10d] = 63, /* Function Key 5 */
+ [0x10e] = 64, /* Function Key 6 */
+ [0x10f] = 65, /* Function Key 7 */
+ [0x110] = 66, /* Function Key 8 */
+ [0x111] = 67, /* Function Key 9 */
+ [0x112] = 68, /* Function Key 10 */
+ [0x113] = 87, /* Function Key 11 */
+ [0x114] = 88, /* Function Key 12 */
+
+ [0x106] = 71 | GREY, /* Home */
+ [0x103] = 72 | GREY, /* Up Arrow */
+ [0x153] = 73 | GREY, /* Page Up */
+ [0x104] = 75 | GREY, /* Left Arrow */
+ [0x105] = 77 | GREY, /* Right Arrow */
+ [0x168] = 79 | GREY, /* End */
+ [0x102] = 80 | GREY, /* Down Arrow */
+ [0x152] = 81 | GREY, /* Page Down */
+ [0x14b] = 82 | GREY, /* Insert */
+ [0x14a] = 83 | GREY, /* Delete */
+
+ ['!'] = 2 | SHIFT,
+ ['@'] = 3 | SHIFT,
+ ['#'] = 4 | SHIFT,
+ ['$'] = 5 | SHIFT,
+ ['%'] = 6 | SHIFT,
+ ['^'] = 7 | SHIFT,
+ ['&'] = 8 | SHIFT,
+ ['*'] = 9 | SHIFT,
+ ['('] = 10 | SHIFT,
+ [')'] = 11 | SHIFT,
+ ['_'] = 12 | SHIFT,
+ ['+'] = 13 | SHIFT,
+
+ [0x161] = 15 | SHIFT, /* Shift + Tab */
+ ['Q'] = 16 | SHIFT,
+ ['W'] = 17 | SHIFT,
+ ['E'] = 18 | SHIFT,
+ ['R'] = 19 | SHIFT,
+ ['T'] = 20 | SHIFT,
+ ['Y'] = 21 | SHIFT,
+ ['U'] = 22 | SHIFT,
+ ['I'] = 23 | SHIFT,
+ ['O'] = 24 | SHIFT,
+ ['P'] = 25 | SHIFT,
+ ['{'] = 26 | SHIFT,
+ ['}'] = 27 | SHIFT,
+
+ ['A'] = 30 | SHIFT,
+ ['S'] = 31 | SHIFT,
+ ['D'] = 32 | SHIFT,
+ ['F'] = 33 | SHIFT,
+ ['G'] = 34 | SHIFT,
+ ['H'] = 35 | SHIFT,
+ ['J'] = 36 | SHIFT,
+ ['K'] = 37 | SHIFT,
+ ['L'] = 38 | SHIFT,
+ [':'] = 39 | SHIFT,
+ ['"'] = 40 | SHIFT,
+ ['~'] = 41 | SHIFT,
+ ['|'] = 43 | SHIFT,
+
+ ['Z'] = 44 | SHIFT,
+ ['X'] = 45 | SHIFT,
+ ['C'] = 46 | SHIFT,
+ ['V'] = 47 | SHIFT,
+ ['B'] = 48 | SHIFT,
+ ['N'] = 49 | SHIFT,
+ ['M'] = 50 | SHIFT,
+ ['<'] = 51 | SHIFT,
+ ['>'] = 52 | SHIFT,
+ ['?'] = 53 | SHIFT,
+
+ [0x115] = 59 | SHIFT, /* Shift + Function Key 1 */
+ [0x116] = 60 | SHIFT, /* Shift + Function Key 2 */
+ [0x117] = 61 | SHIFT, /* Shift + Function Key 3 */
+ [0x118] = 62 | SHIFT, /* Shift + Function Key 4 */
+ [0x119] = 63 | SHIFT, /* Shift + Function Key 5 */
+ [0x11a] = 64 | SHIFT, /* Shift + Function Key 6 */
+ [0x11b] = 65 | SHIFT, /* Shift + Function Key 7 */
+ [0x11c] = 66 | SHIFT, /* Shift + Function Key 8 */
+
+ [0x011] = 16 | CNTRL, /* Control + q */
+ [0x017] = 17 | CNTRL, /* Control + w */
+ [0x005] = 18 | CNTRL, /* Control + e */
+ [0x012] = 19 | CNTRL, /* Control + r */
+ [0x014] = 20 | CNTRL, /* Control + t */
+ [0x019] = 21 | CNTRL, /* Control + y */
+ [0x015] = 22 | CNTRL, /* Control + u */
+ [0x009] = 23 | CNTRL, /* Control + i */
+ [0x00f] = 24 | CNTRL, /* Control + o */
+ [0x010] = 25 | CNTRL, /* Control + p */
+
+ [0x001] = 30 | CNTRL, /* Control + a */
+ [0x013] = 31 | CNTRL, /* Control + s */
+ [0x014] = 32 | CNTRL, /* Control + d */
+ [0x006] = 33 | CNTRL, /* Control + f */
+ [0x007] = 34 | CNTRL, /* Control + g */
+ [0x008] = 35 | CNTRL, /* Control + h */
+ [0x00a] = 36 | CNTRL, /* Control + j */
+ [0x00b] = 37 | CNTRL, /* Control + k */
+ [0x00c] = 38 | CNTRL, /* Control + l */
+
+ [0x01a] = 44 | CNTRL, /* Control + z */
+ [0x018] = 45 | CNTRL, /* Control + x */
+ [0x003] = 46 | CNTRL, /* Control + c */
+ [0x016] = 47 | CNTRL, /* Control + v */
+ [0x002] = 48 | CNTRL, /* Control + b */
+ [0x00e] = 49 | CNTRL, /* Control + n */
+ /* Control + m collides with the keycode for Enter */
+
+};
+
+int curses2keysym[CURSES_KEYS] = {
+ [0 ... (CURSES_KEYS - 1)] = -1,
+
+ ['\n'] = '\n',
+ ['\r'] = '\n',
+
+ [0x07f] = QEMU_KEY_BACKSPACE,
+
+ [0x102] = QEMU_KEY_DOWN,
+ [0x103] = QEMU_KEY_UP,
+ [0x104] = QEMU_KEY_LEFT,
+ [0x105] = QEMU_KEY_RIGHT,
+ [0x106] = QEMU_KEY_HOME,
+ [0x107] = QEMU_KEY_BACKSPACE,
+
+ [0x14a] = QEMU_KEY_DELETE,
+ [0x152] = QEMU_KEY_PAGEDOWN,
+ [0x153] = QEMU_KEY_PAGEUP,
+ [0x157] = '\n',
+ [0x168] = QEMU_KEY_END,
+
+};
+
+typedef struct {
+ const char* name;
+ int keysym;
+} name2keysym_t;
+
+static name2keysym_t name2keysym[] = {
+ /* Plain ASCII */
+ { "space", 0x020 },
+ { "exclam", 0x021 },
+ { "quotedbl", 0x022 },
+ { "numbersign", 0x023 },
+ { "dollar", 0x024 },
+ { "percent", 0x025 },
+ { "ampersand", 0x026 },
+ { "apostrophe", 0x027 },
+ { "parenleft", 0x028 },
+ { "parenright", 0x029 },
+ { "asterisk", 0x02a },
+ { "plus", 0x02b },
+ { "comma", 0x02c },
+ { "minus", 0x02d },
+ { "period", 0x02e },
+ { "slash", 0x02f },
+ { "0", 0x030 },
+ { "1", 0x031 },
+ { "2", 0x032 },
+ { "3", 0x033 },
+ { "4", 0x034 },
+ { "5", 0x035 },
+ { "6", 0x036 },
+ { "7", 0x037 },
+ { "8", 0x038 },
+ { "9", 0x039 },
+ { "colon", 0x03a },
+ { "semicolon", 0x03b },
+ { "less", 0x03c },
+ { "equal", 0x03d },
+ { "greater", 0x03e },
+ { "question", 0x03f },
+ { "at", 0x040 },
+ { "A", 0x041 },
+ { "B", 0x042 },
+ { "C", 0x043 },
+ { "D", 0x044 },
+ { "E", 0x045 },
+ { "F", 0x046 },
+ { "G", 0x047 },
+ { "H", 0x048 },
+ { "I", 0x049 },
+ { "J", 0x04a },
+ { "K", 0x04b },
+ { "L", 0x04c },
+ { "M", 0x04d },
+ { "N", 0x04e },
+ { "O", 0x04f },
+ { "P", 0x050 },
+ { "Q", 0x051 },
+ { "R", 0x052 },
+ { "S", 0x053 },
+ { "T", 0x054 },
+ { "U", 0x055 },
+ { "V", 0x056 },
+ { "W", 0x057 },
+ { "X", 0x058 },
+ { "Y", 0x059 },
+ { "Z", 0x05a },
+ { "bracketleft", 0x05b },
+ { "backslash", 0x05c },
+ { "bracketright", 0x05d },
+ { "asciicircum", 0x05e },
+ { "underscore", 0x05f },
+ { "grave", 0x060 },
+ { "a", 0x061 },
+ { "b", 0x062 },
+ { "c", 0x063 },
+ { "d", 0x064 },
+ { "e", 0x065 },
+ { "f", 0x066 },
+ { "g", 0x067 },
+ { "h", 0x068 },
+ { "i", 0x069 },
+ { "j", 0x06a },
+ { "k", 0x06b },
+ { "l", 0x06c },
+ { "m", 0x06d },
+ { "n", 0x06e },
+ { "o", 0x06f },
+ { "p", 0x070 },
+ { "q", 0x071 },
+ { "r", 0x072 },
+ { "s", 0x073 },
+ { "t", 0x074 },
+ { "u", 0x075 },
+ { "v", 0x076 },
+ { "w", 0x077 },
+ { "x", 0x078 },
+ { "y", 0x079 },
+ { "z", 0x07a },
+ { "braceleft", 0x07b },
+ { "bar", 0x07c },
+ { "braceright", 0x07d },
+ { "asciitilde", 0x07e },
+
+ /* Latin-1 extensions */
+ { "nobreakspace", 0x0a0 },
+ { "exclamdown", 0x0a1 },
+ { "cent", 0x0a2 },
+ { "sterling", 0x0a3 },
+ { "currency", 0x0a4 },
+ { "yen", 0x0a5 },
+ { "brokenbar", 0x0a6 },
+ { "section", 0x0a7 },
+ { "diaeresis", 0x0a8 },
+ { "copyright", 0x0a9 },
+ { "ordfeminine", 0x0aa },
+ { "guillemotleft", 0x0ab },
+ { "notsign", 0x0ac },
+ { "hyphen", 0x0ad },
+ { "registered", 0x0ae },
+ { "macron", 0x0af },
+ { "degree", 0x0b0 },
+ { "plusminus", 0x0b1 },
+ { "twosuperior", 0x0b2 },
+ { "threesuperior", 0x0b3 },
+ { "acute", 0x0b4 },
+ { "mu", 0x0b5 },
+ { "paragraph", 0x0b6 },
+ { "periodcentered", 0x0b7 },
+ { "cedilla", 0x0b8 },
+ { "onesuperior", 0x0b9 },
+ { "masculine", 0x0ba },
+ { "guillemotright", 0x0bb },
+ { "onequarter", 0x0bc },
+ { "onehalf", 0x0bd },
+ { "threequarters", 0x0be },
+ { "questiondown", 0x0bf },
+ { "Agrave", 0x0c0 },
+ { "Aacute", 0x0c1 },
+ { "Acircumflex", 0x0c2 },
+ { "Atilde", 0x0c3 },
+ { "Adiaeresis", 0x0c4 },
+ { "Aring", 0x0c5 },
+ { "AE", 0x0c6 },
+ { "Ccedilla", 0x0c7 },
+ { "Egrave", 0x0c8 },
+ { "Eacute", 0x0c9 },
+ { "Ecircumflex", 0x0ca },
+ { "Ediaeresis", 0x0cb },
+ { "Igrave", 0x0cc },
+ { "Iacute", 0x0cd },
+ { "Icircumflex", 0x0ce },
+ { "Idiaeresis", 0x0cf },
+ { "ETH", 0x0d0 },
+ { "Eth", 0x0d0 },
+ { "Ntilde", 0x0d1 },
+ { "Ograve", 0x0d2 },
+ { "Oacute", 0x0d3 },
+ { "Ocircumflex", 0x0d4 },
+ { "Otilde", 0x0d5 },
+ { "Odiaeresis", 0x0d6 },
+ { "multiply", 0x0d7 },
+ { "Ooblique", 0x0d8 },
+ { "Oslash", 0x0d8 },
+ { "Ugrave", 0x0d9 },
+ { "Uacute", 0x0da },
+ { "Ucircumflex", 0x0db },
+ { "Udiaeresis", 0x0dc },
+ { "Yacute", 0x0dd },
+ { "THORN", 0x0de },
+ { "Thorn", 0x0de },
+ { "ssharp", 0x0df },
+ { "agrave", 0x0e0 },
+ { "aacute", 0x0e1 },
+ { "acircumflex", 0x0e2 },
+ { "atilde", 0x0e3 },
+ { "adiaeresis", 0x0e4 },
+ { "aring", 0x0e5 },
+ { "ae", 0x0e6 },
+ { "ccedilla", 0x0e7 },
+ { "egrave", 0x0e8 },
+ { "eacute", 0x0e9 },
+ { "ecircumflex", 0x0ea },
+ { "ediaeresis", 0x0eb },
+ { "igrave", 0x0ec },
+ { "iacute", 0x0ed },
+ { "icircumflex", 0x0ee },
+ { "idiaeresis", 0x0ef },
+ { "eth", 0x0f0 },
+ { "ntilde", 0x0f1 },
+ { "ograve", 0x0f2 },
+ { "oacute", 0x0f3 },
+ { "ocircumflex", 0x0f4 },
+ { "otilde", 0x0f5 },
+ { "odiaeresis", 0x0f6 },
+ { "division", 0x0f7 },
+ { "oslash", 0x0f8 },
+ { "ooblique", 0x0f8 },
+ { "ugrave", 0x0f9 },
+ { "uacute", 0x0fa },
+ { "ucircumflex", 0x0fb },
+ { "udiaeresis", 0x0fc },
+ { "yacute", 0x0fd },
+ { "thorn", 0x0fe },
+ { "ydiaeresis", 0x0ff },
+
+ /* Special keys */
+ { "BackSpace", 0x07f },
+ { "Tab", '\t' },
+ { "Return", '\r' },
+ { "Right", 0x105 },
+ { "Left", 0x104 },
+ { "Up", 0x103 },
+ { "Down", 0x102 },
+ { "Page_Down", 0x152 },
+ { "Page_Up", 0x153 },
+ { "Insert", 0x14b },
+ { "Delete", 0x14a },
+ { "Home", 0x106 },
+ { "End", 0x168 },
+ { "F1", 0x109 },
+ { "F2", 0x10a },
+ { "F3", 0x10b },
+ { "F4", 0x10c },
+ { "F5", 0x10d },
+ { "F6", 0x10e },
+ { "F7", 0x10f },
+ { "F8", 0x110 },
+ { "F9", 0x111 },
+ { "F10", 0x112 },
+ { "F11", 0x113 },
+ { "F12", 0x114 },
+ { "F13", 0x115 },
+ { "F14", 0x116 },
+ { "F15", 0x117 },
+ { "F16", 0x118 },
+ { "F17", 0x119 },
+ { "F18", 0x11a },
+ { "F19", 0x11b },
+ { "F20", 0x11c },
+ { "Escape", 27 },
+
+ { 0, 0 },
+};
diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index 59bfdff..07e52b0 100644
--- a/hw/cirrus_vga.c
+++ b/hw/cirrus_vga.c
@@ -3257,7 +3257,8 @@ void pci_cirrus_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base,
ds, vga_ram_base, vga_ram_offset, vga_ram_size);
cirrus_init_common(s, device_id, 1);
- graphic_console_init(s->ds, s->update, s->invalidate, s->screen_dump, s);
+ graphic_console_init(s->ds, s->update, s->invalidate, s->screen_dump,
+ s->text_update, s);
s->pci_dev = (PCIDevice *)d;
diff --git a/hw/jazz_led.c b/hw/jazz_led.c
index a0eea26..d547138 100644
--- a/hw/jazz_led.c
+++ b/hw/jazz_led.c
@@ -285,6 +285,22 @@ static void jazz_led_screen_dump(void *opaque, const char *filename)
printf("jazz_led_screen_dump() not implemented\n");
}
+static void jazz_led_text_update(void *opaque, console_ch_t *chardata)
+{
+ LedState *s = opaque;
+ char buf[2];
+
+ dpy_cursor(s->ds, -1, -1);
+ dpy_resize(s->ds, 2, 1);
+
+ /* TODO: draw the segments */
+ snprintf(buf, 2, "%02hhx\n", s->segments);
+ console_write_ch(chardata++, 0x00200100 | buf[0]);
+ console_write_ch(chardata++, 0x00200100 | buf[1]);
+
+ dpy_update(s->ds, 0, 0, 2, 1);
+}
+
void jazz_led_init(DisplayState *ds, target_phys_addr_t base)
{
LedState *s;
@@ -301,5 +317,7 @@ void jazz_led_init(DisplayState *ds, target_phys_addr_t base)
io = cpu_register_io_memory(0, led_read, led_write, s);
cpu_register_physical_memory(s->base, 1, io);
- graphic_console_init(ds, jazz_led_update_display, jazz_led_invalidate_display, jazz_led_screen_dump, s);
+ graphic_console_init(ds, jazz_led_update_display,
+ jazz_led_invalidate_display, jazz_led_screen_dump,
+ jazz_led_text_update, s);
}
diff --git a/hw/omap_lcdc.c b/hw/omap_lcdc.c
index c79d244..42174f7 100644
--- a/hw/omap_lcdc.c
+++ b/hw/omap_lcdc.c
@@ -495,7 +495,7 @@ struct omap_lcd_panel_s *omap_lcdc_init(target_phys_addr_t base, qemu_irq irq,
cpu_register_physical_memory(s->base, 0x100, iomemtype);
graphic_console_init(ds, omap_update_display,
- omap_invalidate_display, omap_screen_dump, s);
+ omap_invalidate_display, omap_screen_dump, NULL, s);
return s;
}
diff --git a/hw/pl110.c b/hw/pl110.c
index e5b2b23..7f45085 100644
--- a/hw/pl110.c
+++ b/hw/pl110.c
@@ -426,7 +426,7 @@ void *pl110_init(DisplayState *ds, uint32_t base, qemu_irq irq,
s->versatile = versatile;
s->irq = irq;
graphic_console_init(ds, pl110_update_display, pl110_invalidate_display,
- NULL, s);
+ NULL, NULL, s);
/* ??? Save/restore. */
return s;
}
diff --git a/hw/pxa2xx_lcd.c b/hw/pxa2xx_lcd.c
index 5855435..7203a3f 100644
--- a/hw/pxa2xx_lcd.c
+++ b/hw/pxa2xx_lcd.c
@@ -1002,7 +1002,7 @@ struct pxa2xx_lcdc_s *pxa2xx_lcdc_init(target_phys_addr_t base, qemu_irq irq,
cpu_register_physical_memory(base, 0x00100000, iomemtype);
graphic_console_init(ds, pxa2xx_update_display,
- pxa2xx_invalidate_display, pxa2xx_screen_dump, s);
+ pxa2xx_invalidate_display, pxa2xx_screen_dump, NULL, s);
switch (s->ds->depth) {
case 0:
diff --git a/hw/ssd0303.c b/hw/ssd0303.c
index 383a623..daa9292 100644
--- a/hw/ssd0303.c
+++ b/hw/ssd0303.c
@@ -270,6 +270,6 @@ void ssd0303_init(DisplayState *ds, i2c_bus *bus, int address)
s->i2c.recv = ssd0303_recv;
s->i2c.send = ssd0303_send;
graphic_console_init(ds, ssd0303_update_display, ssd0303_invalidate_display,
- NULL, s);
+ NULL, NULL, s);
dpy_resize(s->ds, 96 * MAGNIFY, 16 * MAGNIFY);
}
diff --git a/hw/ssd0323.c b/hw/ssd0323.c
index 4706b05..e2e619f 100644
--- a/hw/ssd0323.c
+++ b/hw/ssd0323.c
@@ -280,7 +280,7 @@ void *ssd0323_init(DisplayState *ds, qemu_irq *cmd_p)
s = (ssd0323_state *)qemu_mallocz(sizeof(ssd0323_state));
s->ds = ds;
graphic_console_init(ds, ssd0323_update_display, ssd0323_invalidate_display,
- NULL, s);
+ NULL, NULL, s);
dpy_resize(s->ds, 128 * MAGNIFY, 64 * MAGNIFY);
s->col_end = 63;
s->row_end = 79;
diff --git a/hw/tcx.c b/hw/tcx.c
index afafa2a..f6d3d4c 100644
--- a/hw/tcx.c
+++ b/hw/tcx.c
@@ -537,12 +537,13 @@ void tcx_init(DisplayState *ds, target_phys_addr_t addr, uint8_t *vram_base,
s->cplane_offset = vram_offset;
cpu_register_physical_memory(addr + 0x0a000000ULL, size, vram_offset);
graphic_console_init(s->ds, tcx24_update_display,
- tcx24_invalidate_display, tcx24_screen_dump, s);
+ tcx24_invalidate_display,
+ tcx24_screen_dump, NULL, s);
} else {
cpu_register_physical_memory(addr + 0x00300000ULL, TCX_THC_NREGS_8,
dummy_memory);
graphic_console_init(s->ds, tcx_update_display, tcx_invalidate_display,
- tcx_screen_dump, s);
+ tcx_screen_dump, NULL, s);
}
// NetBSD writes here even with 8-bit display
cpu_register_physical_memory(addr + 0x00301000ULL, TCX_THC_NREGS_24,
diff --git a/hw/vga.c b/hw/vga.c
index 70b7c6d..99a3173 100644
--- a/hw/vga.c
+++ b/hw/vga.c
@@ -1660,6 +1660,165 @@ static void vga_reset(VGAState *s)
s->graphic_mode = -1; /* force full update */
}
+#define TEXTMODE_X(x) ((x) % width)
+#define TEXTMODE_Y(x) ((x) / width)
+#define VMEM2CHTYPE(v) ((v & 0xff0007ff) | \
+ ((v & 0x00000800) << 10) | ((v & 0x00007000) >> 1))
+/* relay text rendering to the display driver
+ * instead of doing a full vga_update_display() */
+static void vga_update_text(void *opaque, console_ch_t *chardata)
+{
+ VGAState *s = (VGAState *) opaque;
+ int graphic_mode, i, cursor_offset, cursor_visible;
+ int cw, cheight, width, height, size, c_min, c_max;
+ uint32_t *src;
+ console_ch_t *dst, val;
+ char msg_buffer[80];
+ int full_update;
+ full_update = 0;
+
+ if (!(s->ar_index & 0x20)) {
+ graphic_mode = GMODE_BLANK;
+ } else {
+ graphic_mode = s->gr[6] & 1;
+ }
+ if (graphic_mode != s->graphic_mode) {
+ s->graphic_mode = graphic_mode;
+ full_update = 1;
+ }
+ if (s->last_width == -1) {
+ s->last_width = 0;
+ full_update = 1;
+ }
+
+ switch (graphic_mode) {
+ case GMODE_TEXT:
+ /* TODO: update palette */
+ full_update |= update_basic_params(s);
+
+ /* total width & height */
+ cheight = (s->cr[9] & 0x1f) + 1;
+ cw = 8;
+ if (!(s->sr[1] & 0x01))
+ cw = 9;
+ if (s->sr[1] & 0x08)
+ cw = 16; /* NOTE: no 18 pixel wide */
+ width = (s->cr[0x01] + 1);
+ if (s->cr[0x06] == 100) {
+ /* ugly hack for CGA 160x100x16 - explain me the logic */
+ height = 100;
+ } else {
+ height = s->cr[0x12] |
+ ((s->cr[0x07] & 0x02) << 7) |
+ ((s->cr[0x07] & 0x40) << 3);
+ height = (height + 1) / cheight;
+ }
+
+ size = (height * width);
+ if (size > CH_ATTR_SIZE) {
+ if (!full_update)
+ return;
+
+ sprintf(msg_buffer, "%i x %i Text mode", width, height);
+ break;
+ }
+
+ if (width != s->last_width || height != s->last_height ||
+ cw != s->last_cw || cheight != s->last_ch) {
+ s->last_scr_width = width * cw;
+ s->last_scr_height = height * cheight;
+ dpy_resize(s->ds, width, height);
+ s->last_width = width;
+ s->last_height = height;
+ s->last_ch = cheight;
+ s->last_cw = cw;
+ full_update = 1;
+ }
+
+ /* Update "hardware" cursor */
+ cursor_offset = ((s->cr[0x0e] << 8) | s->cr[0x0f]) - s->start_addr;
+ if (cursor_offset != s->cursor_offset ||
+ s->cr[0xa] != s->cursor_start ||
+ s->cr[0xb] != s->cursor_end || full_update) {
+ cursor_visible = !(s->cr[0xa] & 0x20);
+ if (cursor_visible && cursor_offset < size && cursor_offset >= 0)
+ dpy_cursor(s->ds,
+ TEXTMODE_X(cursor_offset),
+ TEXTMODE_Y(cursor_offset));
+ else
+ dpy_cursor(s->ds, -1, -1);
+ s->cursor_offset = cursor_offset;
+ s->cursor_start = s->cr[0xa];
+ s->cursor_end = s->cr[0xb];
+ }
+
+ src = (uint32_t *) s->vram_ptr + s->start_addr;
+ dst = chardata;
+
+ if (full_update) {
+ for (i = 0; i < size; src ++, dst ++, i ++)
+ console_write_ch(dst, VMEM2CHTYPE(*src));
+
+ dpy_update(s->ds, 0, 0, width, height);
+ } else {
+ c_max = 0;
+
+ for (i = 0; i < size; src ++, dst ++, i ++) {
+ console_write_ch(&val, VMEM2CHTYPE(*src));
+ if (*dst != val) {
+ *dst = val;
+ c_max = i;
+ break;
+ }
+ }
+ c_min = i;
+ for (; i < size; src ++, dst ++, i ++) {
+ console_write_ch(&val, VMEM2CHTYPE(*src));
+ if (*dst != val) {
+ *dst = val;
+ c_max = i;
+ }
+ }
+
+ if (c_min <= c_max) {
+ i = TEXTMODE_Y(c_min);
+ dpy_update(s->ds, 0, i, width, TEXTMODE_Y(c_max) - i + 1);
+ }
+ }
+
+ return;
+ case GMODE_GRAPH:
+ if (!full_update)
+ return;
+
+ s->get_resolution(s, &width, &height);
+ sprintf(msg_buffer, "%i x %i Graphic mode", width, height);
+ break;
+ case GMODE_BLANK:
+ default:
+ if (!full_update)
+ return;
+
+ sprintf(msg_buffer, "VGA Blank mode");
+ break;
+ }
+
+ /* Display a message */
+ dpy_cursor(s->ds, -1, -1);
+ dpy_resize(s->ds, 60, 3);
+
+ for (dst = chardata, i = 0; i < 60 * 3; i ++)
+ console_write_ch(dst ++, ' ');
+
+ size = strlen(msg_buffer);
+ width = (60 - size) / 2;
+ dst = chardata + 60 + width;
+ for (i = 0; i < size; i ++)
+ console_write_ch(dst ++, 0x00200100 | msg_buffer[i]);
+
+ dpy_update(s->ds, 0, 0, 60, 3);
+}
+
static CPUReadMemoryFunc *vga_mem_read[3] = {
vga_mem_readb,
vga_mem_readw,
@@ -1830,6 +1989,7 @@ void vga_common_init(VGAState *s, DisplayState *ds, uint8_t *vga_ram_base,
s->update = vga_update_display;
s->invalidate = vga_invalidate_display;
s->screen_dump = vga_screen_dump;
+ s->text_update = vga_update_text;
}
/* used by both ISA and PCI */
@@ -1971,7 +2131,8 @@ int isa_vga_init(DisplayState *ds, uint8_t *vga_ram_base,
vga_common_init(s, ds, vga_ram_base, vga_ram_offset, vga_ram_size);
vga_init(s);
- graphic_console_init(s->ds, s->update, s->invalidate, s->screen_dump, s);
+ graphic_console_init(s->ds, s->update, s->invalidate, s->screen_dump,
+ s->text_update, s);
#ifdef CONFIG_BOCHS_VBE
/* XXX: use optimized standard vga accesses */
@@ -1995,7 +2156,8 @@ int isa_vga_mm_init(DisplayState *ds, uint8_t *vga_ram_base,
vga_common_init(s, ds, vga_ram_base, vga_ram_offset, vga_ram_size);
vga_mm_init(s, vram_base, ctrl_base, it_shift);
- graphic_console_init(s->ds, s->update, s->invalidate, s->screen_dump, s);
+ graphic_console_init(s->ds, s->update, s->invalidate, s->screen_dump,
+ s->text_update, s);
#ifdef CONFIG_BOCHS_VBE
/* XXX: use optimized standard vga accesses */
@@ -2023,7 +2185,8 @@ int pci_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base,
vga_common_init(s, ds, vga_ram_base, vga_ram_offset, vga_ram_size);
vga_init(s);
- graphic_console_init(s->ds, s->update, s->invalidate, s->screen_dump, s);
+ graphic_console_init(s->ds, s->update, s->invalidate, s->screen_dump,
+ s->text_update, s);
s->pci_dev = &d->dev;
diff --git a/hw/vga_int.h b/hw/vga_int.h
index a94162d..5d11a7a 100644
--- a/hw/vga_int.h
+++ b/hw/vga_int.h
@@ -139,6 +139,7 @@
vga_hw_update_ptr update; \
vga_hw_invalidate_ptr invalidate; \
vga_hw_screen_dump_ptr screen_dump; \
+ vga_hw_text_update_ptr text_update; \
/* hardware mouse cursor support */ \
uint32_t invalidated_y_table[VGA_MAX_HEIGHT / 32]; \
void (*cursor_invalidate)(struct VGAState *s); \
diff --git a/hw/vmware_vga.c b/hw/vmware_vga.c
index 6cae25c..29e36d6 100644
--- a/hw/vmware_vga.c
+++ b/hw/vmware_vga.c
@@ -949,6 +949,14 @@ static void vmsvga_screen_dump(void *opaque, const char *filename)
}
}
+static void vmsvga_text_update(void *opaque, console_ch_t *chardata)
+{
+ struct vmsvga_state_s *s = (struct vmsvga_state_s *) opaque;
+
+ if (s->text_update)
+ s->text_update(opaque, chardata);
+}
+
#ifdef DIRECT_VRAM
static uint32_t vmsvga_vram_readb(void *opaque, target_phys_addr_t addr)
{
@@ -1114,7 +1122,8 @@ static void vmsvga_init(struct vmsvga_state_s *s, DisplayState *ds,
1, 4, vmsvga_bios_write, s);
graphic_console_init(ds, vmsvga_update_display,
- vmsvga_invalidate_display, vmsvga_screen_dump, s);
+ vmsvga_invalidate_display, vmsvga_screen_dump,
+ vmsvga_text_update, s);
#ifdef EMBED_STDVGA
vga_common_init((VGAState *) s, ds,
diff --git a/monitor.c b/monitor.c
index 0783eaf..025025b 100644
--- a/monitor.c
+++ b/monitor.c
@@ -824,6 +824,8 @@ static const KeyDef key_defs[] = {
{ 0x31, "n" },
{ 0x32, "m" },
+ { 0x37, "asterisk" },
+
{ 0x39, "spc" },
{ 0x3a, "caps_lock" },
{ 0x3b, "f1" },
diff --git a/vl.c b/vl.c
index a04edbc..70b9656 100644
--- a/vl.c
+++ b/vl.c
@@ -172,6 +172,7 @@ BlockDriverState *bs_snapshots;
int vga_ram_size;
static DisplayState display_state;
int nographic;
+int curses;
const char* keyboard_layout = NULL;
int64_t ticks_per_sec;
int ram_size;
@@ -7605,6 +7606,9 @@ static void help(int exitcode)
" (default is CL-GD5446 PCI VGA)\n"
"-no-acpi disable ACPI\n"
#endif
+#ifdef CONFIG_CURSES
+ "-curses use a curses/ncurses interface instead of SDL\n"
+#endif
"-no-reboot exit instead of rebooting\n"
"-loadvm file start right away with a saved state (loadvm in monitor)\n"
"-vnc display start a VNC server on display\n"
@@ -7709,6 +7713,7 @@ enum {
QEMU_OPTION_smp,
QEMU_OPTION_vnc,
QEMU_OPTION_no_acpi,
+ QEMU_OPTION_curses,
QEMU_OPTION_no_reboot,
QEMU_OPTION_show_cursor,
QEMU_OPTION_daemonize,
@@ -7805,6 +7810,9 @@ const QEMUOption qemu_options[] = {
{ "usbdevice", HAS_ARG, QEMU_OPTION_usbdevice },
{ "smp", HAS_ARG, QEMU_OPTION_smp },
{ "vnc", HAS_ARG, QEMU_OPTION_vnc },
+#ifdef CONFIG_CURSES
+ { "curses", 0, QEMU_OPTION_curses },
+#endif
/* temporary options */
{ "usb", 0, QEMU_OPTION_usb },
@@ -8131,6 +8139,7 @@ int main(int argc, char **argv)
#endif
snapshot = 0;
nographic = 0;
+ curses = 0;
kernel_filename = NULL;
kernel_cmdline = "";
cyls = heads = secs = 0;
@@ -8307,6 +8316,11 @@ int main(int argc, char **argv)
pstrcpy(monitor_device, sizeof(monitor_device), "stdio");
nographic = 1;
break;
+#ifdef CONFIG_CURSES
+ case QEMU_OPTION_curses:
+ curses = 1;
+ break;
+#endif
case QEMU_OPTION_portrait:
graphic_rotate = 1;
break;
@@ -8847,13 +8861,23 @@ int main(int argc, char **argv)
/* terminal init */
memset(&display_state, 0, sizeof(display_state));
if (nographic) {
+ if (curses) {
+ fprintf(stderr, "fatal: -nographic can't be used with -curses\n");
+ exit(1);
+ }
/* nearly nothing to do */
dumb_display_init(ds);
} else if (vnc_display != NULL) {
vnc_display_init(ds);
if (vnc_display_open(ds, vnc_display) < 0)
exit(1);
- } else {
+ } else
+#if defined(CONFIG_CURSES)
+ if (curses) {
+ curses_display_init(ds, full_screen);
+ } else
+#endif
+ {
#if defined(CONFIG_SDL)
sdl_display_init(ds, full_screen, no_frame);
#elif defined(CONFIG_COCOA)
diff --git a/vnc.c b/vnc.c
index 9fb8c85..dea9a39 100644
--- a/vnc.c
+++ b/vnc.c
@@ -954,6 +954,7 @@ static void do_key_event(VncState *vs, int down, uint32_t sym)
return;
}
break;
+ case 0x3a: /* CapsLock */
case 0x45: /* NumLock */
if (!down)
vs->modifiers_state[keycode] ^= 1;
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2008-01-10 16:50 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-12 16:39 [Qemu-devel] Re: qemu curses driver Blue Swirl
2005-12-12 23:19 ` andrzej zaborowski
2005-12-13 18:53 ` Blue Swirl
-- strict thread matches above, loose matches on Subject: below --
2005-12-10 8:17 [Qemu-devel] " andrzej zaborowski
2005-12-12 6:58 ` [Qemu-devel] " andrzej zaborowski
2005-12-12 10:46 ` Johannes Schindelin
2005-12-12 22:53 ` andrzej zaborowski
2008-01-10 16:50 ` andrzej zaborowski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).