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