mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-03-03 07:29:23 +00:00
Bare metal VGA: fix mapping of ECMA-48 colors to VGA colors (#622)
See https://github.com/jart/cosmopolitan/pull/613#issuecomment-1247490693
This commit is contained in:
parent
4c40c500b8
commit
cdf9e8c8a3
1 changed files with 32 additions and 2 deletions
|
@ -605,6 +605,36 @@ static void TtyCsiN(struct Tty *tty) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map the given ECMA-48 / VT100 SGR color code to a color code for a VGA
|
||||||
|
* character attribute. More precisely, map
|
||||||
|
*
|
||||||
|
* red──┐
|
||||||
|
* green─┐│
|
||||||
|
* blue┐││
|
||||||
|
* intensity│││
|
||||||
|
* ││││
|
||||||
|
* 3210
|
||||||
|
*
|
||||||
|
* to
|
||||||
|
*
|
||||||
|
* blue──┐
|
||||||
|
* green─┐│
|
||||||
|
* red┐││
|
||||||
|
* intensity│││
|
||||||
|
* ││││
|
||||||
|
* 3210
|
||||||
|
*/
|
||||||
|
static uint8_t TtyMapEcma48Color(uint8_t color)
|
||||||
|
{
|
||||||
|
switch (color & 0b101) {
|
||||||
|
case 0b100:
|
||||||
|
case 0b001:
|
||||||
|
color ^= 0b101;
|
||||||
|
}
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map the given (R, G, B) triplet to one of the 16 basic foreground colors
|
* Map the given (R, G, B) triplet to one of the 16 basic foreground colors
|
||||||
* or one of the 16 background colors.
|
* or one of the 16 background colors.
|
||||||
|
@ -765,7 +795,7 @@ static void TtySelectGraphicsRendition(struct Tty *tty) {
|
||||||
code[0] += 8;
|
code[0] += 8;
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
case 30 ... 37:
|
case 30 ... 37:
|
||||||
tty->fg = code[0] - 30;
|
tty->fg = TtyMapEcma48Color(code[0] - 30);
|
||||||
tty->pr |= kTtyFg;
|
tty->pr |= kTtyFg;
|
||||||
tty->pr &= ~kTtyTrue;
|
tty->pr &= ~kTtyTrue;
|
||||||
break;
|
break;
|
||||||
|
@ -774,7 +804,7 @@ static void TtySelectGraphicsRendition(struct Tty *tty) {
|
||||||
code[0] += 8;
|
code[0] += 8;
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
case 40 ... 47:
|
case 40 ... 47:
|
||||||
tty->bg = code[0] - 40;
|
tty->bg = TtyMapEcma48Color(code[0] - 40);
|
||||||
tty->pr |= kTtyBg;
|
tty->pr |= kTtyBg;
|
||||||
tty->pr &= ~kTtyTrue;
|
tty->pr &= ~kTtyTrue;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Reference in a new issue