|
|
e4c2ac |
/*********************************************************/
|
|
|
e4c2ac |
|
|
|
e4c2ac |
|
|
|
e4c2ac |
|
|
|
e4c2ac |
/*********************************************************/
|
|
|
e4c2ac |
|
|
|
e4c2ac |
#include <psxtypes/psxtypes.h>
|
|
|
e4c2ac |
#include <ntcon/ntcon.h>
|
|
|
e4c2ac |
|
|
|
e4c2ac |
#include <ptycon/ptycon.h>
|
|
|
e4c2ac |
#include "ptycon_bridge_impl.h"
|
|
|
e4c2ac |
#include "ptycon_driver_impl.h"
|
|
|
e4c2ac |
|
|
|
e4c2ac |
|
|
|
e4c2ac |
static ptyc_term_handler sgr_illegal_code;
|
|
|
e4c2ac |
static ptyc_term_handler sgr_default;
|
|
|
e4c2ac |
static ptyc_term_handler sgr_set_ansi_foreground_color;
|
|
|
e4c2ac |
static ptyc_term_handler sgr_set_ansi_background_color;
|
|
|
e4c2ac |
static ptyc_term_handler sgr_set_aixterm_foreground_color;
|
|
|
e4c2ac |
static ptyc_term_handler sgr_set_aixterm_background_color;
|
|
|
e4c2ac |
|
|
|
e4c2ac |
static const uint16_t ansi_foreground_colors[10] = {
|
|
|
e4c2ac |
NT_FOREGROUND_BLACK,
|
|
|
e4c2ac |
NT_FOREGROUND_RED,
|
|
|
e4c2ac |
NT_FOREGROUND_GREEN,
|
|
|
e4c2ac |
NT_FOREGROUND_YELLOW,
|
|
|
e4c2ac |
NT_FOREGROUND_BLUE,
|
|
|
e4c2ac |
NT_FOREGROUND_MAGENTA,
|
|
|
e4c2ac |
NT_FOREGROUND_CYAN,
|
|
|
e4c2ac |
NT_FOREGROUND_WHITE,
|
|
|
e4c2ac |
0,
|
|
|
e4c2ac |
NT_FOREGROUND_WHITE
|
|
|
e4c2ac |
};
|
|
|
e4c2ac |
|
|
|
e4c2ac |
|
|
|
e4c2ac |
static const uint16_t ansi_background_colors[10] = {
|
|
|
e4c2ac |
NT_BACKGROUND_BLACK,
|
|
|
e4c2ac |
NT_BACKGROUND_RED,
|
|
|
e4c2ac |
NT_BACKGROUND_GREEN,
|
|
|
e4c2ac |
NT_BACKGROUND_YELLOW,
|
|
|
e4c2ac |
NT_BACKGROUND_BLUE,
|
|
|
e4c2ac |
NT_BACKGROUND_MAGENTA,
|
|
|
e4c2ac |
NT_BACKGROUND_CYAN,
|
|
|
e4c2ac |
NT_BACKGROUND_WHITE,
|
|
|
e4c2ac |
0,
|
|
|
e4c2ac |
NT_BACKGROUND_BLACK
|
|
|
e4c2ac |
};
|
|
|
e4c2ac |
|
|
|
e4c2ac |
|
|
|
e4c2ac |
static const uint16_t aixterm_foreground_colors[8] = {
|
|
|
e4c2ac |
NT_FOREGROUND_INTENSITY | NT_FOREGROUND_BLACK,
|
|
|
e4c2ac |
NT_FOREGROUND_INTENSITY | NT_FOREGROUND_RED,
|
|
|
e4c2ac |
NT_FOREGROUND_INTENSITY | NT_FOREGROUND_GREEN,
|
|
|
e4c2ac |
NT_FOREGROUND_INTENSITY | NT_FOREGROUND_YELLOW,
|
|
|
e4c2ac |
NT_FOREGROUND_INTENSITY | NT_FOREGROUND_BLUE,
|
|
|
e4c2ac |
NT_FOREGROUND_INTENSITY | NT_FOREGROUND_MAGENTA,
|
|
|
e4c2ac |
NT_FOREGROUND_INTENSITY | NT_FOREGROUND_CYAN,
|
|
|
e4c2ac |
NT_FOREGROUND_INTENSITY | NT_FOREGROUND_WHITE
|
|
|
e4c2ac |
};
|
|
|
e4c2ac |
|
|
|
e4c2ac |
|
|
|
e4c2ac |
static const uint16_t aixterm_background_colors[8] = {
|
|
|
e4c2ac |
NT_BACKGROUND_INTENSITY | NT_BACKGROUND_BLACK,
|
|
|
e4c2ac |
NT_BACKGROUND_INTENSITY | NT_BACKGROUND_RED,
|
|
|
e4c2ac |
NT_BACKGROUND_INTENSITY | NT_BACKGROUND_GREEN,
|
|
|
e4c2ac |
NT_BACKGROUND_INTENSITY | NT_BACKGROUND_YELLOW,
|
|
|
e4c2ac |
NT_BACKGROUND_INTENSITY | NT_BACKGROUND_BLUE,
|
|
|
e4c2ac |
NT_BACKGROUND_INTENSITY | NT_BACKGROUND_MAGENTA,
|
|
|
e4c2ac |
NT_BACKGROUND_INTENSITY | NT_BACKGROUND_CYAN,
|
|
|
e4c2ac |
NT_BACKGROUND_INTENSITY | NT_BACKGROUND_WHITE
|
|
|
e4c2ac |
};
|
|
|
e4c2ac |
|
|
|
e4c2ac |
|
|
|
e4c2ac |
ptyc_term_handler * const ptyc_sgr_handlers[PTYC_SGR_ARRAY_SIZE] = {
|
|
|
e4c2ac |
sgr_default,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_set_ansi_foreground_color,
|
|
|
e4c2ac |
sgr_set_ansi_foreground_color,
|
|
|
e4c2ac |
sgr_set_ansi_foreground_color,
|
|
|
e4c2ac |
sgr_set_ansi_foreground_color,
|
|
|
e4c2ac |
sgr_set_ansi_foreground_color,
|
|
|
e4c2ac |
sgr_set_ansi_foreground_color,
|
|
|
e4c2ac |
sgr_set_ansi_foreground_color,
|
|
|
e4c2ac |
sgr_set_ansi_foreground_color,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_set_ansi_foreground_color,
|
|
|
e4c2ac |
sgr_set_ansi_background_color,
|
|
|
e4c2ac |
sgr_set_ansi_background_color,
|
|
|
e4c2ac |
sgr_set_ansi_background_color,
|
|
|
e4c2ac |
sgr_set_ansi_background_color,
|
|
|
e4c2ac |
sgr_set_ansi_background_color,
|
|
|
e4c2ac |
sgr_set_ansi_background_color,
|
|
|
e4c2ac |
sgr_set_ansi_background_color,
|
|
|
e4c2ac |
sgr_set_ansi_background_color,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_set_ansi_background_color,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_set_aixterm_foreground_color,
|
|
|
e4c2ac |
sgr_set_aixterm_foreground_color,
|
|
|
e4c2ac |
sgr_set_aixterm_foreground_color,
|
|
|
e4c2ac |
sgr_set_aixterm_foreground_color,
|
|
|
e4c2ac |
sgr_set_aixterm_foreground_color,
|
|
|
e4c2ac |
sgr_set_aixterm_foreground_color,
|
|
|
e4c2ac |
sgr_set_aixterm_foreground_color,
|
|
|
e4c2ac |
sgr_set_aixterm_foreground_color,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_illegal_code,
|
|
|
e4c2ac |
sgr_set_aixterm_background_color,
|
|
|
e4c2ac |
sgr_set_aixterm_background_color,
|
|
|
e4c2ac |
sgr_set_aixterm_background_color,
|
|
|
e4c2ac |
sgr_set_aixterm_background_color,
|
|
|
e4c2ac |
sgr_set_aixterm_background_color,
|
|
|
e4c2ac |
sgr_set_aixterm_background_color,
|
|
|
e4c2ac |
sgr_set_aixterm_background_color,
|
|
|
e4c2ac |
sgr_set_aixterm_background_color,
|
|
|
e4c2ac |
sgr_illegal_code
|
|
|
e4c2ac |
};
|
|
|
e4c2ac |
|
|
|
e4c2ac |
|
|
|
e4c2ac |
static void * __fastcall sgr_illegal_code(struct ptyc_term_ctx * tctx)
|
|
|
e4c2ac |
{
|
|
|
e4c2ac |
(void)tctx;
|
|
|
e4c2ac |
return 0;
|
|
|
e4c2ac |
}
|
|
|
e4c2ac |
|
|
|
e4c2ac |
|
|
|
e4c2ac |
static void * __fastcall sgr_default(struct ptyc_term_ctx * tctx)
|
|
|
e4c2ac |
{
|
|
|
e4c2ac |
tctx->background = NT_BACKGROUND_BLACK;
|
|
|
e4c2ac |
tctx->foreground = NT_FOREGROUND_WHITE;
|
|
|
e4c2ac |
|
|
|
e4c2ac |
ntcon->set_console_text_attribute(
|
|
|
e4c2ac |
tctx->hout,
|
|
|
e4c2ac |
tctx->background | tctx->foreground);
|
|
|
e4c2ac |
|
|
|
e4c2ac |
return 0;
|
|
|
e4c2ac |
}
|
|
|
e4c2ac |
|
|
|
e4c2ac |
|
|
|
e4c2ac |
static void * __fastcall sgr_set_ansi_foreground_color(struct ptyc_term_ctx * tctx)
|
|
|
e4c2ac |
{
|
|
|
e4c2ac |
int color_idx;
|
|
|
e4c2ac |
const int param_base = 30;
|
|
|
e4c2ac |
|
|
|
e4c2ac |
color_idx = *tctx->ctrl_mark - param_base;
|
|
|
e4c2ac |
tctx->foreground = ansi_foreground_colors[color_idx];
|
|
|
e4c2ac |
|
|
|
e4c2ac |
ntcon->set_console_text_attribute(
|
|
|
e4c2ac |
tctx->hout,
|
|
|
e4c2ac |
tctx->background | tctx->foreground);
|
|
|
e4c2ac |
|
|
|
e4c2ac |
return 0;
|
|
|
e4c2ac |
}
|
|
|
e4c2ac |
|
|
|
e4c2ac |
|
|
|
e4c2ac |
static void * __fastcall sgr_set_ansi_background_color(struct ptyc_term_ctx * tctx)
|
|
|
e4c2ac |
{
|
|
|
e4c2ac |
int color_idx;
|
|
|
e4c2ac |
const int param_base = 40;
|
|
|
e4c2ac |
|
|
|
e4c2ac |
color_idx = *tctx->ctrl_mark - param_base;
|
|
|
e4c2ac |
tctx->background = ansi_background_colors[color_idx];
|
|
|
e4c2ac |
|
|
|
e4c2ac |
ntcon->set_console_text_attribute(
|
|
|
e4c2ac |
tctx->hout,
|
|
|
e4c2ac |
tctx->background | tctx->foreground);
|
|
|
e4c2ac |
|
|
|
e4c2ac |
return 0;
|
|
|
e4c2ac |
}
|
|
|
e4c2ac |
|
|
|
e4c2ac |
|
|
|
e4c2ac |
static void * __fastcall sgr_set_aixterm_foreground_color(struct ptyc_term_ctx * tctx)
|
|
|
e4c2ac |
{
|
|
|
e4c2ac |
int color_idx;
|
|
|
e4c2ac |
const int param_base = 90;
|
|
|
e4c2ac |
|
|
|
e4c2ac |
color_idx = *tctx->ctrl_mark - param_base;
|
|
|
e4c2ac |
tctx->foreground = aixterm_foreground_colors[color_idx];
|
|
|
e4c2ac |
|
|
|
e4c2ac |
ntcon->set_console_text_attribute(
|
|
|
e4c2ac |
tctx->hout,
|
|
|
e4c2ac |
tctx->background | tctx->foreground);
|
|
|
e4c2ac |
|
|
|
e4c2ac |
return 0;
|
|
|
e4c2ac |
}
|
|
|
e4c2ac |
|
|
|
e4c2ac |
|
|
|
e4c2ac |
static void * __fastcall sgr_set_aixterm_background_color(struct ptyc_term_ctx * tctx)
|
|
|
e4c2ac |
{
|
|
|
e4c2ac |
int color_idx;
|
|
|
e4c2ac |
const int param_base = 100;
|
|
|
e4c2ac |
|
|
|
e4c2ac |
color_idx = *tctx->ctrl_mark - param_base;
|
|
|
e4c2ac |
tctx->background = ansi_background_colors[color_idx];
|
|
|
e4c2ac |
|
|
|
e4c2ac |
ntcon->set_console_text_attribute(
|
|
|
e4c2ac |
tctx->hout,
|
|
|
e4c2ac |
tctx->background | tctx->foreground);
|
|
|
e4c2ac |
|
|
|
e4c2ac |
return 0;
|
|
|
e4c2ac |
}
|