From fddc79c8e9e260a23daf0811c085db2ea52d9c5c Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Fri, 9 Nov 2018 01:01:44 +0100 Subject: [PATCH] Save_C64(): add dropdown to choose save Format (FLI/multicolor/etc) --- src/miscfileformats.c | 194 +++++++++++++++++++++++++++--------------- 1 file changed, 126 insertions(+), 68 deletions(-) diff --git a/src/miscfileformats.c b/src/miscfileformats.c index 7075c173..5207fef2 100644 --- a/src/miscfileformats.c +++ b/src/miscfileformats.c @@ -2216,6 +2216,26 @@ void Save_NEO(T_IO_Context * context) //////////////////////////////////// C64 //////////////////////////////////// +/** C64 file formats + */ +enum c64_format +{ + F_invalid = -1, + F_hires = 0, ///< 320x200 + F_multi = 1, ///< 160x200 + F_bitmap = 2, ///< 320x200 monochrome + F_fli = 3 ///< FLI (Flexible Line Interpretation) +}; + +/** C64 file formats names + */ +static const char *c64_format_names[] = { + "Hires", + "Multicolor", + "Bitmap", + "FLI" +}; + /** * Test for a C64 picture file * @@ -2503,8 +2523,7 @@ void Load_C64(T_IO_Context * context) long file_size; byte hasLoadAddr=0; word load_addr; - enum c64_format {F_invalid=-1, F_hires=0,F_multi=1,F_bitmap=2,F_fli=3} loadFormat = F_invalid; - static const char *c64_format_names[]={"Hires","Multicolor","Bitmap","FLI"}; + enum c64_format loadFormat = F_invalid; /// Set C64 Palette from http://www.pepto.de/projects/colorvic/ static const byte pal[48]={ @@ -2787,69 +2806,94 @@ void Load_C64(T_IO_Context * context) File_error = 1; } -int Save_C64_window(byte *saveWhat, byte *loadAddr) +/** + * Display the dialog for C64 save parameters + * + * @param save + * @return true to proceed, false to abort + */ +static int Save_C64_window(enum c64_format *saveFormat, byte *saveWhat, byte *loadAddr) { - int button; - unsigned int i; - T_Dropdown_button *what, *addr; - static const char * what_label[] = { - "All", - "Bitmap", - "Screen", - "Color" - }; - static const char * address_label[] = { - "None", - "$2000", - "$4000", - "$6000", - "$8000", - "$A000", - "$C000", - "$E000" - }; + int button; + unsigned int i; + T_Dropdown_button *what, *addr; + T_Dropdown_button *format; + static const char * what_label[] = { + "All", + "Bitmap", + "Screen", + "Color" + }; + static const char * address_label[] = { + "None", + "$2000", + "$4000", + "$6000", + "$8000", + "$A000", + "$C000", + "$E000" + }; - Open_window(200,120,"c64 settings"); - Window_set_normal_button(110,100,80,15,"Save",1,1,KEY_RETURN); // 1 - Window_set_normal_button(10,100,80,15,"Cancel",1,1,KEY_ESCAPE); // 2 + Open_window(200,120,"C64 saving settings"); + Window_set_normal_button(110,100,80,15,"Save",1,1,KEY_RETURN); // 1 + Window_set_normal_button(10,100,80,15,"Cancel",1,1,KEY_ESCAPE); // 2 - Print_in_window(13,18,"Data:",MC_Dark,MC_Light); - what=Window_set_dropdown_button(10,28,90,15,70,what_label[*saveWhat],1, 0, 1, LEFT_SIDE,0); // 3 - Window_dropdown_clear_items(what); - for (i=0; iWidth!=320) && (context->Width!=160)) || context->Height!=200) @@ -3445,24 +3490,37 @@ void Save_C64(T_IO_Context * context) return; } - if(!Save_C64_window(&saveWhat,&loadAddr)) + saveFormat = (context->Width == 320) ? F_hires : F_multi; + + GFX2_Log(GFX2_DEBUG, "Save_C64() extension : %s\n", context->File_name + strlen(context->File_name) - 4); + if (strcasecmp(context->File_name + strlen(context->File_name) - 4, ".fli") == 0) + saveFormat = F_fli; + + if(!Save_C64_window(&saveFormat, &saveWhat,&loadAddr)) { File_error = 1; return; } - GFX2_Log(GFX2_DEBUG, "Save_C64() extension : %s\n", context->File_name + strlen(context->File_name) - 4); - if (strcasecmp(context->File_name + strlen(context->File_name) - 4, ".fli") == 0) + switch (saveFormat) { - // FIXME moving FLI to a separate format in the fileselector would be smarter - if (Main.backups->Pages->Nb_layers < 3) - File_error = Save_C64_fli_monolayer(context, saveWhat, loadAddr); - else - File_error = Save_C64_fli(context, saveWhat, loadAddr); - } else if (context->Width==320) { - File_error = Save_C64_hires(context, saveWhat, loadAddr); - } else { - File_error = Save_C64_multi(context, saveWhat, loadAddr); + case F_fli: + if (Main.backups->Pages->Nb_layers < 3) + File_error = Save_C64_fli_monolayer(context, saveWhat, loadAddr); + else + File_error = Save_C64_fli(context, saveWhat, loadAddr); + break; + case F_multi: + File_error = Save_C64_multi(context, saveWhat, loadAddr); + break; + case F_bitmap: + saveWhat = 1; // force save bitmap +#if defined(__GNUC__) && (__GNUC__ >= 7) + __attribute__ ((fallthrough)); +#endif + case F_hires: + default: + File_error = Save_C64_hires(context, saveWhat, loadAddr); } }