@@ -24,27 +24,34 @@ static uint32_t fb_fg_color = 0xFFFFFF; // 白
2424static uint32_t fb_bg_color = 0x000000 ; // 黒
2525
2626static void allocate_gfx_buf_if_needed (void ) {
27- if (!use_framebuffer ) return ;
28- if (gfx_buf ) return ;
27+ if (!use_framebuffer )
28+ return ;
29+ if (gfx_buf )
30+ return ;
2931
3032 const bdf_font_t * font = bdf_get_font ();
3133 int fw = font ? (int )font -> width : 8 ;
3234 int fh = font ? (int )font -> height : 16 ;
33- if (fw <= 0 ) fw = 8 ;
34- if (fh <= 0 ) fh = 16 ;
35+ if (fw <= 0 )
36+ fw = 8 ;
37+ if (fh <= 0 )
38+ fh = 16 ;
3539
3640 gfx_cols = (int )(fb_width / fw );
3741 gfx_rows = (int )(fb_height / fh );
38- if (gfx_cols <= 0 ) gfx_cols = 1 ;
39- if (gfx_rows <= 0 ) gfx_rows = 1 ;
42+ if (gfx_cols <= 0 )
43+ gfx_cols = 1 ;
44+ if (gfx_rows <= 0 )
45+ gfx_rows = 1 ;
4046
4147 uint32_t size = (uint32_t )(gfx_cols * gfx_rows );
4248 gfx_buf = (char * )kmalloc (size );
4349 if (!gfx_buf ) {
4450 gfx_cols = gfx_rows = 0 ;
4551 return ;
4652 }
47- for (uint32_t i = 0 ; i < size ; i ++ ) gfx_buf [i ] = ' ' ;
53+ for (uint32_t i = 0 ; i < size ; i ++ )
54+ gfx_buf [i ] = ' ' ;
4855}
4956
5057/**
@@ -101,24 +108,28 @@ static void draw_char_fb(int x, int y, char c) {
101108
102109 const bdf_glyph_t * glyph = bdf_get_glyph ((uint32_t )(unsigned char )c );
103110
104- int char_width = (glyph && glyph -> width ) ? (int )glyph -> width : (int )font_info -> width ;
105- int char_height = (glyph && glyph -> height ) ? (int )glyph -> height : (int )font_info -> height ;
111+ int char_width = (glyph && glyph -> width ) ? (int )glyph -> width :
112+ (int )font_info -> width ;
113+ int char_height = (glyph && glyph -> height ) ? (int )glyph -> height :
114+ (int )font_info -> height ;
106115
107116 if (!glyph || c == ' ' ) {
108117 for (int row = 0 ; row < char_height ; row ++ ) {
109118 for (int col = 0 ; col < char_width ; col ++ ) {
110119 uint32_t pixel_x = x * char_width + col ;
111120 uint32_t pixel_y = y * char_height + row ;
112121 if (pixel_x < fb_width && pixel_y < fb_height ) {
113- uint32_t offset = pixel_y * fb_pitch + pixel_x ;
122+ uint32_t offset =
123+ pixel_y * fb_pitch + pixel_x ;
114124 framebuffer [offset ] = fb_bg_color ;
115125 }
116126 }
117127 }
118128 return ;
119129 }
120130
121- for (int row = 0 ; row < char_height && row < (int )MAX_GLYPH_HEIGHT ; row ++ ) {
131+ for (int row = 0 ; row < char_height && row < (int )MAX_GLYPH_HEIGHT ;
132+ row ++ ) {
122133 uint16_t bits = glyph -> bitmap [row ];
123134 for (int col = 0 ; col < char_width ; col ++ ) {
124135 uint32_t pixel_x = x * char_width + col ;
@@ -127,8 +138,12 @@ static void draw_char_fb(int x, int y, char c) {
127138 if (pixel_x < fb_width && pixel_y < fb_height ) {
128139 uint32_t offset = pixel_y * fb_pitch + pixel_x ;
129140 int bitpos = (char_width - 1 ) - col ;
130- uint16_t mask = (bitpos >= 0 && bitpos < 16 ) ? (1u << bitpos ) : 0 ;
131- framebuffer [offset ] = (bits & mask ) ? fb_fg_color : fb_bg_color ;
141+ uint16_t mask = (bitpos >= 0 && bitpos < 16 ) ?
142+ (1u << bitpos ) :
143+ 0 ;
144+ framebuffer [offset ] = (bits & mask ) ?
145+ fb_fg_color :
146+ fb_bg_color ;
132147 }
133148 }
134149 }
@@ -256,11 +271,13 @@ void new_line() {
256271 for (int r = 0 ; r < gfx_rows - 1 ; r ++ ) {
257272 char * dst = gfx_buf + r * line_size ;
258273 char * src = gfx_buf + (r + 1 ) * line_size ;
259- for (int c = 0 ; c < line_size ; c ++ ) dst [c ] = src [c ];
274+ for (int c = 0 ; c < line_size ; c ++ )
275+ dst [c ] = src [c ];
260276 }
261277 /* clear last line */
262278 char * last = gfx_buf + (gfx_rows - 1 ) * line_size ;
263- for (int c = 0 ; c < line_size ; c ++ ) last [c ] = ' ' ;
279+ for (int c = 0 ; c < line_size ; c ++ )
280+ last [c ] = ' ' ;
264281 cursor_row = gfx_rows - 1 ;
265282 console_render_text_to_fb ();
266283 }
@@ -281,7 +298,8 @@ void new_line() {
281298 } else {
282299 for (int i = 0 ; i < N_HISTORY - 1 ; ++ i ) {
283300 for (int c = 0 ; c < CONSOLE_COLS ; ++ c )
284- history [i ][c ] = history [i + 1 ][c ];
301+ history [i ][c ] =
302+ history [i + 1 ][c ];
285303 }
286304 for (int c = 0 ; c < CONSOLE_COLS ; ++ c )
287305 history [N_HISTORY - 1 ][c ] = linebuf [c ];
@@ -290,7 +308,8 @@ void new_line() {
290308 for (int r = 0 ; r < CONSOLE_ROWS - 1 ; r ++ ) {
291309 for (int c = 0 ; c < CONSOLE_COLS ; c ++ ) {
292310 int dst = (r * CONSOLE_COLS + c ) * 2 ;
293- int src = ((r + 1 ) * CONSOLE_COLS + c ) * 2 ;
311+ int src = ((r + 1 ) * CONSOLE_COLS + c ) *
312+ 2 ;
294313 video [dst ] = video [src ];
295314 video [dst + 1 ] = video [src + 1 ];
296315 }
@@ -303,8 +322,8 @@ void new_line() {
303322 }
304323 cursor_row = CONSOLE_ROWS - 1 ;
305324 history_offset = (history_lines > CONSOLE_ROWS ) ?
306- history_lines - CONSOLE_ROWS :
307- 0 ;
325+ history_lines - CONSOLE_ROWS :
326+ 0 ;
308327 if (use_framebuffer ) {
309328 console_render_text_to_fb ();
310329 }
@@ -430,9 +449,11 @@ void console_scroll_page_down(void) {
430449}
431450
432451void console_render_text_to_fb (void ) {
433- if (!use_framebuffer ) return ;
452+ if (!use_framebuffer )
453+ return ;
434454 const bdf_font_t * font_info = bdf_get_font ();
435- if (!font_info ) return ;
455+ if (!font_info )
456+ return ;
436457 /* If we have an allocated gfx buffer (sized to fb/font), render from it
437458 * so we can draw beyond 80x25. Otherwise fall back to video memory. */
438459 if (gfx_buf && gfx_cols > 0 && gfx_rows > 0 ) {
@@ -448,7 +469,8 @@ void console_render_text_to_fb(void) {
448469
449470 int fb_cols = (int )(fb_width / font_info -> width );
450471 int fb_rows = (int )(fb_height / font_info -> height );
451- if (fb_cols <= 0 || fb_rows <= 0 ) return ;
472+ if (fb_cols <= 0 || fb_rows <= 0 )
473+ return ;
452474
453475 int cols = (fb_cols < CONSOLE_COLS ) ? fb_cols : CONSOLE_COLS ;
454476 int rows = (fb_rows < CONSOLE_ROWS ) ? fb_rows : CONSOLE_ROWS ;
@@ -472,8 +494,10 @@ void console_post_font_init(void) {
472494 if (gfx_buf && gfx_cols > 0 && gfx_rows > 0 ) {
473495 /* copy existing video memory (80x25) into gfx_buf top-left */
474496 uint8_t * video = (uint8_t * )VIDEO_MEMORY ;
475- int copy_rows = (gfx_rows < CONSOLE_ROWS ) ? gfx_rows : CONSOLE_ROWS ;
476- int copy_cols = (gfx_cols < CONSOLE_COLS ) ? gfx_cols : CONSOLE_COLS ;
497+ int copy_rows = (gfx_rows < CONSOLE_ROWS ) ? gfx_rows :
498+ CONSOLE_ROWS ;
499+ int copy_cols = (gfx_cols < CONSOLE_COLS ) ? gfx_cols :
500+ CONSOLE_COLS ;
477501 for (int r = 0 ; r < copy_rows ; ++ r ) {
478502 for (int c = 0 ; c < copy_cols ; ++ c ) {
479503 int vpos = (r * CONSOLE_COLS + c ) * 2 ;
@@ -487,7 +511,8 @@ void console_post_font_init(void) {
487511 }
488512 /* if gfx_rows > CONSOLE_ROWS, clear remaining rows */
489513 for (int r = copy_rows ; r < gfx_rows ; ++ r ) {
490- for (int c = 0 ; c < gfx_cols ; ++ c ) gfx_buf [r * gfx_cols + c ] = ' ' ;
514+ for (int c = 0 ; c < gfx_cols ; ++ c )
515+ gfx_buf [r * gfx_cols + c ] = ' ' ;
491516 }
492517
493518 /* Render to framebuffer */
0 commit comments