Updated the console screen driver.
committer: mfx <mfx> 968567552 +0000
This commit is contained in:
+66
-45
@@ -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)
|
static screen_t *do_construct(screen_t *s, int fd)
|
||||||
{
|
{
|
||||||
if (!s)
|
if (!s)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (s->init(s,fd) != 0)
|
if (do_init(s,fd) != 0)
|
||||||
{
|
{
|
||||||
s->destroy(s);
|
s->destroy(s);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -52,6 +81,10 @@ static screen_t *do_construct(screen_t *s, int fd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*************************************************************************
|
||||||
|
//
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
static screen_t *screen = NULL;
|
static screen_t *screen = NULL;
|
||||||
|
|
||||||
static void do_destroy(void)
|
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);
|
init_bg = cur_bg = screen->getBg(screen);
|
||||||
if (screen->isMono(screen))
|
if (screen->isMono(screen))
|
||||||
cur_fg = -1;
|
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)
|
if (o == CON_SCREEN)
|
||||||
n = CON_SCREEN;
|
n = CON_SCREEN;
|
||||||
@@ -179,10 +200,10 @@ static void print0(FILE *f, const char *ss)
|
|||||||
for (pass = 0; pass < 2; pass++)
|
for (pass = 0; pass < 2; pass++)
|
||||||
{
|
{
|
||||||
const char *s = ss;
|
const char *s = ss;
|
||||||
int scroll_y = 0;
|
|
||||||
while (*s)
|
for (;;)
|
||||||
{
|
{
|
||||||
for ( ; *s; s++)
|
for (;;)
|
||||||
{
|
{
|
||||||
if (*s == '\n')
|
if (*s == '\n')
|
||||||
{
|
{
|
||||||
@@ -192,57 +213,57 @@ static void print0(FILE *f, const char *ss)
|
|||||||
else if (*s == '\r')
|
else if (*s == '\r')
|
||||||
{
|
{
|
||||||
c_cx = 0;
|
c_cx = 0;
|
||||||
#if 1
|
|
||||||
if (pass > 0 && c_cy < sy)
|
if (pass > 0 && c_cy < sy)
|
||||||
screen->clearLine(screen,c_cy);
|
screen->clearLine(screen,c_cy);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
s++;
|
||||||
}
|
}
|
||||||
if (c_cx >= sx)
|
if (c_cx >= sx)
|
||||||
{
|
{
|
||||||
c_cy++;
|
c_cy++;
|
||||||
c_cx = 0;
|
c_cx = 0;
|
||||||
}
|
}
|
||||||
if (pass > 0 && pi > 0 && py != c_cy)
|
if (pass > 0)
|
||||||
{
|
{
|
||||||
screen->putString(screen,p,px,py);
|
if (pi > 0 && py != c_cy)
|
||||||
pi = 0;
|
|
||||||
}
|
|
||||||
if (c_cy >= sy)
|
|
||||||
{
|
|
||||||
int l = c_cy - sy + 1;
|
|
||||||
if (pass > 0)
|
|
||||||
c_cy -= screen->scrollUp(screen,l);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
scroll_y += l;
|
screen->putString(screen,p,px,py);
|
||||||
c_cy -= l;
|
pi = 0;
|
||||||
}
|
}
|
||||||
if (c_cy < 0)
|
if (c_cy >= sy)
|
||||||
c_cy = 0;
|
|
||||||
c_cx = 0;
|
|
||||||
}
|
|
||||||
if (*s)
|
|
||||||
{
|
|
||||||
if (pass > 0)
|
|
||||||
{
|
{
|
||||||
if (pi == 0)
|
int scroll_y = c_cy - sy + 1;
|
||||||
px = c_cx, py = c_cy;
|
screen->scrollUp(screen,scroll_y);
|
||||||
p[pi++] = *s;
|
c_cy -= scroll_y;
|
||||||
p[pi] = 0;
|
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)
|
if (pass == 0)
|
||||||
{
|
{
|
||||||
c_cx = cx;
|
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)
|
if (c_cy < 0)
|
||||||
c_cy = 0;
|
c_cy = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-3
@@ -169,6 +169,10 @@ static void getCursor(const screen_t *this, int *x, int *y)
|
|||||||
{
|
{
|
||||||
cx = csbi.dwCursorPosition.X;
|
cx = csbi.dwCursorPosition.X;
|
||||||
cy = csbi.dwCursorPosition.Y;
|
cy = csbi.dwCursorPosition.Y;
|
||||||
|
#if 0
|
||||||
|
assert(cx == this->data->cursor_x);
|
||||||
|
assert(cy == this->data->cursor_y);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (x) *x = cx;
|
if (x) *x = cx;
|
||||||
@@ -221,7 +225,7 @@ static void putString(screen_t *this, const char *s, int x, int y)
|
|||||||
|
|
||||||
|
|
||||||
/* private */
|
/* private */
|
||||||
static int cci2shape(CONSOLE_CURSOR_INFO *cci)
|
static int cci2shape(const CONSOLE_CURSOR_INFO *cci)
|
||||||
{
|
{
|
||||||
int shape = cci->dwSize & 255;
|
int shape = cci->dwSize & 255;
|
||||||
if (!cci->bVisible)
|
if (!cci->bVisible)
|
||||||
@@ -289,15 +293,25 @@ static int init(screen_t *this, int fd)
|
|||||||
csbi = &this->data->csbi;
|
csbi = &this->data->csbi;
|
||||||
if (!GetConsoleScreenBufferInfo(ho, csbi))
|
if (!GetConsoleScreenBufferInfo(ho, csbi))
|
||||||
return -1;
|
return -1;
|
||||||
if (csbi->srWindow.Left != 0 || csbi->srWindow.Top != 0)
|
|
||||||
return -1;
|
|
||||||
if (!GetConsoleCursorInfo(ho, &ae.cci))
|
if (!GetConsoleCursorInfo(ho, &ae.cci))
|
||||||
return -1;
|
return -1;
|
||||||
if (!GetConsoleTitle(this->data->title, sizeof(this->data->title)))
|
if (!GetConsoleTitle(this->data->title, sizeof(this->data->title)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
#if 0
|
||||||
this->data->cols = csbi->srWindow.Right - csbi->srWindow.Left + 1;
|
this->data->cols = csbi->srWindow.Right - csbi->srWindow.Left + 1;
|
||||||
this->data->rows = csbi->srWindow.Bottom - csbi->srWindow.Top + 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_x = csbi->dwCursorPosition.X;
|
||||||
this->data->cursor_y = csbi->dwCursorPosition.Y;
|
this->data->cursor_y = csbi->dwCursorPosition.Y;
|
||||||
|
|
||||||
|
|||||||
@@ -100,8 +100,45 @@ screen_t *screen_win32_construct(void);
|
|||||||
void screen_show_frames(screen_t *);
|
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
|
||||||
|
|
||||||
|
#endif /* if #0 */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* USE_SCREEN */
|
||||||
|
|
||||||
#endif /* already included */
|
#endif /* already included */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user