Introduce names (en enum) for 0, 1, and 2 constants. We now have VCI_HALF_BRIGHT, VCI_NORMAL, and VCI_BOLD instead. Apart from the cleanup, 1) the enum allows for better type checking, and 2) this saves some code. No more fiddling with bits is needed in assembly now. (OTOH, the structure is larger.)
Unified · Split
| @@ -705,8 +705,9 @@ void update_region(struct vc_data *vc, unsigned long start, int count) · 704 unmodified lines | ||
| 705 | 705 | |
| 706 | 706 | /* Structure of attributes is hardware-dependent */ |
| 707 | 707 | |
| 708 | −static u8 build_attr(struct vc_data *vc, u8 _color, u8 _intensity, u8 _blink, | |
| 709 | − u8 _underline, u8 _reverse, u8 _italic) | |
| 708 | +static u8 build_attr(struct vc_data *vc, u8 _color, | |
| 709 | + enum vc_intensity _intensity, u8 _blink, u8 _underline, | |
| 710 | + u8 _reverse, u8 _italic) | |
| 710 | 711 | { |
| 711 | 712 | if (vc->vc_sw->con_build_attr) |
| 712 | 713 | return vc->vc_sw->con_build_attr(vc, _color, _intensity, |
| @@ -734,13 +735,13 @@ static u8 build_attr(struct vc_data *vc, u8 _color, u8 _intensity, u8 _blink, · 21 unmodified lines | ||
| 734 | 735 | a = (a & 0xF0) | vc->vc_itcolor; |
| 735 | 736 | else if (_underline) |
| 736 | 737 | a = (a & 0xf0) | vc->vc_ulcolor; |
| 737 | − else if (_intensity == 0) | |
| 738 | + else if (_intensity == VCI_HALF_BRIGHT) | |
| 738 | 739 | a = (a & 0xf0) | vc->vc_halfcolor; |
| 739 | 740 | if (_reverse) |
| 740 | 741 | a = ((a) & 0x88) | ((((a) >> 4) | ((a) << 4)) & 0x77); |
| 741 | 742 | if (_blink) |
| 742 | 743 | a ^= 0x80; |
| 743 | − if (_intensity == 2) | |
| 744 | + if (_intensity == VCI_BOLD) | |
| 744 | 745 | a ^= 0x08; |
| 745 | 746 | if (vc->vc_hi_font_mask == 0x100) |
| 746 | 747 | a <<= 1; |
| @@ -753,8 +754,9 @@ static void update_attr(struct vc_data *vc) · 6 unmodified lines | ||
| 753 | 754 | vc->vc_attr = build_attr(vc, vc->state.color, vc->state.intensity, |
| 754 | 755 | vc->state.blink, vc->state.underline, |
| 755 | 756 | vc->state.reverse ^ vc->vc_decscnm, vc->state.italic); |
| 756 | − vc->vc_video_erase_char = ' ' | (build_attr(vc, vc->state.color, 1, | |
| 757 | − vc->state.blink, 0, vc->vc_decscnm, 0) << 8); | |
| 757 | + vc->vc_video_erase_char = ' ' | (build_attr(vc, vc->state.color, | |
| 758 | + VCI_NORMAL, vc->state.blink, 0, vc->vc_decscnm, | |
| 759 | + 0) << 8); | |
| 758 | 760 | } |
| 759 | 761 | |
| 760 | 762 | /* Note: inverting the screen twice should revert to the original state */ |
| @@ -1611,7 +1613,7 @@ static void csi_X(struct vc_data *vc, int vpar) /* erase the following vpar posi · 850 unmodified lines | ||
| 1611 | 1613 | |
| 1612 | 1614 | static void default_attr(struct vc_data *vc) |
| 1613 | 1615 | { |
| 1614 | − vc->state.intensity = 1; | |
| 1616 | + vc->state.intensity = VCI_NORMAL; | |
| 1615 | 1617 | vc->state.italic = 0; |
| 1616 | 1618 | vc->state.underline = 0; |
| 1617 | 1619 | vc->state.reverse = 0; |
| @@ -1652,11 +1654,11 @@ static void rgb_foreground(struct vc_data *vc, const struct rgb *c) · 34 unmodified lines | ||
| 1652 | 1654 | |
| 1653 | 1655 | if (hue == 7 && max <= 0x55) { |
| 1654 | 1656 | hue = 0; |
| 1655 | − vc->state.intensity = 2; | |
| 1657 | + vc->state.intensity = VCI_BOLD; | |
| 1656 | 1658 | } else if (max > 0xaa) |
| 1657 | − vc->state.intensity = 2; | |
| 1659 | + vc->state.intensity = VCI_BOLD; | |
| 1658 | 1660 | else |
| 1659 | − vc->state.intensity = 1; | |
| 1661 | + vc->state.intensity = VCI_NORMAL; | |
| 1660 | 1662 | |
| 1661 | 1663 | vc->state.color = (vc->state.color & 0xf0) | hue; |
| 1662 | 1664 | } |
| @@ -1715,10 +1717,10 @@ static void csi_m(struct vc_data *vc) · 52 unmodified lines | ||
| 1715 | 1717 | default_attr(vc); |
| 1716 | 1718 | break; |
| 1717 | 1719 | case 1: |
| 1718 | − vc->state.intensity = 2; | |
| 1720 | + vc->state.intensity = VCI_BOLD; | |
| 1719 | 1721 | break; |
| 1720 | 1722 | case 2: |
| 1721 | − vc->state.intensity = 0; | |
| 1723 | + vc->state.intensity = VCI_HALF_BRIGHT; | |
| 1722 | 1724 | break; |
| 1723 | 1725 | case 3: |
| 1724 | 1726 | vc->state.italic = 1; |
| @@ -1764,7 +1766,7 @@ static void csi_m(struct vc_data *vc) · 39 unmodified lines | ||
| 1764 | 1766 | vc->vc_toggle_meta = 1; |
| 1765 | 1767 | break; |
| 1766 | 1768 | case 22: |
| 1767 | − vc->state.intensity = 1; | |
| 1769 | + vc->state.intensity = VCI_NORMAL; | |
| 1768 | 1770 | break; |
| 1769 | 1771 | case 23: |
| 1770 | 1772 | vc->state.italic = 0; |
| @@ -1795,7 +1797,7 @@ static void csi_m(struct vc_data *vc) · 24 unmodified lines | ||
| 1795 | 1797 | default: |
| 1796 | 1798 | if (vc->vc_par[i] >= 90 && vc->vc_par[i] <= 107) { |
| 1797 | 1799 | if (vc->vc_par[i] < 100) |
| 1798 | − vc->state.intensity = 2; | |
| 1800 | + vc->state.intensity = VCI_BOLD; | |
| 1799 | 1801 | vc->vc_par[i] -= 60; |
| 1800 | 1802 | } |
| 1801 | 1803 | if (vc->vc_par[i] >= 30 && vc->vc_par[i] <= 37) |
| @@ -1934,7 +1936,7 @@ static void setterm_command(struct vc_data *vc) · 132 unmodified lines | ||
| 1934 | 1936 | case 2: /* set color for half intensity mode */ |
| 1935 | 1937 | if (vc->vc_can_do_color && vc->vc_par[1] < 16) { |
| 1936 | 1938 | vc->vc_halfcolor = color_table[vc->vc_par[1]]; |
| 1937 | − if (vc->state.intensity == 0) | |
| 1939 | + if (vc->state.intensity == VCI_HALF_BRIGHT) | |
| 1938 | 1940 | update_attr(vc); |
| 1939 | 1941 | } |
| 1940 | 1942 | break; |
| @@ -302,14 +302,14 @@ sisusbcon_deinit(struct vc_data *c) · 301 unmodified lines | ||
| 302 | 302 | |
| 303 | 303 | /* interface routine */ |
| 304 | 304 | static u8 |
| 305 | −sisusbcon_build_attr(struct vc_data *c, u8 color, u8 intensity, | |
| 305 | +sisusbcon_build_attr(struct vc_data *c, u8 color, enum vc_intensity intensity, | |
| 306 | 306 | u8 blink, u8 underline, u8 reverse, u8 unused) |
| 307 | 307 | { |
| 308 | 308 | u8 attr = color; |
| 309 | 309 | |
| 310 | 310 | if (underline) |
| 311 | 311 | attr = (attr & 0xf0) | c->vc_ulcolor; |
| 312 | − else if (intensity == 0) | |
| 312 | + else if (intensity == VCI_HALF_BRIGHT) | |
| 313 | 313 | attr = (attr & 0xf0) | c->vc_halfcolor; |
| 314 | 314 | |
| 315 | 315 | if (reverse) |
| @@ -320,7 +320,7 @@ sisusbcon_build_attr(struct vc_data *c, u8 color, u8 intensity, · 4 unmodified lines | ||
| 320 | 320 | if (blink) |
| 321 | 321 | attr ^= 0x80; |
| 322 | 322 | |
| 323 | − if (intensity == 2) | |
| 323 | + if (intensity == VCI_BOLD) | |
| 324 | 324 | attr ^= 0x08; |
| 325 | 325 | |
| 326 | 326 | return attr; |
| @@ -394,7 +394,8 @@ static inline u16 mda_convert_attr(u16 ch) · 393 unmodified lines | ||
| 394 | 394 | (ch & 0x00ff) | attr; |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | −static u8 mdacon_build_attr(struct vc_data *c, u8 color, u8 intensity, | |
| 397 | +static u8 mdacon_build_attr(struct vc_data *c, u8 color, | |
| 398 | + enum vc_intensity intensity, | |
| 398 | 399 | u8 blink, u8 underline, u8 reverse, u8 italic) |
| 399 | 400 | { |
| 400 | 401 | /* The attribute is just a bit vector: |
| @@ -405,7 +406,7 @@ static u8 mdacon_build_attr(struct vc_data *c, u8 color, u8 intensity, · 4 unmodified lines | ||
| 405 | 406 | * Bit 7 : blink |
| 406 | 407 | */ |
| 407 | 408 | |
| 408 | − return (intensity & 3) | | |
| 409 | + return (intensity & VCI_MASK) | | |
| 409 | 410 | ((underline & 1) << 2) | |
| 410 | 411 | ((reverse & 1) << 3) | |
| 411 | 412 | (!!italic << 4) | |
| @@ -288,7 +288,8 @@ static unsigned long sticon_getxy(struct vc_data *conp, unsigned long pos, · 287 unmodified lines | ||
| 288 | 288 | return ret; |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | −static u8 sticon_build_attr(struct vc_data *conp, u8 color, u8 intens, | |
| 291 | +static u8 sticon_build_attr(struct vc_data *conp, u8 color, | |
| 292 | + enum vc_intensity intens, | |
| 292 | 293 | u8 blink, u8 underline, u8 reverse, u8 italic) |
| 293 | 294 | { |
| 294 | 295 | u8 attr = ((color & 0x70) >> 1) | ((color & 7)); |
| @@ -629,7 +629,8 @@ static void vgacon_deinit(struct vc_data *c) · 628 unmodified lines | ||
| 629 | 629 | con_set_default_unimap(c); |
| 630 | 630 | } |
| 631 | 631 | |
| 632 | −static u8 vgacon_build_attr(struct vc_data *c, u8 color, u8 intensity, | |
| 632 | +static u8 vgacon_build_attr(struct vc_data *c, u8 color, | |
| 633 | + enum vc_intensity intensity, | |
| 633 | 634 | u8 blink, u8 underline, u8 reverse, u8 italic) |
| 634 | 635 | { |
| 635 | 636 | u8 attr = color; |
| @@ -639,7 +640,7 @@ static u8 vgacon_build_attr(struct vc_data *c, u8 color, u8 intensity, · 3 unmodified lines | ||
| 639 | 640 | attr = (attr & 0xF0) | c->vc_itcolor; |
| 640 | 641 | else if (underline) |
| 641 | 642 | attr = (attr & 0xf0) | c->vc_ulcolor; |
| 642 | − else if (intensity == 0) | |
| 643 | + else if (intensity == VCI_HALF_BRIGHT) | |
| 643 | 644 | attr = (attr & 0xf0) | c->vc_halfcolor; |
| 644 | 645 | } |
| 645 | 646 | if (reverse) |
| @@ -648,14 +649,14 @@ static u8 vgacon_build_attr(struct vc_data *c, u8 color, u8 intensity, · 2 unmodified lines | ||
| 648 | 649 | 0x77); |
| 649 | 650 | if (blink) |
| 650 | 651 | attr ^= 0x80; |
| 651 | − if (intensity == 2) | |
| 652 | + if (intensity == VCI_BOLD) | |
| 652 | 653 | attr ^= 0x08; |
| 653 | 654 | if (!vga_can_do_color) { |
| 654 | 655 | if (italic) |
| 655 | 656 | attr = (attr & 0xF8) | 0x02; |
| 656 | 657 | else if (underline) |
| 657 | 658 | attr = (attr & 0xf8) | 0x01; |
| 658 | − else if (intensity == 0) | |
| 659 | + else if (intensity == VCI_HALF_BRIGHT) | |
| 659 | 660 | attr = (attr & 0xf0) | 0x08; |
| 660 | 661 | } |
| 661 | 662 | return attr; |
| @@ -35,6 +35,8 @@ enum con_scroll { · 34 unmodified lines | ||
| 35 | 35 | SM_DOWN, |
| 36 | 36 | }; |
| 37 | 37 | |
| 38 | +enum vc_intensity; | |
| 39 | + | |
| 38 | 40 | /** |
| 39 | 41 | * struct consw - callbacks for consoles |
| 40 | 42 | * |
| @@ -74,7 +76,8 @@ struct consw { · 33 unmodified lines | ||
| 74 | 76 | void (*con_scrolldelta)(struct vc_data *vc, int lines); |
| 75 | 77 | int (*con_set_origin)(struct vc_data *vc); |
| 76 | 78 | void (*con_save_screen)(struct vc_data *vc); |
| 77 | − u8 (*con_build_attr)(struct vc_data *vc, u8 color, u8 intensity, | |
| 79 | + u8 (*con_build_attr)(struct vc_data *vc, u8 color, | |
| 80 | + enum vc_intensity intensity, | |
| 78 | 81 | u8 blink, u8 underline, u8 reverse, u8 italic); |
| 79 | 82 | void (*con_invert_region)(struct vc_data *vc, u16 *p, int count); |
| 80 | 83 | u16 *(*con_screen_pos)(struct vc_data *vc, int offset); |
| @@ -22,6 +22,13 @@ struct uni_screen; · 21 unmodified lines | ||
| 22 | 22 | |
| 23 | 23 | #define NPAR 16 |
| 24 | 24 | |
| 25 | +enum vc_intensity { | |
| 26 | + VCI_HALF_BRIGHT, | |
| 27 | + VCI_NORMAL, | |
| 28 | + VCI_BOLD, | |
| 29 | + VCI_MASK = 0x3, | |
| 30 | +}; | |
| 31 | + | |
| 25 | 32 | /** |
| 26 | 33 | * struct vc_state -- state of a VC |
| 27 | 34 | * @x: cursor's x-position |
| @@ -30,7 +37,7 @@ struct uni_screen; · 2 unmodified lines | ||
| 30 | 37 | * @G0_charset: what's G0 slot set to (like GRAF_MAP, LAT1_MAP) |
| 31 | 38 | * @G1_charset: what's G1 slot set to (like GRAF_MAP, LAT1_MAP) |
| 32 | 39 | * @charset: what character set to use (0=G0 or 1=G1) |
| 33 | − * @intensity: 0=half-bright, 1=normal, 2=bold | |
| 40 | + * @intensity: see enum vc_intensity for values | |
| 34 | 41 | * @reverse: reversed foreground/background colors |
| 35 | 42 | * |
| 36 | 43 | * These members are defined separately from struct vc_data as we save & |
| @@ -46,7 +53,7 @@ struct vc_state { · 9 unmodified lines | ||
| 46 | 53 | unsigned int charset : 1; |
| 47 | 54 | |
| 48 | 55 | /* attribute flags */ |
| 49 | − unsigned int intensity : 2; | |
| 56 | + enum vc_intensity intensity; | |
| 50 | 57 | unsigned int italic : 1; |
| 51 | 58 | unsigned int underline : 1; |
| 52 | 59 | unsigned int blink : 1; |