1212#include "screen.h"
1313#include "../cpu/ports.h"
1414#include "../libc/mem.h"
15+ #include "lowlevel_io.h"
1516#include "../libc/string.h"
1617
1718/* Декларирования частных функций */
@@ -31,6 +32,30 @@ int get_offset_col(int offset);
3132 * Если col, row отрицательные, то используем текущий оффсет
3233 */
3334void kprint_at (char * message , int col , int row , int color ) {
35+ struct { int clrcode ; int color ; } colors [] = {
36+ {.clrcode = WHITE_ON_BLACK_CLR_CODE , .color = WHITE_ON_BLACK },
37+ {.clrcode = BLUE_ON_BLACK_CLR_CODE , .color = BLUE_ON_BLACK },
38+ {.clrcode = GREEN_ON_BLACK_CLR_CODE , .color = GREEN_ON_BLACK },
39+ {.clrcode = CYAN_ON_BLACK_CLR_CODE , .color = CYAN_ON_BLACK },
40+ {.clrcode = RED_ON_BLACK_CLR_CODE , .color = RED_ON_BLACK },
41+ {.clrcode = MAGENTA_ON_BLACK_CLR_CODE , .color = MAGENTA_ON_BLACK },
42+ {.clrcode = BROWN_ON_BLACK_CLR_CODE , .color = BROWN_ON_BLACK },
43+ {.clrcode = LGREY_ON_BLACK_CLR_CODE , .color = LGREY_ON_BLACK },
44+ {.clrcode = DGREY_ON_BLACK_CLR_CODE , .color = DGREY_ON_BLACK },
45+ {.clrcode = LBLUE_ON_BLACK_CLR_CODE , .color = LBLUE_ON_BLACK },
46+ {.clrcode = LGREEN_ON_BLACK_CLR_CODE , .color = LGREEN_ON_BLACK },
47+ {.clrcode = LCYAN_ON_BLACK_CLR_CODE , .color = LCYAN_ON_BLACK },
48+ {.clrcode = LRED_ON_BLACK_CLR_CODE , .color = LRED_ON_BLACK },
49+ {.clrcode = LMAGENTA_ON_BLACK_CLR_CODE , .color = LMAGENTA_ON_BLACK },
50+ {.clrcode = YELLOW_ON_BLACK_CLR_CODE , .color = YELLOW_ON_BLACK },
51+ {.clrcode = WHITE_ON_BLUE_CLR_CODE , .color = WHITE_ON_BLUE },
52+ {.clrcode = WHITE_ON_RED_CLR_CODE , .color = WHITE_ON_RED },
53+ {.clrcode = RED_ON_WHITE_CLR_CODE , .color = RED_ON_WHITE },
54+ {.clrcode = BLUE_ON_WHITE_CLR_CODE , .color = BLUE_ON_WHITE },
55+ };
56+
57+ const int colors_length = sizeof (colors ) / sizeof (colors [0 ]);
58+
3459 /* Установка курсора и оффсета если если col, row отрицательные */
3560 int offset ;
3661 if (col >= 0 && row >= 0 )
@@ -43,44 +68,12 @@ void kprint_at(char *message, int col, int row, int color) {
4368 /* "Прокрутка" сообщения и его вывод */
4469 int i = 0 ;
4570 while (message [i ] != 0 ) {
46- if (color == WHITE_ON_BLACK_CLR_CODE ) {
47- offset = print_char (message [i ++ ], col , row , WHITE_ON_BLACK );
48- } else if (color == BLUE_ON_BLACK_CLR_CODE ) {
49- offset = print_char (message [i ++ ], col , row , BLUE_ON_BLACK );
50- } else if (color == GREEN_ON_BLACK_CLR_CODE ) {
51- offset = print_char (message [i ++ ], col , row , GREEN_ON_BLACK );
52- } else if (color == CYAN_ON_BLACK_CLR_CODE ) {
53- offset = print_char (message [i ++ ], col , row , CYAN_ON_BLACK );
54- } else if (color == RED_ON_BLACK_CLR_CODE ) {
55- offset = print_char (message [i ++ ], col , row , RED_ON_BLACK );
56- } else if (color == MAGENTA_ON_BLACK_CLR_CODE ) {
57- offset = print_char (message [i ++ ], col , row , MAGENTA_ON_BLACK );
58- } else if (color == BROWN_ON_BLACK_CLR_CODE ) {
59- offset = print_char (message [i ++ ], col , row , BROWN_ON_BLACK );
60- } else if (color == LGREY_ON_BLACK_CLR_CODE ) {
61- offset = print_char (message [i ++ ], col , row , LGREY_ON_BLACK );
62- } else if (color == DGREY_ON_BLACK_CLR_CODE ) {
63- offset = print_char (message [i ++ ], col , row , DGREY_ON_BLACK );
64- } else if (color == LBLUE_ON_BLACK_CLR_CODE ) {
65- offset = print_char (message [i ++ ], col , row , LBLUE_ON_BLACK );
66- } else if (color == LGREEN_ON_BLACK_CLR_CODE ) {
67- offset = print_char (message [i ++ ], col , row , LGREEN_ON_BLACK );
68- } else if (color == LCYAN_ON_BLACK_CLR_CODE ) {
69- offset = print_char (message [i ++ ], col , row , LCYAN_ON_BLACK );
70- } else if (color == LRED_ON_BLACK_CLR_CODE ) {
71- offset = print_char (message [i ++ ], col , row , LRED_ON_BLACK );
72- } else if (color == LMAGENTA_ON_BLACK_CLR_CODE ) {
73- offset = print_char (message [i ++ ], col , row , LMAGENTA_ON_BLACK );
74- } else if (color == YELLOW_ON_BLACK_CLR_CODE ) {
75- offset = print_char (message [i ++ ], col , row , YELLOW_ON_BLACK );
76- } else if (color == WHITE_ON_BLUE_CLR_CODE ) {
77- offset = print_char (message [i ++ ], col , row , WHITE_ON_BLUE );
78- } else if (color == WHITE_ON_RED_CLR_CODE ) {
79- offset = print_char (message [i ++ ], col , row , WHITE_ON_RED );
80- } else if (color == RED_ON_WHITE_CLR_CODE ) {
81- offset = print_char (message [i ++ ], col , row , RED_ON_WHITE );
82- } else if (color == BLUE_ON_WHITE_CLR_CODE ) {
83- offset = print_char (message [i ++ ], col , row , BLUE_ON_WHITE );
71+
72+ for (int j = 0 ; j < colors_length ; ++ j ) {
73+ if (color == colors [j ].clrcode ) {
74+ offset = print_char (message [i ++ ], col , row , colors [j ].color );
75+ break ;
76+ }
8477 }
8578
8679 /* Вычисление row/col для следующей итерации */
0 commit comments