diff --git a/src/buttons_effects.c b/src/buttons_effects.c index 0b678185..f1549f75 100644 --- a/src/buttons_effects.c +++ b/src/buttons_effects.c @@ -181,6 +181,7 @@ static int Check_block_constraints(enum IMAGE_MODES mode) int block_width = 8, block_height = 8, max_colors = 2; // default values int error_count = 0; byte errcol = 17; + byte pal_mask; switch (mode) { @@ -198,9 +199,14 @@ static int Check_block_constraints(enum IMAGE_MODES mode) max_colors = 4; errcol = 33; break; + case IMAGE_MODE_MEGADRIVE: + max_colors = 16; + errcol = 65; + break; default: return -1; // unsupported mode } + pal_mask = ~(max_colors - 1); for (y = 0; y <= Main.image_height - block_height; y += block_height) { @@ -215,11 +221,11 @@ static int Check_block_constraints(enum IMAGE_MODES mode) { int i; byte col = Read_pixel_from_layer(0, x+x2, y+y2); - if (mode == IMAGE_MODE_GBC) + if (mode == IMAGE_MODE_GBC || mode == IMAGE_MODE_MEGADRIVE) { if (count == 0) c[count++] = col; - else if ((col & ~3) != (c[0] & ~3)) // compare palettes + else if ((col & pal_mask) != (c[0] & pal_mask)) // compare palettes { if (Main.backups->Pages->Nb_layers < 2) Add_layer(Main.backups, 1); @@ -566,6 +572,7 @@ void Button_Constraint_menu(void) } modes[] = { {IMAGE_MODE_ZX, "ZX Spectrum", "2 colors per 8x8 block", 1}, // 256x192 {IMAGE_MODE_GBC, "Game Boy Color","4 colors per 8x8 block", 1}, // 160x144 to 256x256 + {IMAGE_MODE_MEGADRIVE,"Sega MegaDrive","16colors per 8x8 block",1}, // 256x224 to 1024x256 {IMAGE_MODE_THOMSON, "40col (MO/TO)", "2 colors per 8x1 block", 1}, // 320x200 {IMAGE_MODE_EGX, "EGX (CPC)", "Alternate Mode0/Mode1 ", 0}, // 320x200 {IMAGE_MODE_EGX2, "EGX2 (CPC)", "Alternate Mode1/Mode2 ", 0}, // 640x200 @@ -620,7 +627,7 @@ void Button_Constraint_menu(void) } else if (clicked_button == 3) { - if (Selected_Constraint_Mode == IMAGE_MODE_GBC) + if (Selected_Constraint_Mode == IMAGE_MODE_GBC || Selected_Constraint_Mode == IMAGE_MODE_MEGADRIVE) set_palette = 1; // activate palette back when switching from GBC Selected_Constraint_Mode = Window_attribute2; for (i = 0; i < sizeof(modes)/sizeof(modes[0]) ; i++) @@ -632,7 +639,7 @@ void Button_Constraint_menu(void) Display_cursor(); break; } - if (Selected_Constraint_Mode == IMAGE_MODE_GBC) + if (Selected_Constraint_Mode == IMAGE_MODE_GBC || Selected_Constraint_Mode == IMAGE_MODE_MEGADRIVE) set_palette = 0; } else if (clicked_button == 4) // palette @@ -714,6 +721,7 @@ void Button_Constraint_menu(void) case IMAGE_MODE_ZX: case IMAGE_MODE_GBC: case IMAGE_MODE_C64HIRES: + case IMAGE_MODE_MEGADRIVE: Snap_width = 8; Snap_height = 8; break; @@ -759,6 +767,13 @@ void Button_Constraint_menu(void) Fore_color = 7; Back_color = 0; break; + case IMAGE_MODE_MEGADRIVE: // 64 colors among 512 + memset(Main.palette + 64, 0, sizeof(T_Components) * (256 - 64)); + Main.palette[65].R = 255; // for color clashes + First_color_in_palette = 0; + Fore_color = 15; + Back_color = 0; + break; case IMAGE_MODE_GBC: // 32 colors among 32768 memset(Main.palette + 32, 0, sizeof(T_Components) * (256 - 32)); Main.palette[33].R = 255; // for color clashes diff --git a/src/const.h b/src/const.h index 1b30205b..1ff47794 100644 --- a/src/const.h +++ b/src/const.h @@ -631,6 +631,7 @@ enum IMAGE_MODES IMAGE_MODE_C64FLI, ///< C64 Flexible Line Interpretation IMAGE_MODE_HGR, ///< Apple 2 HGR IMAGE_MODE_DHGR, ///< Apple 2 DHGR + IMAGE_MODE_MEGADRIVE, ///< Sega Mega Drive / Genesis }; /// Circle / Ellipse Modes diff --git a/src/graph.c b/src/graph.c index a1ccb365..b314a528 100644 --- a/src/graph.c +++ b/src/graph.c @@ -3413,24 +3413,33 @@ done: /// Paint a pixel with GBC constraints /// /// Same 4 color palette for all pixels in a 8x8 block. +/// +/// Megadrive constraints are nearly the same : same 16 color palette in a 8x8 tile static void Pixel_in_screen_gbc_with_opt_preview(word x,word y,byte color,int preview) { word startx = x & ~7; word starty = y & ~7; word x2, y2; byte palette; + byte col_mask, pal_mask; + + if (Main.backups->Pages->Image_mode == IMAGE_MODE_MEGADRIVE) + col_mask = 15; + else + col_mask = 3; + pal_mask = ~col_mask; // first set the pixel Pixel_in_screen_layered_with_opt_preview(x,y,color,preview); - palette = color & ~3; + palette = color & pal_mask; // force all pixels of the block to the same palette for (y2 = 0; y2 < 8; y2++) { for (x2 = 0; x2 < 8; x2++) { byte col = Read_pixel_from_current_layer(startx+x2, starty+y2); - if ((col & ~3) != palette) - Pixel_in_screen_layered_with_opt_preview(startx+x2, starty+y2, palette | (col & 3), preview); + if ((col & pal_mask) != palette) + Pixel_in_screen_layered_with_opt_preview(startx+x2, starty+y2, palette | (col & col_mask), preview); } } } @@ -3912,6 +3921,7 @@ void Update_pixel_renderer(void) Pixel_in_current_screen_with_opt_preview = Pixel_in_screen_thomson_with_opt_preview; break; case IMAGE_MODE_GBC: + case IMAGE_MODE_MEGADRIVE: Pixel_in_current_screen_with_opt_preview = Pixel_in_screen_gbc_with_opt_preview; break; case IMAGE_MODE_C64HIRES: diff --git a/src/helpfile.h b/src/helpfile.h index 9145126c..f5e457a9 100644 --- a/src/helpfile.h +++ b/src/helpfile.h @@ -1946,10 +1946,10 @@ static const T_Help_table helptable_effects[] = HELP_TEXT ("") HELP_BOLD ("Block modes") HELP_TEXT ("ZX Spectrum, Game Boy Color, Thomson MOTO,") - HELP_TEXT ("C64 MultiColor, C64 HiRes are modes with") - HELP_TEXT ("block constraints. Only a limited count of") - HELP_TEXT ("different colors (generaly 2) is allowed in") - HELP_TEXT ("a pixel block.") + HELP_TEXT ("Mega Drive, C64 MultiColor and C64 HiRes") + HELP_TEXT ("are modes with block constraints. Only a") + HELP_TEXT ("limited count of different colors is") + HELP_TEXT ("allowed in a pixel block.") HELP_TEXT ("") HELP_BOLD ("Game Boy Color") HELP_TEXT ("All pixels within a 8x8 block should be in") @@ -1962,6 +1962,15 @@ static const T_Help_table helptable_effects[] = HELP_TEXT ("Color #0 of each palette is transparent for") HELP_TEXT ("Game Boy sprites.") HELP_TEXT ("") + HELP_BOLD ("Sega Mega Drive / Genesis") + HELP_TEXT ("The constraints are similar to GBC mode,") + HELP_TEXT ("there are 4 palettes of 16 colors each.") + HELP_TEXT ("Color #0 of each palette is transparent.") + HELP_TEXT ("") + HELP_BOLD ("ZX Spectrum") + HELP_TEXT ("The two colors of the 8x8 block must share") + HELP_TEXT ("the same bightness bit.") + HELP_TEXT ("") HELP_TEXT ("") HELP_BOLD ("C64 Flexible Line Interpretation (FLI)") HELP_TEXT ("- Layer 1 contains the background colors,") diff --git a/src/oldies.c b/src/oldies.c index 7b04c19b..fe3e7a58 100644 --- a/src/oldies.c +++ b/src/oldies.c @@ -65,7 +65,8 @@ static const struct { { IMAGE_MODE_C64MULTI, "C64_MULTICOLOR" }, { IMAGE_MODE_C64FLI, "C64_FLI" }, { IMAGE_MODE_HGR, "APPLE2_HGR" }, - { IMAGE_MODE_DHGR, "APPLE2_DHGR" } + { IMAGE_MODE_DHGR, "APPLE2_DHGR" }, + { IMAGE_MODE_MEGADRIVE, "SEGAMEGADRIVE" }, }; const char * Constraint_mode_label(enum IMAGE_MODES mode)