From ce00884d1e1aa13e98e775982d1dbdea5407f692 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Sun, 10 Sep 2000 06:32:32 +0000 Subject: [PATCH] Updated the console screen driver. committer: mfx 968567552 +0000 --- src/c_screen.cpp | 111 ++++++++++++++++++++++++++++------------------- src/s_win32.cpp | 20 +++++++-- src/screen.h | 37 ++++++++++++++++ 3 files changed, 120 insertions(+), 48 deletions(-) diff --git a/src/c_screen.cpp b/src/c_screen.cpp index afdd2fa9..71b97d34 100644 --- a/src/c_screen.cpp +++ b/src/c_screen.cpp @@ -39,11 +39,40 @@ // **************************************************************************/ +static int do_init(screen_t *s, int fd) +{ + int fg, bg; + + if (s->init(s,fd) != 0) + return -1; + + if (s->getCols(s) < 80 || s->getCols(s) > 256) + return -1; + if (s->getRows(s) < 24) + return -1; + + fg = s->getFg(s); + bg = s->getBg(s); + if (s->isMono(s)) + fg = -1; + if (fg == (bg >> 4)) + return -1; + if (bg != BG_BLACK) + if (!s->isMono(s)) + { + /* return 0; */ /* we could emulate ANSI mono */ + return -1; + } + + return 0; +} + + static screen_t *do_construct(screen_t *s, int fd) { if (!s) return NULL; - if (s->init(s,fd) != 0) + if (do_init(s,fd) != 0) { s->destroy(s); return NULL; @@ -52,6 +81,10 @@ static screen_t *do_construct(screen_t *s, int fd) } +/************************************************************************* +// +**************************************************************************/ + static screen_t *screen = NULL; static void do_destroy(void) @@ -102,18 +135,6 @@ static int init(FILE *f, int o, int now) init_bg = cur_bg = screen->getBg(screen); if (screen->isMono(screen)) cur_fg = -1; - if (screen->getCols(screen) < 80 || screen->getCols(screen) > 256) - return CON_INIT; - if (screen->getRows(screen) < 24) - return CON_INIT; - if (cur_fg == (cur_bg >> 4)) - return CON_INIT; - if (cur_bg != BG_BLACK) - if (!screen->isMono(screen)) - { - /* return CON_ANSI_MONO; */ /* we could emulate ANSI mono */ - return CON_INIT; - } if (o == CON_SCREEN) n = CON_SCREEN; @@ -179,10 +200,10 @@ static void print0(FILE *f, const char *ss) for (pass = 0; pass < 2; pass++) { const char *s = ss; - int scroll_y = 0; - while (*s) + + for (;;) { - for ( ; *s; s++) + for (;;) { if (*s == '\n') { @@ -192,57 +213,57 @@ static void print0(FILE *f, const char *ss) else if (*s == '\r') { c_cx = 0; -#if 1 if (pass > 0 && c_cy < sy) screen->clearLine(screen,c_cy); -#endif } else break; + s++; } if (c_cx >= sx) { c_cy++; c_cx = 0; } - if (pass > 0 && pi > 0 && py != c_cy) + if (pass > 0) { - screen->putString(screen,p,px,py); - pi = 0; - } - if (c_cy >= sy) - { - int l = c_cy - sy + 1; - if (pass > 0) - c_cy -= screen->scrollUp(screen,l); - else + if (pi > 0 && py != c_cy) { - scroll_y += l; - c_cy -= l; + screen->putString(screen,p,px,py); + pi = 0; } - if (c_cy < 0) - c_cy = 0; - c_cx = 0; - } - if (*s) - { - if (pass > 0) + if (c_cy >= sy) { - if (pi == 0) - px = c_cx, py = c_cy; - p[pi++] = *s; - p[pi] = 0; + int scroll_y = c_cy - sy + 1; + screen->scrollUp(screen,scroll_y); + c_cy -= scroll_y; + if (c_cy < 0) + c_cy = 0; } - c_cx++; - s++; } + + if (!*s) + break; + + if (pass > 0) + { + if (pi == 0) + px = c_cx, py = c_cy; + p[pi++] = *s; + p[pi] = 0; + } + c_cx++; + s++; } + if (pass == 0) { c_cx = cx; - if (scroll_y > 0) + if (c_cy >= sy) { - c_cy -= screen->scrollUp(screen,scroll_y); + int scroll_y = c_cy - sy + 1; + screen->scrollUp(screen,scroll_y); + c_cy = cy - scroll_y; if (c_cy < 0) c_cy = 0; } diff --git a/src/s_win32.cpp b/src/s_win32.cpp index ef4e5cd6..58974a7b 100644 --- a/src/s_win32.cpp +++ b/src/s_win32.cpp @@ -169,6 +169,10 @@ static void getCursor(const screen_t *this, int *x, int *y) { cx = csbi.dwCursorPosition.X; cy = csbi.dwCursorPosition.Y; +#if 0 + assert(cx == this->data->cursor_x); + assert(cy == this->data->cursor_y); +#endif } #endif if (x) *x = cx; @@ -221,7 +225,7 @@ static void putString(screen_t *this, const char *s, int x, int y) /* private */ -static int cci2shape(CONSOLE_CURSOR_INFO *cci) +static int cci2shape(const CONSOLE_CURSOR_INFO *cci) { int shape = cci->dwSize & 255; if (!cci->bVisible) @@ -289,15 +293,25 @@ static int init(screen_t *this, int fd) csbi = &this->data->csbi; if (!GetConsoleScreenBufferInfo(ho, csbi)) return -1; - if (csbi->srWindow.Left != 0 || csbi->srWindow.Top != 0) - return -1; if (!GetConsoleCursorInfo(ho, &ae.cci)) return -1; if (!GetConsoleTitle(this->data->title, sizeof(this->data->title))) return -1; +#if 0 this->data->cols = csbi->srWindow.Right - csbi->srWindow.Left + 1; this->data->rows = csbi->srWindow.Bottom - csbi->srWindow.Top + 1; + if (csbi->srWindow.Left != 0 || csbi->srWindow.Top != 0) + return -1; + if (this->data->cols != csbi->dwSize.X) + return -1; +#else + this->data->cols = csbi->dwSize.X; + this->data->rows = csbi->dwSize.Y; + if (csbi->srWindow.Left != 0) + return -1; +#endif + this->data->cursor_x = csbi->dwCursorPosition.X; this->data->cursor_y = csbi->dwCursorPosition.Y; diff --git a/src/screen.h b/src/screen.h index 6bd4f6dd..29a9fd9c 100644 --- a/src/screen.h +++ b/src/screen.h @@ -100,8 +100,45 @@ screen_t *screen_win32_construct(void); void screen_show_frames(screen_t *); +/************************************************************************* +// debugging support +**************************************************************************/ + +#if 0 + +#undef LOG +#undef LOGI +#undef LOGU +#undef LOGS + +#if defined(SCREEN_DEBUG) +static void LOG(const char *format, ...) +{ + static FILE *logfile = NULL; + va_list args; + + if (!logfile) + logfile = fopen("screen.log", "wt"); + + va_start(args,format); + vfprintf(logfile,format,args); + fflush(logfile); + va_end(args); +} +# define LOGI(x) LOG(#x " %ld\n", (long)(x)) +# define LOGU(x) LOG(#x " %lu\n", (long)(x)) +# define LOGS(x) LOG(#x " %s\n", x) +#else +# define LOGI(x) +# define LOGU(x) +# define LOGS(x) #endif +#endif /* if #0 */ + + +#endif /* USE_SCREEN */ + #endif /* already included */