summaryrefslogtreecommitdiffstats
path: root/tis-curses.c
diff options
context:
space:
mode:
Diffstat (limited to 'tis-curses.c')
-rw-r--r--tis-curses.c65
1 files changed, 42 insertions, 23 deletions
diff --git a/tis-curses.c b/tis-curses.c
index 1b7488e..8b3bd3e 100644
--- a/tis-curses.c
+++ b/tis-curses.c
@@ -43,8 +43,10 @@ struct tpu_cell {
static size_t tpu_cell_rows = 2;
static size_t tpu_cell_cols = 3;
-static size_t screenw = 80;
-static size_t screenh = 40;
+static int scrx = 0;
+static int scry = 0;
+static int scrw = 80;
+static int scrh = 40;
static struct tpu_cell *tpu_cells = NULL;
@@ -77,6 +79,11 @@ tui_draw_box(int sx, int sy, int w, int h, const cchar_t *ul, const cchar_t *ur,
{
int x, y;
+ if (sx + w < scrx || sx >= scrx + scrw) return;
+ if (sy + h < scry || sy >= scry + scrh) return;
+
+ sx -= scrx;
+ sy -= scry;
mvadd_wch(sy, sx, ul);
mvadd_wch(sy, sx + w - 1, ur);
mvadd_wch(sy + h - 1, sx, ll);
@@ -103,7 +110,7 @@ tui_draw_text(int x, int y, int attr, const char *fmt, ...)
va_end(ap);
attron(attr);
- mvprintw(y, x, "%s", buf);
+ mvprintw(y - scry, x - scrx, "%s", buf);
attroff(attr);
}
@@ -111,7 +118,7 @@ static void
tui_draw_wch(int x, int y, int attr, const cchar_t *c)
{
attron(attr);
- mvadd_wch(y, x, c);
+ mvadd_wch(y - scry, x - scrx, c);
attroff(attr);
}
@@ -157,52 +164,52 @@ tui_draw_tpu_cell(struct tpu_cell *cell)
port = &cell->tpu.ports[DIR_LEFT];
if (port->type & PORT_IN)
tui_draw_wch((int) cell->x - 1, (int) cell->y + 8,
- port->read ? A_BOLD : 0, WACS_RARROW);
+ port->reading ? A_BOLD : 0, WACS_RARROW);
if (port->type & PORT_OUT)
tui_draw_wch((int) cell->x - 1, (int) cell->y + 7,
- port->write ? A_BOLD : 0, WACS_LARROW);
- if (port->write)
+ port->out > 0 ? A_BOLD : 0, WACS_LARROW);
+ if (port->out >= 0)
tui_draw_text((int) cell->x - 3, (int) cell->y + 6,
- A_BOLD, "%03i", port->val);
+ A_BOLD, "%03i", port->out);
}
if (cell->tpu.ports[DIR_RIGHT].attached) {
port = &cell->tpu.ports[DIR_RIGHT];
if (port->type & PORT_IN)
tui_draw_wch((int) cell->x + TCELL_W + 1, (int) cell->y + 7,
- port->read ? A_BOLD : 0, WACS_LARROW);
+ port->reading ? A_BOLD : 0, WACS_LARROW);
if (port->type & PORT_OUT)
tui_draw_wch((int) cell->x + TCELL_W + 1, (int) cell->y + 8,
- port->write ? A_BOLD : 0, WACS_RARROW);
- if (port->write)
+ port->out > 0 ? A_BOLD : 0, WACS_RARROW);
+ if (port->out >= 0)
tui_draw_text((int) cell->x + TCELL_W + 1, (int) cell->y + 9,
- A_BOLD, "%03i", port->val);
+ A_BOLD, "%03i", port->out);
}
if (cell->tpu.ports[DIR_UP].attached) {
port = &cell->tpu.ports[DIR_UP];
if (port->type & PORT_IN)
tui_draw_wch((int) cell->x + 13, (int) cell->y - 1,
- port->read ? A_BOLD : 0, WACS_DARROW);
+ port->reading ? A_BOLD : 0, WACS_DARROW);
if (port->type & PORT_OUT)
tui_draw_wch((int) cell->x + 15, (int) cell->y - 1,
- port->write ? A_BOLD : 0, WACS_UARROW);
- if (port->write)
+ port->out > 0 ? A_BOLD : 0, WACS_UARROW);
+ if (port->out >= 0)
tui_draw_text((int) cell->x + 16, (int) cell->y - 1,
- A_BOLD, "%03i", port->val);
+ A_BOLD, "%03i", port->out);
}
if (cell->tpu.ports[DIR_DOWN].attached) {
port = &cell->tpu.ports[DIR_DOWN];
if (port->type & PORT_IN)
tui_draw_wch((int) cell->x + 13, (int) cell->y + TCELL_H,
- port->write ? A_BOLD : 0, WACS_DARROW);
+ port->out > 0 ? A_BOLD : 0, WACS_DARROW);
if (port->type & PORT_OUT)
tui_draw_wch((int) cell->x + 15, (int) cell->y + TCELL_H,
- port->read ? A_BOLD : 0, WACS_UARROW);
- if (port->write)
+ port->reading ? A_BOLD : 0, WACS_UARROW);
+ if (port->out >= 0)
tui_draw_text((int) cell->x + 10, (int) cell->y + TCELL_H,
- A_BOLD, "%03i", port->val);
+ A_BOLD, "%03i", port->out);
}
}
@@ -211,9 +218,9 @@ tui_draw(void)
{
int i;
+ clear();
for (i = 0; i < TCELL_CNT; i++)
tui_draw_tpu_cell(&tpu_cells[i]);
-
refresh();
}
@@ -222,8 +229,8 @@ tui_resize(void)
{
size_t x, y, i;
- screenw = (size_t) getmaxx(stdscr);
- screenh = (size_t) getmaxy(stdscr);
+ scrw = getmaxx(stdscr);
+ scrh = getmaxy(stdscr);
for (y = 0; y < tpu_cell_rows; y++) {
for (x = 0; x < tpu_cell_cols; x++) {
@@ -275,6 +282,18 @@ main(int argc, char **argv)
case KEY_RESIZE:
tui_resize();
break;
+ case KEY_UP:
+ scry -= 1;
+ break;
+ case KEY_DOWN:
+ scry += 1;
+ break;
+ case KEY_LEFT:
+ scrx -= 2;
+ break;
+ case KEY_RIGHT:
+ scrx += 2;
+ break;
case KEY_CTRL('c'):
quit = true;
break;