@@ -2453,16 +2453,32 @@ static void do_sgb(Emulator* e) {
24532453 u8 palin = pal & 3 , palon = (pal >> 2 ) & 3 , palout = (pal >> 4 ) & 3 ;
24542454 u8 l = SGB .data [4 + i * 6 ], t = SGB .data [5 + i * 6 ],
24552455 r = SGB .data [6 + i * 6 ], b = SGB .data [7 + i * 6 ];
2456- if (info & 1 ) { // colors inside region
2457- set_sgb_attr_block (e , l , t , r , b , palin );
2456+
2457+ Bool inside = info & 1 ;
2458+ Bool border = info & 2 ;
2459+ Bool outside = info & 4 ;
2460+
2461+ if (inside && !border && !outside ) {
2462+ border = TRUE;
2463+ palon = palin ;
2464+ } else if (outside && !border && !inside ) {
2465+ border = TRUE;
2466+ palon = palout ;
24582467 }
2459- if (info & 2 ) { // colors on region border
2468+
2469+ Bool has_inner = (r - l ) >= 2 && (b - t ) >= 2 ;
2470+ if (inside && has_inner ) { // colors inside region
2471+ set_sgb_attr_block (e , l + 1 , t + 1 , r - 1 , b - 1 , palin );
2472+ }
2473+
2474+ if (border ) { // colors on region border
24602475 set_sgb_attr_block (e , l , t , r , t , palon ); // top
24612476 set_sgb_attr_block (e , l , t , l , b , palon ); // left
24622477 set_sgb_attr_block (e , l , b , r , b , palon ); // bottom
24632478 set_sgb_attr_block (e , r , t , r , b , palon ); // right
24642479 }
2465- if (info & 4 ) { // colors outside region
2480+
2481+ if (outside ) { // colors outside region
24662482 set_sgb_attr_block (e , 0 , 0 , 19 , t - 1 , palout ); // top
24672483 set_sgb_attr_block (e , 0 , t , l - 1 , b , palout ); // left
24682484 set_sgb_attr_block (e , 0 , b + 1 , 19 , 17 , palout ); // bottom
0 commit comments