diff --git a/src/buttons_effects.c b/src/buttons_effects.c index 50408364..56c0a147 100644 --- a/src/buttons_effects.c +++ b/src/buttons_effects.c @@ -42,6 +42,7 @@ #include "struct.h" #include "windows.h" #include "tiles.h" +#include "oldies.h" //---------- Menu dans lequel on tagge des couleurs (genre Stencil) ---------- void Menu_tag_colors(char * window_title, byte * table, byte * mode, byte can_cancel, const char *help_section, word close_shortcut) @@ -213,6 +214,7 @@ void Button_Constraint_mode(void) void Button_Constraint_menu(void) { unsigned int i; + int set_palette = 1; short clicked_button; T_Dropdown_button* dropdown; const char * label; @@ -229,12 +231,15 @@ void Button_Constraint_menu(void) {IMAGE_MODE_EGX2, "EGX2 (CPC)", "Alternate Mode1/Mode2 "}, {IMAGE_MODE_MODE5, "Mode 5 (CPC)", "Mode5 "}, {IMAGE_MODE_RASTER, "Rasters (CPC)", "CPC Rasters "}, + {IMAGE_MODE_C64HIRES,"C64 HiRes", "2 colors per 8x8 block"}, + {IMAGE_MODE_C64MULTI,"C64 Multicolor","4 colors per 4x1 block"}, + {IMAGE_MODE_C64FLI, "C64 FLI", "improved multicolor "}, }; - Open_window(194,79,"8-bit constraints"); + Open_window(194,95,"8-bit constraints"); - Window_set_normal_button(31,55,51,14,"Cancel",0,1,KEY_ESC); // 1 - Window_set_normal_button(112,55,51,14,"OK" ,0,1,KEY_RETURN); // 2 + Window_set_normal_button(31,71,51,14,"Cancel",0,1,KEY_ESC); // 1 + Window_set_normal_button(112,71,51,14,"OK" ,0,1,KEY_RETURN); // 2 label = "Constraints"; summary = ""; @@ -250,6 +255,9 @@ void Button_Constraint_menu(void) Window_dropdown_add_item(dropdown, modes[i].mode, modes[i].label); Print_in_window(10, 21+18, summary, MC_Dark, MC_Light); + Window_set_normal_button(10, 51, 14, 14, set_palette?"X":" ", 0, 1, KEY_p); // 4 + Print_in_window(10+18, 51+3, "Set Palette", MC_Dark, MC_Light); + Update_window_area(0,0,Window_width, Window_height); Display_cursor(); @@ -273,6 +281,14 @@ void Button_Constraint_menu(void) break; } } + else if (clicked_button == 4) + { + // palette + set_palette = !set_palette; + Hide_cursor(); + Print_in_window(10+3, 51+3, set_palette?"X":" ", MC_Black, MC_Light); + Display_cursor(); + } } while ( (clicked_button!=1) && (clicked_button!=2) ); @@ -285,6 +301,33 @@ void Button_Constraint_menu(void) if (Main.backups->Pages->Image_mode > IMAGE_MODE_ANIMATION) Button_Constraint_mode(); // unactivate current mode Button_Constraint_mode(); // activate selected Mode + if (set_palette) + { + switch (Selected_Constraint_Mode) + { + case IMAGE_MODE_ZX: + ZX_Spectrum_set_palette(Main.palette); + break; + //case IMAGE_MODE_THOMSON: + // ask TO7/70, MO5 or MO6 / TO8/TO9 + case IMAGE_MODE_EGX: + case IMAGE_MODE_EGX2: + case IMAGE_MODE_MODE5: + case IMAGE_MODE_RASTER: + // TODO : CPC + break; + case IMAGE_MODE_C64HIRES: + case IMAGE_MODE_C64MULTI: + case IMAGE_MODE_C64FLI: + C64_set_palette(Main.palette); + break; + default: + break; + } + // Refresh palette + Set_palette(Main.palette); + //Compute_optimal_menu_colors(Main.palette); // I'm not sure this is needed + } } } @@ -624,7 +667,7 @@ void Button_Smooth_mode(void) } -byte Smooth_default_matrices[4][3][3]= +static const byte Smooth_default_matrices[4][3][3]= { { {1,2,1}, {2,4,2}, {1,2,1} }, { {1,3,1}, {3,9,3}, {1,3,1} }, diff --git a/src/const.h b/src/const.h index 7984fa95..efec8a4d 100644 --- a/src/const.h +++ b/src/const.h @@ -606,6 +606,7 @@ enum OPERATIONS NB_OPERATIONS ///< Number of operations handled by the engine }; +/// Image drawing modes. enum IMAGE_MODES { IMAGE_MODE_LAYERED=0, ///< Layered image @@ -617,6 +618,9 @@ enum IMAGE_MODES IMAGE_MODE_EGX2, ///< CPC EGX2 IMAGE_MODE_MODE5, ///< CPC mode 5 IMAGE_MODE_RASTER, ///< CPC generic rasters + IMAGE_MODE_C64HIRES, ///< C64 HiRes + IMAGE_MODE_C64MULTI, ///< C64 Multicolor + IMAGE_MODE_C64FLI, ///< C64 Flexible Line Interpretation }; /// Circle / Ellipse Modes diff --git a/src/miscfileformats.c b/src/miscfileformats.c index f13444f7..21a23ff4 100644 --- a/src/miscfileformats.c +++ b/src/miscfileformats.c @@ -2679,25 +2679,6 @@ void Load_C64(T_IO_Context * context) word load_addr; enum c64_format loadFormat = F_invalid; - /// Set C64 Palette from http://www.pepto.de/projects/colorvic/ - static const byte pal[48]={ - 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xFF, - 0x68, 0x37, 0x2B, - 0x70, 0xA4, 0xB2, - 0x6F, 0x3D, 0x86, - 0x58, 0x8D, 0x43, - 0x35, 0x28, 0x79, - 0xB8, 0xC7, 0x6F, - 0x6F, 0x4F, 0x25, - 0x43, 0x39, 0x00, - 0x9A, 0x67, 0x59, - 0x44, 0x44, 0x44, - 0x6C, 0x6C, 0x6C, - 0x9A, 0xD2, 0x84, - 0x6C, 0x5E, 0xB5, - 0x95, 0x95, 0x95}; - byte *file_buffer; byte *bitmap, *screen_ram, *color_ram=NULL, *background=NULL; // Only pointers to existing data word width, height=200; @@ -2952,13 +2933,9 @@ void Load_C64(T_IO_Context * context) Pre_load(context, width, height, file_size, FORMAT_C64, context->Ratio, (loadFormat == F_bitmap) ? 1 : 4); // Do this as soon as you can - memcpy(context->Palette,pal,48); // this set the software palette for grafx2 - // Transparent color "16" is a dark grey that is distinguishable - // from black, but darker than normal colors. - context->Palette[16].R=20; - context->Palette[16].G=20; - context->Palette[16].B=20; - + if (Config.Clear_palette) + memset(context->Palette,0, sizeof(T_Palette)); + C64_set_palette(context->Palette); context->Transparent_color=16; switch(loadFormat) diff --git a/src/oldies.c b/src/oldies.c index a2b29885..38c4b921 100644 --- a/src/oldies.c +++ b/src/oldies.c @@ -420,6 +420,48 @@ int C64_FLI_enforcer(void) return 0; } +void C64_set_palette(T_Components * palette) +{ + /// Set C64 Palette from http://www.pepto.de/projects/colorvic/ + static const byte pal[48]={ + 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, + 0x68, 0x37, 0x2B, + 0x70, 0xA4, 0xB2, + 0x6F, 0x3D, 0x86, + 0x58, 0x8D, 0x43, + 0x35, 0x28, 0x79, + 0xB8, 0xC7, 0x6F, + 0x6F, 0x4F, 0x25, + 0x43, 0x39, 0x00, + 0x9A, 0x67, 0x59, + 0x44, 0x44, 0x44, + 0x6C, 0x6C, 0x6C, + 0x9A, 0xD2, 0x84, + 0x6C, 0x5E, 0xB5, + 0x95, 0x95, 0x95}; + + memcpy(palette, pal, 48); + /// Also set transparent color "16" as a dark grey that is distinguishable + /// from black, but darker than normal colors. + palette[16].R=20; + palette[16].G=20; + palette[16].B=20; +} + +void ZX_Spectrum_set_palette(T_Components * palette) +{ + int i, intensity; + + for (i = 0; i < 16; i++) + { + intensity = (i & 8) ? 255 : 205; + palette[i].G = ((i & 4) >> 2) * intensity; + palette[i].R = ((i & 2) >> 1) * intensity; + palette[i].B = (i & 1) * intensity; + } +} + int DECB_Check_binary_file(FILE * f) { byte code; diff --git a/src/oldies.h b/src/oldies.h index c554ebee..462c24ea 100644 --- a/src/oldies.h +++ b/src/oldies.h @@ -38,6 +38,26 @@ int C64_FLI(byte *bitmap, byte *screen_ram, byte *color_ram, byte *background); int C64_FLI_enforcer(void); +/** + * Set the 16 colors Commodore 64 palette + */ +void C64_set_palette(T_Components * palette); + +/** @}*/ + +/** @defgroup zx_spectrum Sinclair ZX Spectrum + * + * @{ + */ + +/** + * Set the 16 colors ZX Spectrum palette. + * + * The ZX Spectrum palette is a 16 color RGBI palette. + * The color components are in IGRB order. + */ +void ZX_Spectrum_set_palette(T_Components * palette); + /** @}*/ /** @defgroup decb DECB binary format