Commit c2e9375e authored by Sven Schnelle's avatar Sven Schnelle Committed by Heiko Carstens

s390/tty3270: add struct tty3270_attribute

In preparation of background color and graphic escape support add
a structure for attributes can be copied at once.
Signed-off-by: default avatarSven Schnelle <svens@linux.ibm.com>
Acked-by: default avatarHeiko Carstens <hca@linux.ibm.com>
Tested-by: default avatarNiklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: default avatarHeiko Carstens <hca@linux.ibm.com>
parent 562baff5
...@@ -41,10 +41,14 @@ static int tty3270_max_index; ...@@ -41,10 +41,14 @@ static int tty3270_max_index;
static struct tty3270 *condev; static struct tty3270 *condev;
static struct raw3270_fn tty3270_fn; static struct raw3270_fn tty3270_fn;
struct tty3270_attribute {
unsigned char highlight; /* Blink/reverse/underscore */
unsigned char f_color; /* Foreground color */
};
struct tty3270_cell { struct tty3270_cell {
unsigned char character; unsigned char character;
unsigned char highlight; struct tty3270_attribute attributes;
unsigned char f_color;
}; };
struct tty3270_line { struct tty3270_line {
...@@ -80,8 +84,8 @@ struct tty3270 { ...@@ -80,8 +84,8 @@ struct tty3270 {
/* Current tty screen. */ /* Current tty screen. */
unsigned int cx, cy; /* Current output position. */ unsigned int cx, cy; /* Current output position. */
unsigned int highlight; /* Blink/reverse/underscore */ struct tty3270_attribute attributes;
unsigned int f_color; /* Foreground color */ struct tty3270_attribute saved_attributes;
struct tty3270_line *screen; struct tty3270_line *screen;
unsigned int n_model, n_cols, n_rows; /* New model & size */ unsigned int n_model, n_cols, n_rows; /* New model & size */
struct work_struct resize_work; struct work_struct resize_work;
...@@ -101,7 +105,6 @@ struct tty3270 { ...@@ -101,7 +105,6 @@ struct tty3270 {
int esc_state, esc_ques, esc_npar; int esc_state, esc_ques, esc_npar;
int esc_par[ESCAPE_NPAR]; int esc_par[ESCAPE_NPAR];
unsigned int saved_cx, saved_cy; unsigned int saved_cx, saved_cy;
unsigned int saved_highlight, saved_f_color;
/* Command recalling. */ /* Command recalling. */
struct list_head rcl_lines; /* List of recallable lines. */ struct list_head rcl_lines; /* List of recallable lines. */
...@@ -1067,16 +1070,14 @@ static void tty3270_put_character(struct tty3270 *tp, char ch) ...@@ -1067,16 +1070,14 @@ static void tty3270_put_character(struct tty3270 *tp, char ch)
while (line->len < tp->cx) { while (line->len < tp->cx) {
cell = line->cells + line->len; cell = line->cells + line->len;
cell->character = tp->view.ascebc[' ']; cell->character = tp->view.ascebc[' '];
cell->highlight = tp->highlight; cell->attributes = tp->attributes;
cell->f_color = tp->f_color;
line->len++; line->len++;
} }
line->len++; line->len++;
} }
cell = line->cells + tp->cx; cell = line->cells + tp->cx;
cell->character = tp->view.ascebc[(unsigned int) ch]; cell->character = tp->view.ascebc[(unsigned int) ch];
cell->highlight = tp->highlight; cell->attributes = tp->attributes;
cell->f_color = tp->f_color;
} }
/* /*
...@@ -1099,13 +1100,13 @@ static void tty3270_convert_line(struct tty3270 *tp, int line_nr) ...@@ -1099,13 +1100,13 @@ static void tty3270_convert_line(struct tty3270 *tp, int line_nr)
highlight = TAX_RESET; highlight = TAX_RESET;
f_color = TAC_RESET; f_color = TAC_RESET;
for (i = 0, cell = line->cells; i < line->len; i++, cell++) { for (i = 0, cell = line->cells; i < line->len; i++, cell++) {
if (cell->highlight != highlight) { if (cell->attributes.highlight != highlight) {
flen += 3; /* TO_SA to switch highlight. */ flen += 3; /* TO_SA to switch highlight. */
highlight = cell->highlight; highlight = cell->attributes.highlight;
} }
if (cell->f_color != f_color) { if (cell->attributes.f_color != f_color) {
flen += 3; /* TO_SA to switch color. */ flen += 3; /* TO_SA to switch color. */
f_color = cell->f_color; f_color = cell->attributes.f_color;
} }
} }
if (highlight != TAX_RESET) if (highlight != TAX_RESET)
...@@ -1143,17 +1144,17 @@ static void tty3270_convert_line(struct tty3270 *tp, int line_nr) ...@@ -1143,17 +1144,17 @@ static void tty3270_convert_line(struct tty3270 *tp, int line_nr)
highlight = TAX_RESET; highlight = TAX_RESET;
f_color = TAC_RESET; f_color = TAC_RESET;
for (i = 0, cell = line->cells; i < line->len; i++, cell++) { for (i = 0, cell = line->cells; i < line->len; i++, cell++) {
if (cell->highlight != highlight) { if (cell->attributes.highlight != highlight) {
*cp++ = TO_SA; *cp++ = TO_SA;
*cp++ = TAT_EXTHI; *cp++ = TAT_EXTHI;
*cp++ = cell->highlight; *cp++ = cell->attributes.highlight;
highlight = cell->highlight; highlight = cell->attributes.highlight;
} }
if (cell->f_color != f_color) { if (cell->attributes.f_color != f_color) {
*cp++ = TO_SA; *cp++ = TO_SA;
*cp++ = TAT_COLOR; *cp++ = TAT_COLOR;
*cp++ = cell->f_color; *cp++ = cell->attributes.f_color;
f_color = cell->f_color; f_color = cell->attributes.f_color;
} }
*cp++ = cell->character; *cp++ = cell->character;
} }
...@@ -1224,6 +1225,18 @@ static void tty3270_ri(struct tty3270 *tp) ...@@ -1224,6 +1225,18 @@ static void tty3270_ri(struct tty3270 *tp)
} }
} }
static void tty3270_reset_attributes(struct tty3270_attribute *attr)
{
attr->highlight = TAX_RESET;
attr->f_color = TAC_RESET;
}
static void tty3270_reset_cell(struct tty3270 *tp, struct tty3270_cell *cell)
{
cell->character = tp->view.ascebc[' '];
tty3270_reset_attributes(&cell->attributes);
}
/* /*
* Insert characters at current position. * Insert characters at current position.
*/ */
...@@ -1233,12 +1246,8 @@ static void tty3270_insert_characters(struct tty3270 *tp, int n) ...@@ -1233,12 +1246,8 @@ static void tty3270_insert_characters(struct tty3270 *tp, int n)
int k; int k;
line = tp->screen + tp->cy; line = tp->screen + tp->cy;
while (line->len < tp->cx) { while (line->len < tp->cx)
line->cells[line->len].character = tp->view.ascebc[' ']; tty3270_reset_cell(tp, &line->cells[line->len++]);
line->cells[line->len].highlight = TAX_RESET;
line->cells[line->len].f_color = TAC_RESET;
line->len++;
}
if (n > tp->view.cols - tp->cx) if (n > tp->view.cols - tp->cx)
n = tp->view.cols - tp->cx; n = tp->view.cols - tp->cx;
k = min_t(int, line->len - tp->cx, tp->view.cols - tp->cx - n); k = min_t(int, line->len - tp->cx, tp->view.cols - tp->cx - n);
...@@ -1249,8 +1258,7 @@ static void tty3270_insert_characters(struct tty3270 *tp, int n) ...@@ -1249,8 +1258,7 @@ static void tty3270_insert_characters(struct tty3270 *tp, int n)
line->len = tp->view.cols; line->len = tp->view.cols;
while (n-- > 0) { while (n-- > 0) {
line->cells[tp->cx + n].character = tp->view.ascebc[' ']; line->cells[tp->cx + n].character = tp->view.ascebc[' '];
line->cells[tp->cx + n].highlight = tp->highlight; line->cells[tp->cx + n].attributes = tp->attributes;
line->cells[tp->cx + n].f_color = tp->f_color;
} }
} }
...@@ -1285,9 +1293,7 @@ static void tty3270_erase_characters(struct tty3270 *tp, int n) ...@@ -1285,9 +1293,7 @@ static void tty3270_erase_characters(struct tty3270 *tp, int n)
line = tp->screen + tp->cy; line = tp->screen + tp->cy;
while (line->len > tp->cx && n-- > 0) { while (line->len > tp->cx && n-- > 0) {
cell = line->cells + tp->cx++; cell = line->cells + tp->cx++;
cell->character = ' '; tty3270_reset_cell(tp, cell);
cell->highlight = TAX_RESET;
cell->f_color = TAC_RESET;
} }
tp->cx += n; tp->cx += n;
tp->cx = min_t(int, tp->cx, tp->view.cols - 1); tp->cx = min_t(int, tp->cx, tp->view.cols - 1);
...@@ -1314,8 +1320,8 @@ static void tty3270_erase_line(struct tty3270 *tp, int mode) ...@@ -1314,8 +1320,8 @@ static void tty3270_erase_line(struct tty3270 *tp, int mode)
for (i = 0; i < tp->cx; i++) { for (i = 0; i < tp->cx; i++) {
cell = line->cells + i; cell = line->cells + i;
cell->character = ' '; cell->character = ' ';
cell->highlight = TAX_RESET; cell->attributes.highlight = TAX_RESET;
cell->f_color = TAC_RESET; cell->attributes.f_color = TAC_RESET;
} }
if (line->len <= tp->cx) if (line->len <= tp->cx)
line->len = tp->cx + 1; line->len = tp->cx + 1;
...@@ -1380,30 +1386,29 @@ static void tty3270_set_attributes(struct tty3270 *tp) ...@@ -1380,30 +1386,29 @@ static void tty3270_set_attributes(struct tty3270 *tp)
attr = tp->esc_par[i]; attr = tp->esc_par[i];
switch (attr) { switch (attr) {
case 0: /* Reset */ case 0: /* Reset */
tp->highlight = TAX_RESET; tty3270_reset_attributes(&tp->attributes);
tp->f_color = TAC_RESET;
break; break;
/* Highlight. */ /* Highlight. */
case 4: /* Start underlining. */ case 4: /* Start underlining. */
tp->highlight = TAX_UNDER; tp->attributes.highlight = TAX_UNDER;
break; break;
case 5: /* Start blink. */ case 5: /* Start blink. */
tp->highlight = TAX_BLINK; tp->attributes.highlight = TAX_BLINK;
break; break;
case 7: /* Start reverse. */ case 7: /* Start reverse. */
tp->highlight = TAX_REVER; tp->attributes.highlight = TAX_REVER;
break; break;
case 24: /* End underlining */ case 24: /* End underlining */
if (tp->highlight == TAX_UNDER) if (tp->attributes.highlight == TAX_UNDER)
tp->highlight = TAX_RESET; tp->attributes.highlight = TAX_RESET;
break; break;
case 25: /* End blink. */ case 25: /* End blink. */
if (tp->highlight == TAX_BLINK) if (tp->attributes.highlight == TAX_BLINK)
tp->highlight = TAX_RESET; tp->attributes.highlight = TAX_RESET;
break; break;
case 27: /* End reverse. */ case 27: /* End reverse. */
if (tp->highlight == TAX_REVER) if (tp->attributes.highlight == TAX_REVER)
tp->highlight = TAX_RESET; tp->attributes.highlight = TAX_RESET;
break; break;
/* Foreground color. */ /* Foreground color. */
case 30: /* Black */ case 30: /* Black */
...@@ -1415,7 +1420,7 @@ static void tty3270_set_attributes(struct tty3270 *tp) ...@@ -1415,7 +1420,7 @@ static void tty3270_set_attributes(struct tty3270 *tp)
case 36: /* Cyan */ case 36: /* Cyan */
case 37: /* White */ case 37: /* White */
case 39: /* Black */ case 39: /* Black */
tp->f_color = f_colors[attr - 30]; tp->attributes.f_color = f_colors[attr - 30];
break; break;
} }
} }
...@@ -1491,20 +1496,18 @@ static void tty3270_escape_sequence(struct tty3270 *tp, char ch) ...@@ -1491,20 +1496,18 @@ static void tty3270_escape_sequence(struct tty3270 *tp, char ch)
case '7': /* Save cursor position. */ case '7': /* Save cursor position. */
tp->saved_cx = tp->cx; tp->saved_cx = tp->cx;
tp->saved_cy = tp->cy; tp->saved_cy = tp->cy;
tp->saved_highlight = tp->highlight; tp->saved_attributes = tp->attributes;
tp->saved_f_color = tp->f_color;
break; break;
case '8': /* Restore cursor position. */ case '8': /* Restore cursor position. */
tty3270_convert_line(tp, tp->cy); tty3270_convert_line(tp, tp->cy);
tty3270_goto_xy(tp, tp->saved_cx, tp->saved_cy); tty3270_goto_xy(tp, tp->saved_cx, tp->saved_cy);
tp->highlight = tp->saved_highlight; tp->attributes = tp->saved_attributes;
tp->f_color = tp->saved_f_color;
break; break;
case 'c': /* Reset terminal. */ case 'c': /* Reset terminal. */
tp->cx = tp->saved_cx = 0; tp->cx = tp->saved_cx = 0;
tp->cy = tp->saved_cy = 0; tp->cy = tp->saved_cy = 0;
tp->highlight = tp->saved_highlight = TAX_RESET; tty3270_reset_attributes(&tp->attributes);
tp->f_color = tp->saved_f_color = TAC_RESET; tty3270_reset_attributes(&tp->saved_attributes);
tty3270_erase_display(tp, 2); tty3270_erase_display(tp, 2);
break; break;
} }
...@@ -1592,14 +1595,12 @@ static void tty3270_escape_sequence(struct tty3270 *tp, char ch) ...@@ -1592,14 +1595,12 @@ static void tty3270_escape_sequence(struct tty3270 *tp, char ch)
case 's': /* Save cursor position. */ case 's': /* Save cursor position. */
tp->saved_cx = tp->cx; tp->saved_cx = tp->cx;
tp->saved_cy = tp->cy; tp->saved_cy = tp->cy;
tp->saved_highlight = tp->highlight; tp->saved_attributes = tp->attributes;
tp->saved_f_color = tp->f_color;
break; break;
case 'u': /* Restore cursor position. */ case 'u': /* Restore cursor position. */
tty3270_convert_line(tp, tp->cy); tty3270_convert_line(tp, tp->cy);
tty3270_goto_xy(tp, tp->saved_cx, tp->saved_cy); tty3270_goto_xy(tp, tp->saved_cx, tp->saved_cy);
tp->highlight = tp->saved_highlight; tp->attributes = tp->saved_attributes;
tp->f_color = tp->saved_f_color;
break; break;
} }
} }
...@@ -1791,8 +1792,8 @@ static void tty3270_hangup(struct tty_struct *tty) ...@@ -1791,8 +1792,8 @@ static void tty3270_hangup(struct tty_struct *tty)
spin_lock_irq(&tp->view.lock); spin_lock_irq(&tp->view.lock);
tp->cx = tp->saved_cx = 0; tp->cx = tp->saved_cx = 0;
tp->cy = tp->saved_cy = 0; tp->cy = tp->saved_cy = 0;
tp->highlight = tp->saved_highlight = TAX_RESET; tty3270_reset_attributes(&tp->attributes);
tp->f_color = tp->saved_f_color = TAC_RESET; tty3270_reset_attributes(&tp->saved_attributes);
tty3270_blank_screen(tp); tty3270_blank_screen(tp);
while (tp->nr_lines < tp->view.rows - 2) while (tp->nr_lines < tp->view.rows - 2)
tty3270_blank_line(tp); tty3270_blank_line(tp);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment