|  |  | @ -116,7 +116,12 @@ bool Screen::inGraphicsMode() | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | static bool doSetTile_map(const Pen &pen, int x, int y) { |  |  |  | static bool doSetTile_map(const Pen &pen, int x, int y) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     size_t max_index = gps->main_viewport->dim_x * gps->main_viewport->dim_y - 1; | 
			
		
	
		
		
			
				
					
					|  |  |  |     size_t index = (x * gps->main_viewport->dim_y) + y; |  |  |  |     size_t index = (x * gps->main_viewport->dim_y) + y; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     if (index < 0 || index > max_index) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         return false; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     long texpos = pen.tile; |  |  |  |     long texpos = pen.tile; | 
			
		
	
		
		
			
				
					
					|  |  |  |     if (texpos == 0) { |  |  |  |     if (texpos == 0) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         texpos = init->font.large_font_texpos[(uint8_t)pen.ch]; |  |  |  |         texpos = init->font.large_font_texpos[(uint8_t)pen.ch]; | 
			
		
	
	
		
		
			
				
					|  |  | @ -207,39 +212,83 @@ bool Screen::paintTile(const Pen &pen, int x, int y, bool map) | 
			
		
	
		
		
			
				
					
					|  |  |  |     return true; |  |  |  |     return true; | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | static Pen doGetTile_default(int x, int y, bool map) |  |  |  | static Pen doGetTile_map(int x, int y) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | { |  |  |  |     size_t max_index = gps->main_viewport->dim_x * gps->main_viewport->dim_y - 1; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     auto dim = Screen::getWindowSize(); |  |  |  |     size_t index = (x * gps->main_viewport->dim_y) + y; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     if (x < 0 || x >= dim.x || y < 0 || y >= dim.y) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         return Pen(0,0,0,-1); |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | /* TODO: understand how this changes for v50
 |  |  |  |     if (index < 0 || index > max_index) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     int index = x*dim.y + y; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     auto screen = gps->screen + index*4; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     if (screen[3] & 0x80) |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         return Pen(0, 0, 0, -1); |  |  |  |         return Pen(0, 0, 0, -1); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     Pen pen( |  |  |  |     int tile = gps->main_viewport->screentexpos[index]; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         screen[0], screen[1], screen[2], screen[3]?true:false, |  |  |  |     if (tile == 0) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         gps->screentexpos[index] |  |  |  |         tile = gps->main_viewport->screentexpos_item[index]; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     ); |  |  |  |     if (tile == 0) | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         tile = gps->main_viewport->screentexpos_building_one[index]; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     if (tile == 0) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         tile = gps->main_viewport->screentexpos_background_two[index]; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     if (tile == 0) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         tile = gps->main_viewport->screentexpos_background[index]; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     if (pen.tile) |  |  |  |     char ch = 0; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |     uint8_t fg = 0; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         if (gps->screentexpos_grayscale[index]) |  |  |  |     uint8_t bg = 0; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         { |  |  |  |     return Pen(ch, fg, bg, tile, false); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             pen.tile_mode = Screen::Pen::TileColor; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             pen.tile_fg = gps->screentexpos_cf[index]; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             pen.tile_bg = gps->screentexpos_cbr[index]; |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  |         else if (gps->screentexpos_addcolor[index]) |  |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         { |  |  |  | static uint8_t to_16_bit_color(uint8_t  *rgb) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             pen.tile_mode = Screen::Pen::CharColor; |  |  |  |     for (uint8_t c = 0; c < 16; ++c) { | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         if (rgb[0] == gps->uccolor[c][0] && | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 rgb[1] == gps->uccolor[c][1] && | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 rgb[2] == gps->uccolor[c][2]) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             return c; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     return 0; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | static Pen doGetTile_default(int x, int y, bool map) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     if (x < 0 || y < 0) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         return Pen(0, 0, 0, -1); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     bool use_graphics = Screen::inGraphicsMode(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     if (map && use_graphics) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         return doGetTile_map(x, y); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     size_t index = (x * gps->dimy) + y; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     uint8_t *screen = &gps->screen[index * 8]; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     if (screen > gps->screen_limit) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         return Pen(0, 0, 0, -1); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     long *texpos = &gps->screentexpos[index]; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     uint32_t *flag = &gps->screentexpos_flag[index]; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     if (gps->top_in_use && | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             (gps->screen_top[index * 8] || | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |              (use_graphics && gps->screentexpos_top[index]))) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         screen = &gps->screen_top[index * 8]; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         texpos = &gps->screentexpos_top[index]; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         flag = &gps->screentexpos_top_flag[index]; | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     char ch = *screen; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     uint8_t fg = to_16_bit_color(&screen[1]); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     uint8_t bg = to_16_bit_color(&screen[4]); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     int tile = 0; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     if (use_graphics) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         tile = *texpos; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     if (*flag & 1) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         // TileColor
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         return Pen(ch, fg&7, bg, !!(fg&8), tile, fg, bg); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } else if (*flag & 2) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         // CharColor
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         return Pen(ch, fg, bg, tile, true); | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     return pen; |  |  |  |     // AsIs
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | */ return Pen(0,0,0,-1); |  |  |  |     return Pen(ch, fg, bg, tile, false); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | GUI_HOOK_DEFINE(Screen::Hooks::get_tile, doGetTile_default); |  |  |  | GUI_HOOK_DEFINE(Screen::Hooks::get_tile, doGetTile_default); | 
			
		
	
	
		
		
			
				
					|  |  | 
 |