upx-clang-format -i s_djgpp2.cpp s_object.cpp s_vcsa.cpp s_win32.cpp screen.h

This commit is contained in:
Markus F.X.J. Oberhumer
2016-09-21 17:45:55 +02:00
parent 104da198d3
commit 633073803f
6 changed files with 339 additions and 727 deletions
+1
View File
@@ -129,6 +129,7 @@ else
endif endif
CLANG_FORMAT_FILES += s_djgpp2.cpp s_object.cpp s_vcsa.cpp s_win32.cpp screen.h
CLANG_FORMAT_FILES += snprintf.cpp CLANG_FORMAT_FILES += snprintf.cpp
CLANG_FORMAT_FILES += stdcxx.h stdcxx.cpp CLANG_FORMAT_FILES += stdcxx.h stdcxx.cpp
clang-format: clang-format:
+98 -225
View File
@@ -25,7 +25,6 @@
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
#include "conf.h" #include "conf.h"
#if (USE_SCREEN) && defined(__DJGPP__) #if (USE_SCREEN) && defined(__DJGPP__)
@@ -39,7 +38,6 @@
/* #define USE_SCROLLBACK 1 */ /* #define USE_SCROLLBACK 1 */
/************************************************************************* /*************************************************************************
// direct screen access // direct screen access
**************************************************************************/ **************************************************************************/
@@ -53,14 +51,13 @@
#include <sys/exceptn.h> #include <sys/exceptn.h>
#include <sys/farptr.h> #include <sys/farptr.h>
#include <sys/movedata.h> #include <sys/movedata.h>
#define dossel _go32_info_block.selector_for_linear_memory #define dossel _go32_info_block.selector_for_linear_memory
#define co80 _go32_info_block.linear_address_of_primary_screen #define co80 _go32_info_block.linear_address_of_primary_screen
#undef kbhit #undef kbhit
#define Cell upx_uint16_t #define Cell upx_uint16_t
struct screen_data_t struct screen_data_t {
{
int mode; int mode;
int cols; int cols;
int rows; int rows;
@@ -80,32 +77,22 @@ struct screen_data_t
#endif /* USE_SCROLLBACK */ #endif /* USE_SCROLLBACK */
}; };
/* atExit information */ /* atExit information */
static struct static struct { int cursor_shape; } ae = {-1};
{
int cursor_shape;
} ae = {
-1
};
#if USE_SCROLLBACK #if USE_SCROLLBACK
static __inline__ void sb_add(screen_t *this, int *val, int inc) static __inline__ void sb_add(screen_t *this, int *val, int inc) {
{
*val = (*val + inc) & (this->data->sb_size - 1); *val = (*val + inc) & (this->data->sb_size - 1);
} }
static void sb_push(screen_t *this, const Cell *line, int len) static void sb_push(screen_t *this, const Cell *line, int len) {
{ memcpy(this->data->sb_buf[this->data->sb_sp], line, len);
memcpy(this->data->sb_buf[this->data->sb_sp],line,len); sb_add(this, &this->data->sb_sp, 1);
sb_add(this,&this->data->sb_sp,1);
if (this->data->sb_sp == this->data->sb_base) if (this->data->sb_sp == this->data->sb_base)
sb_add(this, &this->data->sb_base, 1); sb_add(this, &this->data->sb_base, 1);
} }
static const Cell *sb_pop(screen_t *this) static const Cell *sb_pop(screen_t *this) {
{
if (this->data->sb_sp == this->data->sb_base) if (this->data->sb_sp == this->data->sb_base)
return NULL; return NULL;
sb_add(this, &this->data->sb_sp, -1); sb_add(this, &this->data->sb_sp, -1);
@@ -113,49 +100,28 @@ static const Cell *sb_pop(screen_t *this)
} }
#endif /* USE_SCROLLBACK */ #endif /* USE_SCROLLBACK */
static void refresh(screen_t *this) { UNUSED(this); }
static void refresh(screen_t *this) static __inline__ Cell make_cell(screen_t *this, int ch, int attr) {
{
UNUSED(this); UNUSED(this);
return (Cell)(((attr & 0xff) << 8) | (ch & 0xff));
} }
static int getMode(const screen_t *this) {
static __inline__
Cell make_cell(screen_t *this, int ch, int attr)
{
UNUSED(this);
return (Cell) (((attr & 0xff) << 8) | (ch & 0xff));
}
static int getMode(const screen_t *this)
{
UNUSED(this); UNUSED(this);
return ScreenMode(); return ScreenMode();
} }
static int getPage(const screen_t *this) {
static int getPage(const screen_t *this)
{
UNUSED(this); UNUSED(this);
return _farpeekb(dossel, 0x462); return _farpeekb(dossel, 0x462);
} }
static int getRows(const screen_t *this) { return this->data->rows; }
static int getRows(const screen_t *this) static int getCols(const screen_t *this) { return this->data->cols; }
{
return this->data->rows;
}
static int isMono(const screen_t *this) {
static int getCols(const screen_t *this)
{
return this->data->cols;
}
static int isMono(const screen_t *this)
{
if (this->data->mode == 7) if (this->data->mode == 7)
return 1; return 1;
if ((_farpeekb(dossel, 0x465) & (4 | 16)) != 0) if ((_farpeekb(dossel, 0x465) & (4 | 16)) != 0)
@@ -163,42 +129,26 @@ static int isMono(const screen_t *this)
return 0; return 0;
} }
static int getFg(const screen_t *this) { return this->data->attr & mask_fg; }
static int getFg(const screen_t *this) static int getBg(const screen_t *this) { return this->data->attr & mask_bg; }
{
return this->data->attr & mask_fg;
}
static void setFg(screen_t *this, int fg) {
static int getBg(const screen_t *this)
{
return this->data->attr & mask_bg;
}
static void setFg(screen_t *this, int fg)
{
this->data->attr = (this->data->attr & mask_bg) | (fg & mask_fg); this->data->attr = (this->data->attr & mask_bg) | (fg & mask_fg);
} }
static void setBg(screen_t *this, int bg) {
static void setBg(screen_t *this, int bg)
{
this->data->attr = (this->data->attr & mask_fg) | (bg & mask_bg); this->data->attr = (this->data->attr & mask_fg) | (bg & mask_bg);
} }
static void setCursor(screen_t *this, int x, int y) {
static void setCursor(screen_t *this, int x, int y) if (x >= 0 && y >= 0 && x < this->data->cols && y < this->data->rows) {
{ ScreenSetCursor(y, x);
if (x >= 0 && y >= 0 && x < this->data->cols && y < this->data->rows)
{
ScreenSetCursor(y,x);
this->data->cursor_x = x; this->data->cursor_x = x;
this->data->cursor_y = y; this->data->cursor_y = y;
} }
} }
/* /*
// I added ScreenGetCursor, because when upx prints something longer than // I added ScreenGetCursor, because when upx prints something longer than
// 1 line (an error message for example), the this->data->cursor_y can // 1 line (an error message for example), the this->data->cursor_y can
@@ -210,88 +160,71 @@ static void setCursor(screen_t *this, int x, int y)
// the 2 passes implementation. // the 2 passes implementation.
*/ */
static void getCursor(const screen_t *this, int *x, int *y) static void getCursor(const screen_t *this, int *x, int *y) {
{
int cx = this->data->cursor_x; int cx = this->data->cursor_x;
int cy = this->data->cursor_y; int cy = this->data->cursor_y;
#if 1 #if 1
ScreenGetCursor(&cy,&cx); ScreenGetCursor(&cy, &cx);
#endif #endif
if (x) *x = cx; if (x)
if (y) *y = cy; *x = cx;
if (y)
*y = cy;
} }
static void putCharAttr(screen_t *this, int ch, int attr, int x, int y) {
static void putCharAttr(screen_t *this, int ch, int attr, int x, int y)
{
UNUSED(this); UNUSED(this);
ScreenPutChar(ch,attr,x,y); ScreenPutChar(ch, attr, x, y);
} }
static void putChar(screen_t *this, int ch, int x, int y) {
static void putChar(screen_t *this, int ch, int x, int y) ScreenPutChar(ch, this->data->attr, x, y);
{
ScreenPutChar(ch,this->data->attr,x,y);
} }
static void putStringAttr(screen_t *this, const char *s, int attr, int x, int y) {
static void putStringAttr(screen_t *this, const char *s, int attr, int x, int y)
{
UNUSED(this); UNUSED(this);
assert((int)strlen(s) <= 256); assert((int) strlen(s) <= 256);
assert(x + (int)strlen(s) <= this->data->cols); assert(x + (int) strlen(s) <= this->data->cols);
ScreenPutString(s,attr,x,y); ScreenPutString(s, attr, x, y);
} }
static void putString(screen_t *this, const char *s, int x, int y) {
static void putString(screen_t *this, const char *s, int x, int y) assert((int) strlen(s) <= 256);
{ assert(x + (int) strlen(s) <= this->data->cols);
assert((int)strlen(s) <= 256); ScreenPutString(s, this->data->attr, x, y);
assert(x + (int)strlen(s) <= this->data->cols);
ScreenPutString(s,this->data->attr,x,y);
} }
/* private */ /* private */
static void getChar(screen_t *this, int *ch, int *attr, int x, int y) static void getChar(screen_t *this, int *ch, int *attr, int x, int y) {
{
UNUSED(this); UNUSED(this);
ScreenGetChar(ch,attr,x,y); ScreenGetChar(ch, attr, x, y);
} }
static int getCursorShape(const screen_t *this) {
static int getCursorShape(const screen_t *this)
{
UNUSED(this); UNUSED(this);
return _farpeekw(dossel, 0x460); return _farpeekw(dossel, 0x460);
} }
static void setCursorShape(screen_t *this, int shape) {
static void setCursorShape(screen_t *this, int shape)
{
__dpmi_regs r; __dpmi_regs r;
memset(&r, 0, sizeof(r)); /* just in case... */ memset(&r, 0, sizeof(r)); /* just in case... */
r.x.ax = 0x0103; r.x.ax = 0x0103;
#if 1 #if 1
if (this) if (this)
r.h.al = getMode(this); /* required for buggy BIOSes */ r.h.al = getMode(this); /* required for buggy BIOSes */
#endif #endif
r.x.cx = shape & 0x7f1f; r.x.cx = shape & 0x7f1f;
__dpmi_int(0x10, &r); __dpmi_int(0x10, &r);
} }
static int hideCursor(screen_t *this) {
static int hideCursor(screen_t *this)
{
int shape = getCursorShape(this); int shape = getCursorShape(this);
setCursorShape(this,0x2000); setCursorShape(this, 0x2000);
return shape; return shape;
} }
static int init(screen_t *this, int fd) {
static int init(screen_t *this, int fd)
{
int mode; int mode;
int cols, rows; int cols, rows;
int attr; int attr;
@@ -324,27 +257,23 @@ static int init(screen_t *this, int fd)
cols = ScreenCols(); cols = ScreenCols();
rows = ScreenRows(); rows = ScreenRows();
mode = getMode(this); mode = getMode(this);
if (mode > 0x13) if (mode > 0x13) {
{
/* assume this is some SVGA/VESA text mode */ /* assume this is some SVGA/VESA text mode */
__dpmi_regs r; __dpmi_regs r;
memset(&r,0,sizeof(r)); /* just in case... */ memset(&r, 0, sizeof(r)); /* just in case... */
r.x.ax = 0x4f03; /* VESA - get current video mode */ r.x.ax = 0x4f03; /* VESA - get current video mode */
__dpmi_int(0x10, &r); __dpmi_int(0x10, &r);
if (r.h.ah == 0) if (r.h.ah == 0)
mode = r.x.bx; mode = r.x.bx;
} } else {
else
{
if (mode != 2 && mode != 3 && mode != 7) if (mode != 2 && mode != 3 && mode != 7)
return -1; return -1;
} }
ScreenGetCursor(&this->data->cursor_y, &this->data->cursor_x); ScreenGetCursor(&this->data->cursor_y, &this->data->cursor_x);
getChar(this, NULL, &attr, this->data->cursor_x, this->data->cursor_y); getChar(this, NULL, &attr, this->data->cursor_x, this->data->cursor_y);
this->data->init_attr = attr; this->data->init_attr = attr;
if (mode != 7) if (mode != 7) {
{
/* Does it normally blink when bg has its 3rd bit set? */ /* Does it normally blink when bg has its 3rd bit set? */
int b_mask = (_farpeekb(dossel, 0x465) & 0x20) ? 0x70 : 0xf0; int b_mask = (_farpeekb(dossel, 0x465) & 0x20) ? 0x70 : 0xf0;
attr = attr & (mask_fg | b_mask); attr = attr & (mask_fg | b_mask);
@@ -354,25 +283,20 @@ static int init(screen_t *this, int fd)
this->data->rows = rows; this->data->rows = rows;
this->data->attr = attr; this->data->attr = attr;
this->data->empty_attr = attr; this->data->empty_attr = attr;
this->data->empty_cell = make_cell(this,' ',attr); this->data->empty_cell = make_cell(this, ' ', attr);
ae.cursor_shape = getCursorShape(this); ae.cursor_shape = getCursorShape(this);
return 0; return 0;
} }
static void updateLineN(screen_t *this, const void *line, int y, int len) {
static void updateLineN(screen_t *this, const void *line, int y, int len) if (y >= 0 && y < this->data->rows && len > 0 && len <= 2 * this->data->cols)
{ movedata(_my_ds(), (unsigned) line, dossel, co80 + y * this->data->cols * 2, len);
if (y >= 0 && y < this->data->rows && len > 0 && len <= 2*this->data->cols)
movedata(_my_ds(), (unsigned)line, dossel, co80+y*this->data->cols*2, len);
} }
static void clearLine(screen_t *this, int y) {
static void clearLine(screen_t *this, int y) if (y >= 0 && y < this->data->rows) {
{
if (y >= 0 && y < this->data->rows)
{
unsigned sp = co80 + y * this->data->cols * 2; unsigned sp = co80 + y * this->data->cols * 2;
Cell a = this->data->empty_cell; Cell a = this->data->empty_cell;
int i = this->data->cols; int i = this->data->cols;
@@ -385,51 +309,43 @@ static void clearLine(screen_t *this, int y)
} }
} }
static void clear(screen_t *this) {
static void clear(screen_t *this)
{
unsigned char attr = ScreenAttrib; unsigned char attr = ScreenAttrib;
ScreenAttrib = this->data->empty_attr; ScreenAttrib = this->data->empty_attr;
ScreenClear(); ScreenClear();
ScreenAttrib = attr; ScreenAttrib = attr;
} }
static int scrollUp(screen_t *this, int lines) {
static int scrollUp(screen_t *this, int lines)
{
int sr = this->data->rows; int sr = this->data->rows;
int sc = this->data->cols; int sc = this->data->cols;
int y; int y;
if (lines <= 0 || lines > sr) if (lines <= 0 || lines > sr)
return 0; return 0;
#if USE_SCROLLBACK #if USE_SCROLLBACK
/* copy to scrollback buffer */ /* copy to scrollback buffer */
for (y = 0; y < lines; y++) for (y = 0; y < lines; y++) {
{ Cell buf[sc];
Cell buf[ sc ]; movedata(dossel, co80 + y * this->data->cols * 2, _my_ds(), (unsigned) buf, sizeof(buf));
movedata(dossel, co80+y*this->data->cols*2, _my_ds(), (unsigned)buf, sizeof(buf));
sb_push(this, buf, sizeof(buf)); sb_push(this, buf, sizeof(buf));
} }
#endif #endif
/* move screen up */ /* move screen up */
if (lines < sr) if (lines < sr)
movedata(dossel, co80+lines*sc*2, dossel,co80, (sr-lines)*sc*2); movedata(dossel, co80 + lines * sc * 2, dossel, co80, (sr - lines) * sc * 2);
/* fill in blank lines at bottom */ /* fill in blank lines at bottom */
for (y = sr - lines; y < sr; y++) for (y = sr - lines; y < sr; y++)
clearLine(this,y); clearLine(this, y);
this->data->scroll_counter += lines; this->data->scroll_counter += lines;
return lines; return lines;
} }
static int scrollDown(screen_t *this, int lines) {
static int scrollDown(screen_t *this, int lines)
{
int sr = this->data->rows; int sr = this->data->rows;
int sc = this->data->cols; int sc = this->data->cols;
int y; int y;
@@ -438,26 +354,24 @@ static int scrollDown(screen_t *this, int lines)
return 0; return 0;
/* move screen down */ /* move screen down */
if (lines < sr) if (lines < sr) {
{
/* !@#% movedata can't handle overlapping regions... */ /* !@#% movedata can't handle overlapping regions... */
/* movedata(dossel,co80,dossel,co80+lines*sc*2,(sr-lines)*sc*2); */ /* movedata(dossel,co80,dossel,co80+lines*sc*2,(sr-lines)*sc*2); */
Cell buf[ (sr-lines)*sc ]; Cell buf[(sr - lines) * sc];
movedata(dossel,co80,_my_ds(),(unsigned)buf,sizeof(buf)); movedata(dossel, co80, _my_ds(), (unsigned) buf, sizeof(buf));
movedata(_my_ds(),(unsigned)buf,dossel,co80+lines*sc*2,sizeof(buf)); movedata(_my_ds(), (unsigned) buf, dossel, co80 + lines * sc * 2, sizeof(buf));
} }
/* copy top lines from scrollback buffer */ /* copy top lines from scrollback buffer */
for (y = lines; --y >= 0; ) for (y = lines; --y >= 0;) {
{
#if USE_SCROLLBACK #if USE_SCROLLBACK
const Cell *buf = sb_pop(this); const Cell *buf = sb_pop(this);
if (buf == NULL) if (buf == NULL)
clearLine(this,y); clearLine(this, y);
else else
updateLineN(this,buf,y,sc*2); updateLineN(this, buf, y, sc * 2);
#else #else
clearLine(this,y); clearLine(this, y);
#endif #endif
} }
@@ -465,22 +379,14 @@ static int scrollDown(screen_t *this, int lines)
return lines; return lines;
} }
static int getScrollCounter(const screen_t *this) { return this->data->scroll_counter; }
static int getScrollCounter(const screen_t *this) static int s_kbhit(screen_t *this) {
{
return this->data->scroll_counter;
}
static int s_kbhit(screen_t *this)
{
UNUSED(this); UNUSED(this);
return kbhit(); return kbhit();
} }
static int intro(screen_t *this, void (*show_frames)(screen_t *)) {
static int intro(screen_t *this, void (*show_frames)(screen_t *) )
{
int shape; int shape;
upx_uint16_t old_flags = __djgpp_hwint_flags; upx_uint16_t old_flags = __djgpp_hwint_flags;
@@ -493,7 +399,7 @@ static int intro(screen_t *this, void (*show_frames)(screen_t *) )
shape = hideCursor(this); shape = hideCursor(this);
show_frames(this); show_frames(this);
setCursorShape(this,shape); setCursorShape(this, shape);
while (kbhit()) while (kbhit())
(void) getkey(); (void) getkey();
@@ -502,65 +408,32 @@ static int intro(screen_t *this, void (*show_frames)(screen_t *) )
return 1; return 1;
} }
static void atExit(void) {
static void atExit(void)
{
static int done = 0; static int done = 0;
if (done) return; if (done)
return;
done = 1; done = 1;
if (ae.cursor_shape >= 0) if (ae.cursor_shape >= 0)
setCursorShape(NULL,ae.cursor_shape); setCursorShape(NULL, ae.cursor_shape);
} }
static const screen_t driver = {sobject_destroy, 0, /* finalize, */
static const screen_t driver = atExit, init, refresh,
{ getMode, getPage, getRows,
sobject_destroy, getCols, isMono, getFg,
0, /* finalize, */ getBg, getCursor, getCursorShape,
atExit, setFg, setBg, setCursor,
init, setCursorShape, hideCursor, putChar,
refresh, putCharAttr, putString, putStringAttr,
getMode, clear, clearLine, updateLineN,
getPage, scrollUp, scrollDown, getScrollCounter,
getRows, s_kbhit, intro, (struct screen_data_t *) 0};
getCols,
isMono,
getFg,
getBg,
getCursor,
getCursorShape,
setFg,
setBg,
setCursor,
setCursorShape,
hideCursor,
putChar,
putCharAttr,
putString,
putStringAttr,
clear,
clearLine,
updateLineN,
scrollUp,
scrollDown,
getScrollCounter,
s_kbhit,
intro,
(struct screen_data_t *) 0
};
/* public constructor */ /* public constructor */
screen_t *screen_djgpp2_construct(void) screen_t *screen_djgpp2_construct(void) { return sobject_construct(&driver, sizeof(*driver.data)); }
{
return sobject_construct(&driver,sizeof(*driver.data));
}
#endif /* (USE_SCREEN) && defined(__DJGPP__) */ #endif /* (USE_SCREEN) && defined(__DJGPP__) */
/* /*
vi:ts=4:et vi:ts=4:et
*/ */
+6 -20
View File
@@ -25,7 +25,6 @@
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
#include "conf.h" #include "conf.h"
#if (USE_SCREEN) #if (USE_SCREEN)
@@ -34,7 +33,6 @@
#include "screen.h" #include "screen.h"
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
@@ -42,19 +40,13 @@
// ugly hacks // ugly hacks
static screen_t *last_screen = NULL; static screen_t *last_screen = NULL;
screen_t *sobject_get_screen(void) screen_t *sobject_get_screen(void) { return last_screen; }
{
return last_screen;
}
void sobject_destroy(screen_t *this) {
void sobject_destroy(screen_t *this)
{
last_screen = NULL; last_screen = NULL;
if (!this) if (!this)
return; return;
if (this->data) if (this->data) {
{
if (this->finalize) if (this->finalize)
this->finalize(this); this->finalize(this);
free(this->data); free(this->data);
@@ -63,9 +55,7 @@ void sobject_destroy(screen_t *this)
free(this); free(this);
} }
screen_t *sobject_construct(const screen_t *c, size_t data_size) {
screen_t *sobject_construct(const screen_t *c, size_t data_size)
{
screen_t *this; screen_t *this;
last_screen = NULL; last_screen = NULL;
@@ -80,22 +70,18 @@ screen_t *sobject_construct(const screen_t *c, size_t data_size)
/* initialize instance variables */ /* initialize instance variables */
this->data = (struct screen_data_t *) malloc(data_size); this->data = (struct screen_data_t *) malloc(data_size);
if (!this->data) if (!this->data) {
{
free(this); free(this);
return NULL; return NULL;
} }
memset(this->data,0,data_size); memset(this->data, 0, data_size);
last_screen = this; last_screen = this;
return this; return this;
} }
#endif /* (USE_SCREEN) */ #endif /* (USE_SCREEN) */
/* /*
vi:ts=4:et vi:ts=4:et
*/ */
+136 -259
View File
@@ -25,7 +25,6 @@
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
#include "conf.h" #include "conf.h"
#if (USE_SCREEN) && (USE_SCREEN_VCSA) #if (USE_SCREEN) && (USE_SCREEN_VCSA)
@@ -39,7 +38,6 @@
/* #define USE_SCROLLBACK 1 */ /* #define USE_SCROLLBACK 1 */
/************************************************************************* /*************************************************************************
// direct screen access ( /dev/vcsaNN ) // direct screen access ( /dev/vcsaNN )
**************************************************************************/ **************************************************************************/
@@ -48,16 +46,14 @@
#include <sys/select.h> #include <sys/select.h>
#include <termios.h> #include <termios.h>
#if defined(__linux__) #if defined(__linux__)
# include <linux/kd.h> #include <linux/kd.h>
# include <linux/kdev_t.h> #include <linux/kdev_t.h>
# include <linux/major.h> #include <linux/major.h>
#endif #endif
#define Cell upx_uint16_t #define Cell upx_uint16_t
struct screen_data_t struct screen_data_t {
{
int fd; int fd;
int mode; int mode;
int page; int page;
@@ -79,119 +75,71 @@ struct screen_data_t
#endif /* USE_SCROLLBACK */ #endif /* USE_SCROLLBACK */
}; };
#if USE_SCROLLBACK #if USE_SCROLLBACK
static __inline__ void sb_add(screen_t *this, int *val, int inc) static __inline__ void sb_add(screen_t *this, int *val, int inc) {
{
*val = (*val + inc) & (this->data->sb_size - 1); *val = (*val + inc) & (this->data->sb_size - 1);
} }
static void sb_push(screen_t *this, const Cell *line, int len) static void sb_push(screen_t *this, const Cell *line, int len) {
{ memcpy(this->data->sb_buf[this->data->sb_sp], line, len);
memcpy(this->data->sb_buf[this->data->sb_sp],line,len); sb_add(this, &this->data->sb_sp, 1);
sb_add(this,&this->data->sb_sp,1);
if (this->data->sb_sp == this->data->sb_base) if (this->data->sb_sp == this->data->sb_base)
sb_add(this,&this->data->sb_base,1); sb_add(this, &this->data->sb_base, 1);
} }
static const Cell *sb_pop(screen_t *this) static const Cell *sb_pop(screen_t *this) {
{
if (this->data->sb_sp == this->data->sb_base) if (this->data->sb_sp == this->data->sb_base)
return NULL; return NULL;
sb_add(this,&this->data->sb_sp,-1); sb_add(this, &this->data->sb_sp, -1);
return this->data->sb_buf[this->data->sb_sp]; return this->data->sb_buf[this->data->sb_sp];
} }
#endif /* USE_SCROLLBACK */ #endif /* USE_SCROLLBACK */
static void refresh(screen_t *this) { UNUSED(this); }
static void refresh(screen_t *this) static __inline__ Cell make_cell(screen_t *this, int ch, int attr) {
{
UNUSED(this);
}
static __inline__
Cell make_cell(screen_t *this, int ch, int attr)
{
return ((attr & 0xff) << 8) | (this->data->map[ch & 0xff] & 0xff); return ((attr & 0xff) << 8) | (this->data->map[ch & 0xff] & 0xff);
} }
static int getMode(const screen_t *this) { return this->data->mode; }
static int getMode(const screen_t *this) static int getPage(const screen_t *this) { return this->data->page; }
{
return this->data->mode;
}
static int getRows(const screen_t *this) { return this->data->rows; }
static int getPage(const screen_t *this) static int getCols(const screen_t *this) { return this->data->cols; }
{
return this->data->page;
}
static int isMono(const screen_t *this) {
static int getRows(const screen_t *this)
{
return this->data->rows;
}
static int getCols(const screen_t *this)
{
return this->data->cols;
}
static int isMono(const screen_t *this)
{
/* FIXME */ /* FIXME */
UNUSED(this); UNUSED(this);
return 0; return 0;
} }
static int getFg(const screen_t *this) { return this->data->attr & mask_fg; }
static int getFg(const screen_t *this) static int getBg(const screen_t *this) { return this->data->attr & mask_bg; }
{
return this->data->attr & mask_fg;
}
static void setFg(screen_t *this, int fg) {
static int getBg(const screen_t *this)
{
return this->data->attr & mask_bg;
}
static void setFg(screen_t *this, int fg)
{
this->data->attr = (this->data->attr & mask_bg) | (fg & mask_fg); this->data->attr = (this->data->attr & mask_bg) | (fg & mask_fg);
} }
static void setBg(screen_t *this, int bg) {
static void setBg(screen_t *this, int bg)
{
this->data->attr = (this->data->attr & mask_fg) | (bg & mask_bg); this->data->attr = (this->data->attr & mask_fg) | (bg & mask_bg);
} }
/* private */ /* private */
static int gotoxy(screen_t *this, int x, int y) static int gotoxy(screen_t *this, int x, int y) {
{ if (x >= 0 && y >= 0 && x < this->data->cols && y < this->data->rows) {
if (x >= 0 && y >= 0 && x < this->data->cols && y < this->data->rows) if (lseek(this->data->fd, 4 + (x + y * this->data->cols) * 2, SEEK_SET) != -1) {
{
if (lseek(this->data->fd, 4 + (x + y * this->data->cols) * 2, SEEK_SET) != -1)
{
return 0; return 0;
} }
} }
return -1; return -1;
} }
static void setCursor(screen_t *this, int x, int y) {
static void setCursor(screen_t *this, int x, int y) if (gotoxy(this, x, y) == 0) {
{ unsigned char b[2] = {x, y};
if (gotoxy(this,x,y) == 0)
{
unsigned char b[2] = { x, y };
if (lseek(this->data->fd, 2, SEEK_SET) != -1) if (lseek(this->data->fd, 2, SEEK_SET) != -1)
write(this->data->fd, b, 2); write(this->data->fd, b, 2);
this->data->cursor_x = x; this->data->cursor_x = x;
@@ -199,67 +147,53 @@ static void setCursor(screen_t *this, int x, int y)
} }
} }
static void getCursor(const screen_t *this, int *x, int *y) {
static void getCursor(const screen_t *this, int *x, int *y)
{
int cx = this->data->cursor_x; int cx = this->data->cursor_x;
int cy = this->data->cursor_y; int cy = this->data->cursor_y;
#if 1 #if 1
if (lseek(this->data->fd, 2, SEEK_SET) != -1) if (lseek(this->data->fd, 2, SEEK_SET) != -1) {
{
unsigned char b[2]; unsigned char b[2];
if (read(this->data->fd, b, 2) == 2) if (read(this->data->fd, b, 2) == 2) {
{ if (b[0] < this->data->cols && b[1] < this->data->rows) {
if (b[0] < this->data->cols && b[1] < this->data->rows)
{
cx = b[0]; cx = b[0];
cy = b[1]; cy = b[1];
} }
} }
} }
#endif #endif
if (x) *x = cx; if (x)
if (y) *y = cy; *x = cx;
if (y)
*y = cy;
} }
static void putCharAttr(screen_t *this, int ch, int attr, int x, int y) {
Cell a = make_cell(this, ch, attr);
static void putCharAttr(screen_t *this, int ch, int attr, int x, int y) if (gotoxy(this, x, y) == 0)
{
Cell a = make_cell(this,ch,attr);
if (gotoxy(this,x,y) == 0)
write(this->data->fd, &a, 2); write(this->data->fd, &a, 2);
} }
static void putChar(screen_t *this, int ch, int x, int y) {
static void putChar(screen_t *this, int ch, int x, int y) putCharAttr(this, ch, this->data->attr, x, y);
{
putCharAttr(this,ch,this->data->attr,x,y);
} }
static void putStringAttr(screen_t *this, const char *s, int attr, int x, int y) {
static void putStringAttr(screen_t *this, const char *s, int attr, int x, int y) assert((int) strlen(s) <= 256);
{ assert(x + (int) strlen(s) <= this->data->cols);
assert((int)strlen(s) <= 256);
assert(x + (int)strlen(s) <= this->data->cols);
while (*s) while (*s)
putCharAttr(this,*s++,attr,x++,y); putCharAttr(this, *s++, attr, x++, y);
} }
static void putString(screen_t *this, const char *s, int x, int y) {
static void putString(screen_t *this, const char *s, int x, int y) putStringAttr(this, s, this->data->attr, x, y);
{
putStringAttr(this,s,this->data->attr,x,y);
} }
/* private */ /* private */
static void getChar(screen_t *this, int *ch, int *attr, int x, int y) static void getChar(screen_t *this, int *ch, int *attr, int x, int y) {
{
upx_uint16_t a; upx_uint16_t a;
if (gotoxy(this,x,y) == 0 && read(this->data->fd, &a, 2) == 2) if (gotoxy(this, x, y) == 0 && read(this->data->fd, &a, 2) == 2) {
{
if (ch) if (ch)
*ch = a & 0xff; *ch = a & 0xff;
if (attr) if (attr)
@@ -267,19 +201,15 @@ static void getChar(screen_t *this, int *ch, int *attr, int x, int y)
} }
} }
/* private */ /* private */
static int init_scrnmap(screen_t *this, int fd) static int init_scrnmap(screen_t *this, int fd) {
{
int scrnmap_done = 0; int scrnmap_done = 0;
int i; int i;
#if 1 && defined(GIO_UNISCRNMAP) && defined(E_TABSZ) #if 1 && defined(GIO_UNISCRNMAP) && defined(E_TABSZ)
if (!scrnmap_done) if (!scrnmap_done) {
{
upx_uint16_t scrnmap[E_TABSZ]; upx_uint16_t scrnmap[E_TABSZ];
if (ioctl(fd, GIO_UNISCRNMAP, scrnmap) == 0) if (ioctl(fd, GIO_UNISCRNMAP, scrnmap) == 0) {
{
for (i = 0; i < E_TABSZ; i++) for (i = 0; i < E_TABSZ; i++)
this->data->map[scrnmap[i] & 0xff] = i; this->data->map[scrnmap[i] & 0xff] = i;
scrnmap_done = 1; scrnmap_done = 1;
@@ -287,11 +217,9 @@ static int init_scrnmap(screen_t *this, int fd)
} }
#endif #endif
#if 1 && defined(GIO_SCRNMAP) && defined(E_TABSZ) #if 1 && defined(GIO_SCRNMAP) && defined(E_TABSZ)
if (!scrnmap_done) if (!scrnmap_done) {
{
unsigned char scrnmap[E_TABSZ]; unsigned char scrnmap[E_TABSZ];
if (ioctl(fd, GIO_SCRNMAP, scrnmap) == 0) if (ioctl(fd, GIO_SCRNMAP, scrnmap) == 0) {
{
for (i = 0; i < E_TABSZ; i++) for (i = 0; i < E_TABSZ; i++)
this->data->map[scrnmap[i] & 0xff] = i; this->data->map[scrnmap[i] & 0xff] = i;
scrnmap_done = 1; scrnmap_done = 1;
@@ -302,9 +230,7 @@ static int init_scrnmap(screen_t *this, int fd)
return scrnmap_done; return scrnmap_done;
} }
static int init(screen_t *this, int fd) {
static int init(screen_t *this, int fd)
{
struct stat st; struct stat st;
if (!this || !this->data) if (!this || !this->data)
@@ -320,13 +246,12 @@ static int init(screen_t *this, int fd)
#endif #endif
if (fd < 0 || !acc_isatty(fd)) if (fd < 0 || !acc_isatty(fd))
return -1; return -1;
if (fstat(fd,&st) != 0) if (fstat(fd, &st) != 0)
return -1; return -1;
/* check if we are running in a virtual console */ /* check if we are running in a virtual console */
#if defined(MINOR) && defined(MAJOR) && defined(TTY_MAJOR) #if defined(MINOR) && defined(MAJOR) && defined(TTY_MAJOR)
if (MAJOR(st.st_rdev) == TTY_MAJOR) if (MAJOR(st.st_rdev) == TTY_MAJOR) {
{
char vc_name[64]; char vc_name[64];
unsigned char vc_data[4]; unsigned char vc_data[4];
int i; int i;
@@ -335,15 +260,12 @@ static int init(screen_t *this, int fd)
upx_snprintf(vc_name, sizeof(vc_name), "/dev/vcsa%d", (int) MINOR(st.st_rdev)); upx_snprintf(vc_name, sizeof(vc_name), "/dev/vcsa%d", (int) MINOR(st.st_rdev));
this->data->fd = open(vc_name, O_RDWR); this->data->fd = open(vc_name, O_RDWR);
if (this->data->fd == -1) if (this->data->fd == -1) {
{
upx_snprintf(vc_name, sizeof(vc_name), "/dev/vcc/a%d", (int) MINOR(st.st_rdev)); upx_snprintf(vc_name, sizeof(vc_name), "/dev/vcc/a%d", (int) MINOR(st.st_rdev));
this->data->fd = open(vc_name, O_RDWR); this->data->fd = open(vc_name, O_RDWR);
} }
if (this->data->fd != -1) if (this->data->fd != -1) {
{ if (read(this->data->fd, vc_data, 4) == 4) {
if (read(this->data->fd, vc_data, 4) == 4)
{
this->data->mode = 3; this->data->mode = 3;
this->data->rows = vc_data[0]; this->data->rows = vc_data[0];
this->data->cols = vc_data[1]; this->data->cols = vc_data[1];
@@ -352,18 +274,15 @@ static int init(screen_t *this, int fd)
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
this->data->map[i] = i; this->data->map[i] = i;
i = init_scrnmap(this,this->data->fd) || i = init_scrnmap(this, this->data->fd) || init_scrnmap(this, STDIN_FILENO);
init_scrnmap(this,STDIN_FILENO);
getChar(this,NULL,&attr,this->data->cursor_x,this->data->cursor_y); getChar(this, NULL, &attr, this->data->cursor_x, this->data->cursor_y);
this->data->init_attr = attr; this->data->init_attr = attr;
this->data->attr = attr; this->data->attr = attr;
a = make_cell(this,' ',attr); a = make_cell(this, ' ', attr);
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
this->data->empty_line[i] = a; this->data->empty_line[i] = a;
} } else {
else
{
close(this->data->fd); close(this->data->fd);
this->data->fd = -1; this->data->fd = -1;
} }
@@ -377,25 +296,19 @@ static int init(screen_t *this, int fd)
return 0; return 0;
} }
static void finalize(screen_t *this) {
static void finalize(screen_t *this)
{
if (this->data->fd != -1) if (this->data->fd != -1)
(void) close(this->data->fd); (void) close(this->data->fd);
} }
static void updateLineN(screen_t *this, const void *line, int y, int len) {
static void updateLineN(screen_t *this, const void *line, int y, int len) if (len > 0 && len <= 2 * this->data->cols && gotoxy(this, 0, y) == 0) {
{
if (len > 0 && len <= 2*this->data->cols && gotoxy(this,0,y) == 0)
{
int i; int i;
unsigned char new_line[len]; unsigned char new_line[len];
unsigned char *l1 = new_line; unsigned char *l1 = new_line;
const unsigned char *l2 = (const unsigned char *) line; const unsigned char *l2 = (const unsigned char *) line;
for (i = 0; i < len; i += 2) for (i = 0; i < len; i += 2) {
{
*l1++ = *l2++; *l1++ = *l2++;
*l1++ = this->data->map[*l2++]; *l1++ = this->data->map[*l2++];
} }
@@ -403,25 +316,19 @@ static void updateLineN(screen_t *this, const void *line, int y, int len)
} }
} }
static void clearLine(screen_t *this, int y) {
static void clearLine(screen_t *this, int y) if (gotoxy(this, 0, y) == 0)
{ write(this->data->fd, this->data->empty_line, 2 * this->data->cols);
if (gotoxy(this,0,y) == 0)
write(this->data->fd, this->data->empty_line, 2*this->data->cols);
} }
static void clear(screen_t *this) {
static void clear(screen_t *this)
{
int y; int y;
for (y = 0; y < this->data->rows; y++) for (y = 0; y < this->data->rows; y++)
clearLine(this,y); clearLine(this, y);
} }
static int scrollUp(screen_t *this, int lines) {
static int scrollUp(screen_t *this, int lines)
{
int sr = this->data->rows; int sr = this->data->rows;
int sc = this->data->cols; int sc = this->data->cols;
int y; int y;
@@ -431,36 +338,32 @@ static int scrollUp(screen_t *this, int lines)
#if USE_SCROLLBACK #if USE_SCROLLBACK
/* copy to scrollback buffer */ /* copy to scrollback buffer */
for (y = 0; y < lines; y++) for (y = 0; y < lines; y++) {
{ Cell buf[sc];
Cell buf[ sc ]; gotoxy(this, 0, y);
gotoxy(this,0,y);
read(this->data->fd, buf, sizeof(buf)); read(this->data->fd, buf, sizeof(buf));
sb_push(this,buf,sizeof(buf)); sb_push(this, buf, sizeof(buf));
} }
#endif #endif
/* move screen up */ /* move screen up */
if (lines < sr) if (lines < sr) {
{ Cell buf[(sr - lines) * sc];
Cell buf[ (sr-lines)*sc ]; gotoxy(this, 0, lines);
gotoxy(this,0,lines);
read(this->data->fd, buf, sizeof(buf)); read(this->data->fd, buf, sizeof(buf));
gotoxy(this,0,0); gotoxy(this, 0, 0);
write(this->data->fd, buf, sizeof(buf)); write(this->data->fd, buf, sizeof(buf));
} }
/* fill in blank lines at bottom */ /* fill in blank lines at bottom */
for (y = sr - lines; y < sr; y++) for (y = sr - lines; y < sr; y++)
clearLine(this,y); clearLine(this, y);
this->data->scroll_counter += lines; this->data->scroll_counter += lines;
return lines; return lines;
} }
static int scrollDown(screen_t *this, int lines) {
static int scrollDown(screen_t *this, int lines)
{
int sr = this->data->rows; int sr = this->data->rows;
int sc = this->data->cols; int sc = this->data->cols;
int y; int y;
@@ -469,26 +372,24 @@ static int scrollDown(screen_t *this, int lines)
return 0; return 0;
/* move screen down */ /* move screen down */
if (lines < sr) if (lines < sr) {
{ Cell buf[(sr - lines) * sc];
Cell buf[ (sr-lines)*sc ]; gotoxy(this, 0, 0);
gotoxy(this,0,0);
read(this->data->fd, buf, sizeof(buf)); read(this->data->fd, buf, sizeof(buf));
gotoxy(this,0,lines); gotoxy(this, 0, lines);
write(this->data->fd, buf, sizeof(buf)); write(this->data->fd, buf, sizeof(buf));
} }
/* copy top lines from scrollback buffer */ /* copy top lines from scrollback buffer */
for (y = lines; --y >= 0; ) for (y = lines; --y >= 0;) {
{
#if USE_SCROLLBACK #if USE_SCROLLBACK
const Cell *buf = sb_pop(this); const Cell *buf = sb_pop(this);
if (buf == NULL) if (buf == NULL)
clearLine(this,y); clearLine(this, y);
else else
updateLineN(this,buf,y,sc*2); updateLineN(this, buf, y, sc * 2);
#else #else
clearLine(this,y); clearLine(this, y);
#endif #endif
} }
@@ -496,29 +397,19 @@ static int scrollDown(screen_t *this, int lines)
return lines; return lines;
} }
static int getScrollCounter(const screen_t *this) { return this->data->scroll_counter; }
static int getScrollCounter(const screen_t *this) static int getCursorShape(const screen_t *this) {
{
return this->data->scroll_counter;
}
static int getCursorShape(const screen_t *this)
{
UNUSED(this); UNUSED(this);
return 0; return 0;
} }
static void setCursorShape(screen_t *this, int shape) {
static void setCursorShape(screen_t *this, int shape)
{
UNUSED(this); UNUSED(this);
UNUSED(shape); UNUSED(shape);
} }
static int kbhit(screen_t *this) {
static int kbhit(screen_t *this)
{
const int fd = STDIN_FILENO; const int fd = STDIN_FILENO;
const unsigned usec = 0; const unsigned usec = 0;
struct timeval tv; struct timeval tv;
@@ -527,14 +418,12 @@ static int kbhit(screen_t *this)
UNUSED(this); UNUSED(this);
FD_ZERO(&fds); FD_ZERO(&fds);
FD_SET(fd, &fds); FD_SET(fd, &fds);
tv.tv_sec = usec / 1000000; tv.tv_sec = usec / 1000000;
tv.tv_usec = usec % 1000000; tv.tv_usec = usec % 1000000;
return (select(fd + 1, &fds, NULL, NULL, &tv) > 0); return (select(fd + 1, &fds, NULL, NULL, &tv) > 0);
} }
static int intro(screen_t *this, void (*show_frames)(screen_t *)) {
static int intro(screen_t *this, void (*show_frames)(screen_t *) )
{
int shape; int shape;
struct termios term_old, term_new; struct termios term_old, term_new;
int term_r; int term_r;
@@ -543,19 +432,18 @@ static int intro(screen_t *this, void (*show_frames)(screen_t *) )
return 0; return 0;
term_r = tcgetattr(STDIN_FILENO, &term_old); term_r = tcgetattr(STDIN_FILENO, &term_old);
if (term_r == 0) if (term_r == 0) {
{
term_new = term_old; term_new = term_old;
term_new.c_lflag &= ~(ISIG | ICANON | ECHO); term_new.c_lflag &= ~(ISIG | ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &term_new); tcsetattr(STDIN_FILENO, TCSANOW, &term_new);
} }
shape = getCursorShape(this); shape = getCursorShape(this);
setCursorShape(this,0x2000); setCursorShape(this, 0x2000);
show_frames(this); show_frames(this);
if (this->data->rows > 24) if (this->data->rows > 24)
setCursor(this,this->data->cursor_x,this->data->cursor_y+1); setCursor(this, this->data->cursor_x, this->data->cursor_y + 1);
setCursorShape(this,shape); setCursorShape(this, shape);
while (kbhit(this)) while (kbhit(this))
(void) fgetc(stdin); (void) fgetc(stdin);
@@ -565,55 +453,44 @@ static int intro(screen_t *this, void (*show_frames)(screen_t *) )
return 1; return 1;
} }
static const screen_t driver = {sobject_destroy,
static const screen_t driver = finalize,
{ 0, /* atExit */
sobject_destroy, init,
finalize, refresh,
0, /* atExit */ getMode,
init, getPage,
refresh, getRows,
getMode, getCols,
getPage, isMono,
getRows, getFg,
getCols, getBg,
isMono, getCursor,
getFg, getCursorShape,
getBg, setFg,
getCursor, setBg,
getCursorShape, setCursor,
setFg, setCursorShape,
setBg, 0, /* hideCursor */
setCursor, putChar,
setCursorShape, putCharAttr,
0, /* hideCursor */ putString,
putChar, putStringAttr,
putCharAttr, clear,
putString, clearLine,
putStringAttr, updateLineN,
clear, scrollUp,
clearLine, scrollDown,
updateLineN, getScrollCounter,
scrollUp, kbhit,
scrollDown, intro,
getScrollCounter, (struct screen_data_t *) 0};
kbhit,
intro,
(struct screen_data_t *) 0
};
/* public constructor */ /* public constructor */
screen_t *screen_vcsa_construct(void) screen_t *screen_vcsa_construct(void) { return sobject_construct(&driver, sizeof(*driver.data)); }
{
return sobject_construct(&driver,sizeof(*driver.data));
}
#endif /* (USE_SCREEN) && (USE_SCREEN_VCSA) */ #endif /* (USE_SCREEN) && (USE_SCREEN_VCSA) */
/* /*
vi:ts=4:et vi:ts=4:et
*/ */
+93 -211
View File
@@ -25,7 +25,6 @@
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
#include "conf.h" #include "conf.h"
#if (USE_SCREEN_WIN32) #if (USE_SCREEN_WIN32)
@@ -37,28 +36,25 @@
#define mask_fg 0x0f #define mask_fg 0x0f
#define mask_bg 0xf0 #define mask_bg 0xf0
/************************************************************************* /*************************************************************************
// direct screen access // direct screen access
**************************************************************************/ **************************************************************************/
#if (ACC_CC_MSC && (_MSC_VER >= 1000 && _MSC_VER < 1200)) #if (ACC_CC_MSC && (_MSC_VER >= 1000 && _MSC_VER < 1200))
/* avoid -W4 warnings in <conio.h> */ /* avoid -W4 warnings in <conio.h> */
# pragma warning(disable: 4032) #pragma warning(disable : 4032)
/* avoid -W4 warnings in <windows.h> */ /* avoid -W4 warnings in <windows.h> */
# pragma warning(disable: 4201 4214 4514) #pragma warning(disable : 4201 4214 4514)
#endif #endif
#if defined(__RSXNT__) #if defined(__RSXNT__)
# define timeval win32_timeval /* struct timeval already in <sys/time.h> */ #define timeval win32_timeval /* struct timeval already in <sys/time.h> */
#endif #endif
#include <windows.h> #include <windows.h>
#if (HAVE_CONIO_H) #if (HAVE_CONIO_H)
# include <conio.h> #include <conio.h>
#endif #endif
struct screen_data_t {
struct screen_data_t
{
HANDLE hi; HANDLE hi;
HANDLE ho; HANDLE ho;
CONSOLE_SCREEN_BUFFER_INFO csbi; CONSOLE_SCREEN_BUFFER_INFO csbi;
@@ -80,106 +76,65 @@ struct screen_data_t
CHAR_INFO empty_line[256]; CHAR_INFO empty_line[256];
}; };
#define P(x) ((SHORT)(x))
#define P(x) ((SHORT) (x)) static const COORD pos00 = {0, 0};
static const COORD size11 = {1, 1};
static const COORD pos00 = { 0, 0 };
static const COORD size11 = { 1, 1 };
/* atExit information */ /* atExit information */
static struct static struct {
{
int is_valid; int is_valid;
HANDLE ho; HANDLE ho;
CONSOLE_CURSOR_INFO cci; CONSOLE_CURSOR_INFO cci;
} ae; } ae;
static void refresh(screen_t *this) { UNUSED(this); }
static void refresh(screen_t *this) static int getMode(const screen_t *this) { return this->data->mode; }
{
UNUSED(this);
}
static int getPage(const screen_t *this) {
static int getMode(const screen_t *this)
{
return this->data->mode;
}
static int getPage(const screen_t *this)
{
UNUSED(this); UNUSED(this);
return 0; return 0;
} }
static int getRows(const screen_t *this) { return this->data->rows; }
static int getRows(const screen_t *this) static int getCols(const screen_t *this) { return this->data->cols; }
{
return this->data->rows;
}
static int isMono(const screen_t *this) {
static int getCols(const screen_t *this)
{
return this->data->cols;
}
static int isMono(const screen_t *this)
{
UNUSED(this); UNUSED(this);
return 0; return 0;
} }
static int getFg(const screen_t *this) { return this->data->attr & mask_fg; }
static int getFg(const screen_t *this) static int getBg(const screen_t *this) { return this->data->attr & mask_bg; }
{
return this->data->attr & mask_fg;
}
static void setFg(screen_t *this, int fg) {
static int getBg(const screen_t *this) this->data->attr = (WORD)((this->data->attr & mask_bg) | (fg & mask_fg));
{
return this->data->attr & mask_bg;
}
static void setFg(screen_t *this, int fg)
{
this->data->attr = (WORD) ((this->data->attr & mask_bg) | (fg & mask_fg));
SetConsoleTextAttribute(this->data->ho, this->data->attr); SetConsoleTextAttribute(this->data->ho, this->data->attr);
} }
static void setBg(screen_t *this, int bg) {
static void setBg(screen_t *this, int bg) this->data->attr = (WORD)((this->data->attr & mask_fg) | (bg & mask_bg));
{
this->data->attr = (WORD) ((this->data->attr & mask_fg) | (bg & mask_bg));
SetConsoleTextAttribute(this->data->ho, this->data->attr); SetConsoleTextAttribute(this->data->ho, this->data->attr);
} }
static void setCursor(screen_t *this, int x, int y) {
static void setCursor(screen_t *this, int x, int y) if (x >= 0 && y >= 0 && x < this->data->cols && y < this->data->rows) {
{ COORD coord = {P(x), P(y)};
if (x >= 0 && y >= 0 && x < this->data->cols && y < this->data->rows)
{
COORD coord = { P(x), P(y) };
SetConsoleCursorPosition(this->data->ho, coord); SetConsoleCursorPosition(this->data->ho, coord);
this->data->cursor_x = x; this->data->cursor_x = x;
this->data->cursor_y = y; this->data->cursor_y = y;
} }
} }
static void getCursor(const screen_t *this, int *x, int *y) {
static void getCursor(const screen_t *this, int *x, int *y)
{
int cx = this->data->cursor_x; int cx = this->data->cursor_x;
int cy = this->data->cursor_y; int cy = this->data->cursor_y;
#if 1 #if 1
CONSOLE_SCREEN_BUFFER_INFO csbi; CONSOLE_SCREEN_BUFFER_INFO csbi;
if (GetConsoleScreenBufferInfo(this->data->ho, &csbi)) if (GetConsoleScreenBufferInfo(this->data->ho, &csbi)) {
{
cx = csbi.dwCursorPosition.X; cx = csbi.dwCursorPosition.X;
cy = csbi.dwCursorPosition.Y; cy = csbi.dwCursorPosition.Y;
#if 0 #if 0
@@ -188,30 +143,26 @@ static void getCursor(const screen_t *this, int *x, int *y)
#endif #endif
} }
#endif #endif
if (x) *x = cx; if (x)
if (y) *y = cy; *x = cx;
if (y)
*y = cy;
} }
static void putCharAttr(screen_t *this, int ch, int attr, int x, int y) {
static void putCharAttr(screen_t *this, int ch, int attr, int x, int y)
{
CHAR_INFO ci; CHAR_INFO ci;
SMALL_RECT region = { P(x), P(y), P(x), P(y) }; SMALL_RECT region = {P(x), P(y), P(x), P(y)};
ci.Char.UnicodeChar = 0; ci.Char.UnicodeChar = 0;
ci.Char.AsciiChar = (CHAR) ch; ci.Char.AsciiChar = (CHAR) ch;
ci.Attributes = (WORD) attr; ci.Attributes = (WORD) attr;
WriteConsoleOutputA(this->data->ho, &ci, size11, pos00, &region); WriteConsoleOutputA(this->data->ho, &ci, size11, pos00, &region);
} }
static void putChar(screen_t *this, int ch, int x, int y) {
static void putChar(screen_t *this, int ch, int x, int y)
{
this->putCharAttr(this, ch, this->data->attr, x, y); this->putCharAttr(this, ch, this->data->attr, x, y);
} }
static void putStringAttr(screen_t *this, const char *s, int attr, int x, int y) {
static void putStringAttr(screen_t *this, const char *s, int attr, int x, int y)
{
int i; int i;
int l = (int) strlen(s); int l = (int) strlen(s);
if (l <= 0) if (l <= 0)
@@ -219,10 +170,9 @@ static void putStringAttr(screen_t *this, const char *s, int attr, int x, int y)
assert(l <= 256); assert(l <= 256);
assert(x + l <= this->data->cols); assert(x + l <= this->data->cols);
CHAR_INFO ci[256]; CHAR_INFO ci[256];
COORD size = { P(l), 1 }; COORD size = {P(l), 1};
SMALL_RECT region = { P(x), P(y), P(x + l - 1), P(y) }; SMALL_RECT region = {P(x), P(y), P(x + l - 1), P(y)};
for (i = 0; i < l; i++) for (i = 0; i < l; i++) {
{
ci[i].Char.UnicodeChar = 0; ci[i].Char.UnicodeChar = 0;
ci[i].Char.AsciiChar = *s++; ci[i].Char.AsciiChar = *s++;
ci[i].Attributes = (WORD) attr; ci[i].Attributes = (WORD) attr;
@@ -230,58 +180,45 @@ static void putStringAttr(screen_t *this, const char *s, int attr, int x, int y)
WriteConsoleOutputA(this->data->ho, &ci[0], size, pos00, &region); WriteConsoleOutputA(this->data->ho, &ci[0], size, pos00, &region);
} }
static void putString(screen_t *this, const char *s, int x, int y) {
static void putString(screen_t *this, const char *s, int x, int y)
{
this->putStringAttr(this, s, this->data->attr, x, y); this->putStringAttr(this, s, this->data->attr, x, y);
} }
/* private */ /* private */
static int cci2shape(const 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)
shape |= 0x2000; shape |= 0x2000;
return shape; return shape;
} }
static int getCursorShape(const screen_t *this) {
static int getCursorShape(const screen_t *this)
{
CONSOLE_CURSOR_INFO cci; CONSOLE_CURSOR_INFO cci;
GetConsoleCursorInfo(this->data->ho, &cci); GetConsoleCursorInfo(this->data->ho, &cci);
return cci2shape(&cci); return cci2shape(&cci);
} }
static void setCursorShape(screen_t *this, int shape) {
static void setCursorShape(screen_t *this, int shape)
{
CONSOLE_CURSOR_INFO cci; CONSOLE_CURSOR_INFO cci;
cci.dwSize = shape & 255; cci.dwSize = shape & 255;
cci.bVisible = (shape & 0x2000) ? 0 : 1; cci.bVisible = (shape & 0x2000) ? 0 : 1;
SetConsoleCursorInfo(this->data->ho, &cci); SetConsoleCursorInfo(this->data->ho, &cci);
} }
static int hideCursor(screen_t *this) {
static int hideCursor(screen_t *this)
{
CONSOLE_CURSOR_INFO cci; CONSOLE_CURSOR_INFO cci;
int shape; int shape;
GetConsoleCursorInfo(this->data->ho, &cci); GetConsoleCursorInfo(this->data->ho, &cci);
shape = cci2shape(&cci); shape = cci2shape(&cci);
if (cci.bVisible) if (cci.bVisible) {
{
cci.bVisible = 0; cci.bVisible = 0;
SetConsoleCursorInfo(this->data->ho, &cci); SetConsoleCursorInfo(this->data->ho, &cci);
} }
return shape; return shape;
} }
static int init(screen_t *this, int fd) {
static int init(screen_t *this, int fd)
{
HANDLE hi, ho; HANDLE hi, ho;
CONSOLE_SCREEN_BUFFER_INFO *csbi; CONSOLE_SCREEN_BUFFER_INFO *csbi;
DWORD mode; DWORD mode;
@@ -338,7 +275,7 @@ static int init(screen_t *this, int fd)
attr = csbi->wAttributes; attr = csbi->wAttributes;
this->data->hi = hi; this->data->hi = hi;
this->data->ho = ho; this->data->ho = ho;
this->data->mode = 3; // ??? this->data->mode = 3; // ???
this->data->attr = attr; this->data->attr = attr;
this->data->init_attr = attr; this->data->init_attr = attr;
this->data->empty_cell.Char.UnicodeChar = 0; this->data->empty_cell.Char.UnicodeChar = 0;
@@ -350,11 +287,8 @@ static int init(screen_t *this, int fd)
return 0; return 0;
} }
static void updateLineN(screen_t *this, const void *line, int y, int len) {
static void updateLineN(screen_t *this, const void *line, int y, int len) if (y >= 0 && y < this->data->rows && len > 0 && len <= 2 * this->data->cols) {
{
if (y >= 0 && y < this->data->rows && len > 0 && len <= 2*this->data->cols)
{
#if 0 #if 0
const char *s = (const char *) line; const char *s = (const char *) line;
int l = len / 2; int l = len / 2;
@@ -376,160 +310,108 @@ static void updateLineN(screen_t *this, const void *line, int y, int len)
} }
} }
static void clearLine(screen_t *this, int y) {
static void clearLine(screen_t *this, int y) if (y >= 0 && y < this->data->rows) {
{ COORD size = {P(this->data->cols), 1};
if (y >= 0 && y < this->data->rows) SMALL_RECT region = {0, P(y), P(this->data->cols - 1), P(y)};
{
COORD size = { P(this->data->cols), 1 };
SMALL_RECT region = { 0, P(y), P(this->data->cols-1), P(y) };
WriteConsoleOutputA(this->data->ho, this->data->empty_line, size, pos00, &region); WriteConsoleOutputA(this->data->ho, this->data->empty_line, size, pos00, &region);
} }
} }
static void clear(screen_t *this) {
static void clear(screen_t *this)
{
int y; int y;
for (y = 0; y < this->data->rows; y++) for (y = 0; y < this->data->rows; y++)
this->clearLine(this, y); this->clearLine(this, y);
} }
/* private */ /* private */
static int do_scroll(screen_t *this, int lines, int way) static int do_scroll(screen_t *this, int lines, int way) {
{
if (lines <= 0 || lines > this->data->rows) if (lines <= 0 || lines > this->data->rows)
return 0; return 0;
if (lines == this->data->rows) if (lines == this->data->rows) {
{
this->clear(this); this->clear(this);
return lines; return lines;
} }
SMALL_RECT rect = { 0, 0, P(this->data->cols-1), P(this->data->rows-1) }; SMALL_RECT rect = {0, 0, P(this->data->cols - 1), P(this->data->rows - 1)};
//SMALL_RECT clip = rect; // SMALL_RECT clip = rect;
COORD dest = { 0, 0 }; COORD dest = {0, 0};
switch (way) switch (way) {
{ case 0:
case 0: rect.Top = P(rect.Top + lines);
rect.Top = P(rect.Top + lines); break;
break; case 1:
case 1: rect.Bottom = P(rect.Bottom - lines);
rect.Bottom = P(rect.Bottom - lines); dest.Y = P(dest.Y + lines);
dest.Y = P(dest.Y + lines); break;
break;
} }
//ScrollConsoleScreenBuffer(this->data->ho, &rect, &clip, dest, &this->data->empty_cell); // ScrollConsoleScreenBuffer(this->data->ho, &rect, &clip, dest, &this->data->empty_cell);
ScrollConsoleScreenBuffer(this->data->ho, &rect, NULL, dest, &this->data->empty_cell); ScrollConsoleScreenBuffer(this->data->ho, &rect, NULL, dest, &this->data->empty_cell);
return lines; return lines;
} }
static int scrollUp(screen_t *this, int lines) static int scrollUp(screen_t *this, int lines) {
{
lines = do_scroll(this, lines, 0); lines = do_scroll(this, lines, 0);
this->data->scroll_counter += lines; this->data->scroll_counter += lines;
return lines; return lines;
} }
static int scrollDown(screen_t *this, int lines) static int scrollDown(screen_t *this, int lines) {
{
lines = do_scroll(this, lines, 1); lines = do_scroll(this, lines, 1);
this->data->scroll_counter -= lines; this->data->scroll_counter -= lines;
return lines; return lines;
} }
static int getScrollCounter(const screen_t *this) static int getScrollCounter(const screen_t *this) { return this->data->scroll_counter; }
{
return this->data->scroll_counter;
}
static int s_kbhit(screen_t *this) {
static int s_kbhit(screen_t *this)
{
UNUSED(this); UNUSED(this);
#if (HAVE_CONIO_H) #if (HAVE_CONIO_H)
# if defined(__RSXNT__) #if defined(__RSXNT__)
return 0; return 0;
# elif defined(__BORLANDC__) || defined(__WATCOMC__) #elif defined(__BORLANDC__) || defined(__WATCOMC__)
return kbhit(); return kbhit();
# else #else
return _kbhit(); return _kbhit();
# endif #endif
#else #else
return 0; return 0;
#endif #endif
} }
static int intro(screen_t *this, void (*show_frames)(screen_t *)) {
static int intro(screen_t *this, void (*show_frames)(screen_t *) )
{
UNUSED(this); UNUSED(this);
UNUSED(show_frames); UNUSED(show_frames);
return 0; return 0;
} }
static void atExit(void) {
static void atExit(void)
{
static int done = 0; static int done = 0;
if (done) return; if (done)
return;
done = 1; done = 1;
if (ae.is_valid) if (ae.is_valid) {
{
} }
} }
static const screen_t driver = {sobject_destroy, 0, /* finalize, */
static const screen_t driver = atExit, init, refresh,
{ getMode, getPage, getRows,
sobject_destroy, getCols, isMono, getFg,
0, /* finalize, */ getBg, getCursor, getCursorShape,
atExit, setFg, setBg, setCursor,
init, setCursorShape, hideCursor, putChar,
refresh, putCharAttr, putString, putStringAttr,
getMode, clear, clearLine, updateLineN,
getPage, scrollUp, scrollDown, getScrollCounter,
getRows, s_kbhit, intro, (struct screen_data_t *) 0};
getCols,
isMono,
getFg,
getBg,
getCursor,
getCursorShape,
setFg,
setBg,
setCursor,
setCursorShape,
hideCursor,
putChar,
putCharAttr,
putString,
putStringAttr,
clear,
clearLine,
updateLineN,
scrollUp,
scrollDown,
getScrollCounter,
s_kbhit,
intro,
(struct screen_data_t *) 0
};
/* public constructor */ /* public constructor */
screen_t *screen_win32_construct(void) screen_t *screen_win32_construct(void) { return sobject_construct(&driver, sizeof(*driver.data)); }
{
return sobject_construct(&driver,sizeof(*driver.data));
}
#endif /* (USE_SCREEN_WIN32) */ #endif /* (USE_SCREEN_WIN32) */
/* /*
vi:ts=4:et vi:ts=4:et
*/ */
+5 -12
View File
@@ -25,13 +25,11 @@
<markus@oberhumer.com> <ml1050@users.sourceforge.net> <markus@oberhumer.com> <ml1050@users.sourceforge.net>
*/ */
#ifndef __UPX_SCREEN_H #ifndef __UPX_SCREEN_H
#define __UPX_SCREEN_H 1 #define __UPX_SCREEN_H 1
#if (USE_SCREEN) #if (USE_SCREEN)
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
@@ -40,12 +38,11 @@ struct screen_data_t;
struct screen_t; struct screen_t;
typedef struct screen_t screen_t; typedef struct screen_t screen_t;
struct screen_t struct screen_t {
{ /* public: */
/* public: */
void (*destroy)(screen_t *s); void (*destroy)(screen_t *s);
void (*finalize)(screen_t *s); void (*finalize)(screen_t *s);
void (*atExit)(void); /* atexit/signal handler */ void (*atExit)(void); /* atexit/signal handler */
int (*init)(screen_t *s, int fd); int (*init)(screen_t *s, int fd);
@@ -83,13 +80,12 @@ struct screen_t
int (*kbhit)(screen_t *s); int (*kbhit)(screen_t *s);
int (*intro)(screen_t *s, void (*)(screen_t*) ); int (*intro)(screen_t *s, void (*)(screen_t *));
/* private: */ /* private: */
struct screen_data_t *data; struct screen_data_t *data;
}; };
screen_t *sobject_construct(const screen_t *c, size_t data_size); screen_t *sobject_construct(const screen_t *c, size_t data_size);
void sobject_destroy(screen_t *); void sobject_destroy(screen_t *);
screen_t *sobject_get_screen(void); screen_t *sobject_get_screen(void);
@@ -101,13 +97,10 @@ screen_t *screen_win32_construct(void);
void screen_show_frames(screen_t *); void screen_show_frames(screen_t *);
#endif /* USE_SCREEN */ #endif /* USE_SCREEN */
#endif /* already included */ #endif /* already included */
/* /*
vi:ts=4:et vi:ts=4:et
*/ */