summaryrefslogtreecommitdiff
path: root/sys/dev/rasops
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2018-04-20 16:06:08 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2018-04-20 16:06:08 +0000
commit1fcdae3803f12bcab8d7dcd79f499606f6286306 (patch)
treee70105ce5469978a0e66ebab77083109aa41e72a /sys/dev/rasops
parentec7677f0c1cf4c5c826b0fbbf535d65a596a17ea (diff)
sync
Diffstat (limited to 'sys/dev/rasops')
-rw-r--r--sys/dev/rasops/rasops.c101
-rw-r--r--sys/dev/rasops/rasops.h3
2 files changed, 87 insertions, 17 deletions
diff --git a/sys/dev/rasops/rasops.c b/sys/dev/rasops/rasops.c
index 956f2a5fb48..1b601908a84 100644
--- a/sys/dev/rasops/rasops.c
+++ b/sys/dev/rasops/rasops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rasops.c,v 1.50 2018/01/23 10:10:32 fcambus Exp $ */
+/* $OpenBSD: rasops.c,v 1.51 2018/04/20 16:06:07 deraadt Exp $ */
/* $NetBSD: rasops.c,v 1.35 2001/02/02 06:01:01 marcus Exp $ */
/*-
@@ -1373,8 +1373,13 @@ struct rasops_screen {
int rs_visible;
int rs_crow;
int rs_ccol;
+
+ int rs_dispoffset; /* rs_bs index, start of our actual screen */
+ int rs_visibleoffset; /* rs_bs index, current scrollback screen */
};
+#define RS_SCROLLBACK_SCREENS 5
+
int
rasops_alloc_screen(void *v, void **cookiep,
int *curxp, int *curyp, long *attrp)
@@ -1387,13 +1392,15 @@ rasops_alloc_screen(void *v, void **cookiep,
if (scr == NULL)
return (ENOMEM);
- scr->rs_bs = mallocarray(ri->ri_rows,
+ scr->rs_bs = mallocarray(ri->ri_rows * RS_SCROLLBACK_SCREENS,
ri->ri_cols * sizeof(struct wsdisplay_charcell), M_DEVBUF,
M_NOWAIT);
if (scr->rs_bs == NULL) {
free(scr, M_DEVBUF, sizeof(*scr));
return (ENOMEM);
}
+ scr->rs_visibleoffset = scr->rs_dispoffset = ri->ri_rows *
+ (RS_SCROLLBACK_SCREENS - 1) * ri->ri_cols;
*cookiep = scr;
*curxp = 0;
@@ -1405,13 +1412,19 @@ rasops_alloc_screen(void *v, void **cookiep,
scr->rs_crow = -1;
scr->rs_ccol = -1;
+ for (i = 0; i < scr->rs_dispoffset; i++) {
+ scr->rs_bs[i].uc = ' ';
+ scr->rs_bs[i].attr = *attrp;
+ }
+
if (ri->ri_bs && scr->rs_visible) {
- memcpy(scr->rs_bs, ri->ri_bs, ri->ri_rows * ri->ri_cols *
+ memcpy(scr->rs_bs + scr->rs_dispoffset, ri->ri_bs,
+ ri->ri_rows * ri->ri_cols *
sizeof(struct wsdisplay_charcell));
} else {
for (i = 0; i < ri->ri_rows * ri->ri_cols; i++) {
- scr->rs_bs[i].uc = ' ';
- scr->rs_bs[i].attr = *attrp;
+ scr->rs_bs[scr->rs_dispoffset + i].uc = ' ';
+ scr->rs_bs[scr->rs_dispoffset + i].attr = *attrp;
}
}
@@ -1431,7 +1444,8 @@ rasops_free_screen(void *v, void *cookie)
ri->ri_nscreens--;
free(scr->rs_bs, M_DEVBUF,
- ri->ri_rows * ri->ri_cols * sizeof(struct wsdisplay_charcell));
+ ri->ri_rows * RS_SCROLLBACK_SCREENS * ri->ri_cols *
+ sizeof(struct wsdisplay_charcell));
free(scr, M_DEVBUF, sizeof(*scr));
}
@@ -1467,9 +1481,11 @@ rasops_doswitch(void *v)
ri->ri_eraserows(ri, 0, ri->ri_rows, attr);
ri->ri_active = scr;
ri->ri_active->rs_visible = 1;
+ ri->ri_active->rs_visibleoffset = ri->ri_active->rs_dispoffset;
for (row = 0; row < ri->ri_rows; row++) {
for (col = 0; col < ri->ri_cols; col++) {
- int off = row * scr->rs_ri->ri_cols + col;
+ int off = row * scr->rs_ri->ri_cols + col +
+ scr->rs_visibleoffset;
ri->ri_putchar(ri, row, col, scr->rs_bs[off].uc,
scr->rs_bs[off].attr);
@@ -1491,7 +1507,7 @@ rasops_getchar(void *v, int row, int col, struct wsdisplay_charcell *cell)
if (scr == NULL || scr->rs_bs == NULL)
return (1);
- *cell = scr->rs_bs[row * ri->ri_cols + col];
+ *cell = scr->rs_bs[row * ri->ri_cols + col + scr->rs_dispoffset];
return (0);
}
@@ -1521,7 +1537,10 @@ int
rasops_vcons_putchar(void *cookie, int row, int col, u_int uc, long attr)
{
struct rasops_screen *scr = cookie;
- int off = row * scr->rs_ri->ri_cols + col;
+ int off = row * scr->rs_ri->ri_cols + col + scr->rs_dispoffset;
+
+ if (scr->rs_visible && scr->rs_visibleoffset != scr->rs_dispoffset)
+ rasops_scrollback(scr->rs_ri, scr, 0);
scr->rs_bs[off].uc = uc;
scr->rs_bs[off].attr = attr;
@@ -1540,7 +1559,8 @@ rasops_vcons_copycols(void *cookie, int row, int src, int dst, int num)
int cols = scr->rs_ri->ri_cols;
int col, rc;
- memmove(&scr->rs_bs[row * cols + dst], &scr->rs_bs[row * cols + src],
+ memmove(&scr->rs_bs[row * cols + dst + scr->rs_dispoffset],
+ &scr->rs_bs[row * cols + src + scr->rs_dispoffset],
num * sizeof(struct wsdisplay_charcell));
if (!scr->rs_visible)
@@ -1550,7 +1570,7 @@ rasops_vcons_copycols(void *cookie, int row, int src, int dst, int num)
return ri->ri_copycols(ri, row, src, dst, num);
for (col = dst; col < dst + num; col++) {
- int off = row * cols + col;
+ int off = row * cols + col + scr->rs_dispoffset;
rc = ri->ri_putchar(ri, row, col,
scr->rs_bs[off].uc, scr->rs_bs[off].attr);
@@ -1569,7 +1589,7 @@ rasops_vcons_erasecols(void *cookie, int row, int col, int num, long attr)
int i;
for (i = 0; i < num; i++) {
- int off = row * cols + col + i;
+ int off = row * cols + col + i + scr->rs_dispoffset;
scr->rs_bs[off].uc = ' ';
scr->rs_bs[off].attr = attr;
@@ -1589,8 +1609,15 @@ rasops_vcons_copyrows(void *cookie, int src, int dst, int num)
int cols = ri->ri_cols;
int row, col, rc;
- memmove(&scr->rs_bs[dst * cols], &scr->rs_bs[src * cols],
- num * cols * sizeof(struct wsdisplay_charcell));
+ if (dst == 0 && (src + num == ri->ri_rows))
+ memmove(&scr->rs_bs[dst],
+ &scr->rs_bs[src * cols],
+ ((ri->ri_rows * RS_SCROLLBACK_SCREENS * cols) -
+ (src * cols)) * sizeof(struct wsdisplay_charcell));
+ else
+ memmove(&scr->rs_bs[dst * cols + scr->rs_dispoffset],
+ &scr->rs_bs[src * cols + scr->rs_dispoffset],
+ num * cols * sizeof(struct wsdisplay_charcell));
if (!scr->rs_visible)
return 0;
@@ -1600,7 +1627,7 @@ rasops_vcons_copyrows(void *cookie, int src, int dst, int num)
for (row = dst; row < dst + num; row++) {
for (col = 0; col < cols; col++) {
- int off = row * cols + col;
+ int off = row * cols + col + scr->rs_dispoffset;
rc = ri->ri_putchar(ri, row, col,
scr->rs_bs[off].uc, scr->rs_bs[off].attr);
@@ -1620,7 +1647,7 @@ rasops_vcons_eraserows(void *cookie, int row, int num, long attr)
int i;
for (i = 0; i < num * cols; i++) {
- int off = row * cols + i;
+ int off = row * cols + i + scr->rs_dispoffset;
scr->rs_bs[off].uc = ' ';
scr->rs_bs[off].attr = attr;
@@ -1872,3 +1899,45 @@ rasops_list_font(void *v, struct wsdisplay_font *font)
font->cookie = font->data = NULL; /* don't leak kernel pointers */
return 0;
}
+
+void
+rasops_scrollback(void *v, void *cookie, int lines)
+{
+ struct rasops_info *ri = v;
+ struct rasops_screen *scr = cookie;
+ int row, col, oldvoff;
+ long attr;
+
+ oldvoff = scr->rs_visibleoffset;
+
+ if (lines == 0)
+ scr->rs_visibleoffset = scr->rs_dispoffset;
+ else {
+ int off = scr->rs_visibleoffset + (lines * ri->ri_cols);
+
+ if (off < 0)
+ off = 0;
+ else if (off > scr->rs_dispoffset)
+ off = scr->rs_dispoffset;
+
+ scr->rs_visibleoffset = off;
+ }
+
+ if (scr->rs_visibleoffset == oldvoff)
+ return;
+
+ rasops_cursor(ri, 0, 0, 0);
+ ri->ri_eraserows(ri, 0, ri->ri_rows, attr);
+ for (row = 0; row < ri->ri_rows; row++) {
+ for (col = 0; col < ri->ri_cols; col++) {
+ int off = row * scr->rs_ri->ri_cols + col +
+ scr->rs_visibleoffset;
+
+ ri->ri_putchar(ri, row, col, scr->rs_bs[off].uc,
+ scr->rs_bs[off].attr);
+ }
+ }
+
+ if (scr->rs_crow != -1 && scr->rs_visibleoffset == scr->rs_dispoffset)
+ rasops_cursor(ri, 1, scr->rs_crow, scr->rs_ccol);
+}
diff --git a/sys/dev/rasops/rasops.h b/sys/dev/rasops/rasops.h
index d338441d8cd..eeb8b0ba7f4 100644
--- a/sys/dev/rasops/rasops.h
+++ b/sys/dev/rasops/rasops.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rasops.h,v 1.19 2017/08/17 20:21:53 kettenis Exp $ */
+/* $OpenBSD: rasops.h,v 1.20 2018/04/20 16:06:07 deraadt Exp $ */
/* $NetBSD: rasops.h,v 1.13 2000/06/13 13:36:54 ad Exp $ */
/*-
@@ -178,6 +178,7 @@ int rasops_show_screen(void *, void *, int,
int rasops_load_font(void *, void *, struct wsdisplay_font *);
int rasops_list_font(void *, struct wsdisplay_font *);
int rasops_getchar(void *, int, int, struct wsdisplay_charcell *);
+void rasops_scrollback(void *, void *, int);
extern const u_char rasops_isgray[16];
extern const u_char rasops_cmap[256*3];