@@ -61,6 +61,7 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) {
61
61
#if CIRCUITPY_TERMINALIO
62
62
displayio_tilegrid_t * grid = & supervisor_terminal_text_grid ;
63
63
bool tall = height_px > width_px ;
64
+ bool reset_tiles = false;
64
65
uint16_t terminal_width_px = tall ? width_px : width_px - blinka_bitmap .width ;
65
66
uint16_t terminal_height_px = tall ? height_px - blinka_bitmap .height : height_px ;
66
67
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) {
81
82
82
83
uint16_t total_tiles = width_in_tiles * height_in_tiles ;
83
84
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
+ }
84
90
// Reuse the previous allocation if possible
85
91
if (tilegrid_tiles ) {
86
92
if (get_allocation_length (tilegrid_tiles ) != align32_size (total_tiles )) {
87
93
free_memory (tilegrid_tiles );
88
94
tilegrid_tiles = NULL ;
95
+ reset_tiles = true;
89
96
}
90
97
}
91
98
if (!tilegrid_tiles ) {
92
99
tilegrid_tiles = allocate_memory (align32_size (total_tiles ), false, true);
100
+ reset_tiles = true;
93
101
if (!tilegrid_tiles ) {
94
102
return ;
95
103
}
96
104
}
97
- uint8_t * tiles = (uint8_t * )tilegrid_tiles -> ptr ;
98
105
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;
113
124
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
+ }
115
127
#endif
116
128
117
129
circuitpython_splash .scale = scale ;
0 commit comments