@@ -61,6 +61,7 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) {
6161 #if CIRCUITPY_TERMINALIO
6262 displayio_tilegrid_t * grid = & supervisor_terminal_text_grid ;
6363 bool tall = height_px > width_px ;
64+ bool reset_tiles = false;
6465 uint16_t terminal_width_px = tall ? width_px : width_px - blinka_bitmap .width ;
6566 uint16_t terminal_height_px = tall ? height_px - blinka_bitmap .height : height_px ;
6667 uint16_t width_in_tiles = terminal_width_px / grid -> tile_width ;
@@ -81,37 +82,48 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) {
8182
8283 uint16_t total_tiles = width_in_tiles * height_in_tiles ;
8384
85+ // check if the terminal tile dimensions are the same
86+ if ((grid -> width_in_tiles != width_in_tiles ) ||
87+ (grid -> height_in_tiles != height_in_tiles )) {
88+ reset_tiles = true;
89+ }
8490 // Reuse the previous allocation if possible
8591 if (tilegrid_tiles ) {
8692 if (get_allocation_length (tilegrid_tiles ) != align32_size (total_tiles )) {
8793 free_memory (tilegrid_tiles );
8894 tilegrid_tiles = NULL ;
95+ reset_tiles = true;
8996 }
9097 }
9198 if (!tilegrid_tiles ) {
9299 tilegrid_tiles = allocate_memory (align32_size (total_tiles ), false, true);
100+ reset_tiles = true;
93101 if (!tilegrid_tiles ) {
94102 return ;
95103 }
96104 }
97- uint8_t * tiles = (uint8_t * )tilegrid_tiles -> ptr ;
98105
99- grid -> y = tall ? blinka_bitmap .height : 0 ;
100- grid -> x = tall ? 0 : blinka_bitmap .width ;
101- grid -> top_left_y = 0 ;
102- if (remaining_pixels > 0 ) {
103- grid -> y -= (grid -> tile_height - remaining_pixels );
104- }
105- grid -> width_in_tiles = width_in_tiles ;
106- grid -> height_in_tiles = height_in_tiles ;
107- assert (width_in_tiles > 0 );
108- assert (height_in_tiles > 0 );
109- grid -> pixel_width = width_in_tiles * grid -> tile_width ;
110- grid -> pixel_height = height_in_tiles * grid -> tile_height ;
111- grid -> tiles = tiles ;
112- grid -> full_change = true;
106+ if (reset_tiles ) {
107+ uint8_t * tiles = (uint8_t * )tilegrid_tiles -> ptr ;
108+
109+ grid -> y = tall ? blinka_bitmap .height : 0 ;
110+ grid -> x = tall ? 0 : blinka_bitmap .width ;
111+ grid -> top_left_y = 0 ;
112+ if (remaining_pixels > 0 ) {
113+ grid -> y -= (grid -> tile_height - remaining_pixels );
114+ }
115+ grid -> width_in_tiles = width_in_tiles ;
116+ grid -> height_in_tiles = height_in_tiles ;
117+ assert (width_in_tiles > 0 );
118+ assert (height_in_tiles > 0 );
119+ grid -> pixel_width = width_in_tiles * grid -> tile_width ;
120+ grid -> pixel_height = height_in_tiles * grid -> tile_height ;
121+ grid -> tiles = tiles ;
122+
123+ grid -> full_change = true;
113124
114- common_hal_terminalio_terminal_construct (& supervisor_terminal , grid , & supervisor_terminal_font );
125+ common_hal_terminalio_terminal_construct (& supervisor_terminal , grid , & supervisor_terminal_font );
126+ }
115127 #endif
116128
117129 circuitpython_splash .scale = scale ;
0 commit comments