From 84068c5516917c39a7f7d15aedc23fcbcd375f2f Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Mon, 10 Dec 2018 00:21:15 +0100 Subject: [PATCH] change C64_FLI() to use T_IO_Context --- src/engine.c | 2 ++ src/loadsave.c | 2 +- src/miscfileformats.c | 5 +++-- src/oldies.c | 27 ++++++++++++++++++--------- src/oldies.h | 7 ++++++- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/engine.c b/src/engine.c index 9bb34e06..0390dc83 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1343,10 +1343,12 @@ void Main_handler(void) Layer_activate((key_index-SPECIAL_LAYER1_TOGGLE)/2, RIGHT_SIDE); action++; break; +#if 0 case SPECIAL_FORMAT_CHECKER: C64_FLI_enforcer(); action++; break; +#endif case SPECIAL_REPEAT_SCRIPT: #ifdef __ENABLE_LUA__ diff --git a/src/loadsave.c b/src/loadsave.c index d97b1b55..3e4c79e0 100644 --- a/src/loadsave.c +++ b/src/loadsave.c @@ -114,7 +114,7 @@ const T_Format File_formats[] = { {FORMAT_KCF, " kcf", Test_KCF, Load_KCF, Save_KCF, 1, 0, 0, "kcf", "kcf"}, {FORMAT_PAL, " pal", Test_PAL, Load_PAL, Save_PAL, 1, 0, 0, "pal", "pal"}, {FORMAT_GPL, " gpl", Test_GPL, Load_GPL, Save_GPL, 1, 0, 0, "gpl", "gpl"}, - {FORMAT_C64, " c64", Test_C64, Load_C64, Save_C64, 0, 1, 0, "c64", + {FORMAT_C64, " c64", Test_C64, Load_C64, Save_C64, 0, 1, 1, "c64", "c64;p64;a64;pi;rp;aas;art;dd;iph;ipt;hpc;ocp;koa;koala;fli;bml;cdu;prg;pmg;rpm"}, {FORMAT_SCR, " cpc", Test_SCR, Load_SCR, Save_SCR, 0, 0, 0, "scr", "cpc;scr;win"}, {FORMAT_CM5, " cm5", Test_CM5, Load_CM5, Save_CM5, 0, 0, 1, "cm5", "cm5"}, diff --git a/src/miscfileformats.c b/src/miscfileformats.c index 13887209..149703ac 100644 --- a/src/miscfileformats.c +++ b/src/miscfileformats.c @@ -3748,7 +3748,7 @@ int Save_C64_fli(T_IO_Context * context, byte saveWhat, byte loadAddr) memset(file_buffer,0,sizeof(file_buffer)); - switch(C64_FLI(file_buffer+9474, file_buffer+1282, file_buffer+258, file_buffer+2)) + switch(C64_FLI(context, file_buffer+9474, file_buffer+1282, file_buffer+258, file_buffer+2)) { case 0: // OK break; @@ -3831,10 +3831,11 @@ void Save_C64(T_IO_Context * context) return; } + Set_saving_layer(context, 0); switch (saveFormat) { case F_fli: - if (Main.backups->Pages->Nb_layers < 3) + if (context->Nb_layers < 3) File_error = Save_C64_fli_monolayer(context, saveWhat, loadAddr); else File_error = Save_C64_fli(context, saveWhat, loadAddr); diff --git a/src/oldies.c b/src/oldies.c index a685b2f1..10a958d7 100644 --- a/src/oldies.c +++ b/src/oldies.c @@ -46,12 +46,14 @@ #endif #endif +#if 0 static void Set_Pixel_in_layer(word x,word y, byte layer, byte color) { *((y)*Main.image_width+(x)+Main.backups->Pages->Image[layer].Pixels)=color; } +#endif -int C64_FLI(byte *bitmap, byte *screen_ram, byte *color_ram, byte *background) +int C64_FLI(T_IO_Context * context, byte *bitmap, byte *screen_ram, byte *color_ram, byte *background) { word used_colors[200][40]; word block_used_colors[25][40]; @@ -67,9 +69,9 @@ int C64_FLI(byte *bitmap, byte *screen_ram, byte *color_ram, byte *background) const byte no_color=16; // Prerequisites - if (Main.backups->Pages->Nb_layers < 3) + if (context->Nb_layers < 3) return 1; - if (Main.image_width != 160 || Main.image_height != 200) + if (context->Width != 160 || context->Height != 200) return 2; memset(used_colors,0,200*40*sizeof(word)); @@ -80,23 +82,25 @@ int C64_FLI(byte *bitmap, byte *screen_ram, byte *color_ram, byte *background) // Initialize these as "unset" memset(line_color,no_color,200*sizeof(byte)); memset(block_color,no_color,25*40*sizeof(byte)); - + // Examine all 4-pixel blocks to fill used_colors[][] + Set_saving_layer(context, 2); for (row=0;row<200;row++) { for (col=0;col<40;col++) { for (x=0;x<4;x++) { - byte c=*((row)*Main.image_width+(col*4+x)+Main.backups->Pages->Image[2].Pixels); + byte c = Get_pixel(context, col*4+x, row); used_colors[row][col] |= 1<Pages->Image[0].Pixels); + byte c = Get_pixel(context, 0, row); if (c<16) { line_color[row]=c; @@ -108,11 +112,12 @@ int C64_FLI(byte *bitmap, byte *screen_ram, byte *color_ram, byte *background) } } // Get "mandatory colors" from layer 2 + Set_saving_layer(context, 1); for (row=0;row<200;row+=8) { for (col=0;col<40;col++) { - byte c=*((row)*Main.image_width+(col*4)+Main.backups->Pages->Image[1].Pixels); + byte c = Get_pixel(context, col*4, row); if (c<16) { block_color[row/8][col]=c; @@ -295,7 +300,9 @@ int C64_FLI(byte *bitmap, byte *screen_ram, byte *color_ram, byte *background) } } } - + + // Screen RAMs and Bitmap + Set_saving_layer(context, 2); for(row=0; row<25; row++) { for(col=0; col<40; col++) @@ -324,7 +331,7 @@ int C64_FLI(byte *bitmap, byte *screen_ram, byte *color_ram, byte *background) for(x=0; x<4; x++) { byte bits; - byte c=*((row*8+y)*Main.image_width+(col*4+x)+Main.backups->Pages->Image[2].Pixels); + byte c = Get_pixel(context, col*4+x, row*8+y); if (c==line_color[row*8+y]) // BG color @@ -357,6 +364,7 @@ int C64_FLI(byte *bitmap, byte *screen_ram, byte *color_ram, byte *background) } +#if 0 int C64_FLI_enforcer(void) { byte background[200]; @@ -427,6 +435,7 @@ int C64_FLI_enforcer(void) return 0; } +#endif void C64_set_palette(T_Components * palette) { diff --git a/src/oldies.h b/src/oldies.h index 74ef4a69..371dee7b 100644 --- a/src/oldies.h +++ b/src/oldies.h @@ -22,6 +22,8 @@ ///@file oldies.h /// functions relative to old computers (Commodore 64, Thomsons MO/TO, Amstrad CPC, ZX Spectrum, etc.) +#include "loadsave.h" + /** @defgroup c64 Commodore 64 * Some C64 video mode related functions * @{ @@ -29,14 +31,16 @@ /** * Save a 3 layer picture to C64 FLI format * + * @param context the Save context * @param bitmap a 8000 byte buffer to store bitmap data * @param screen_ram a 8192 byte buffer to store the 8 screen RAMs * @param color_ram a 1000 byte buffer to store the color RAM * @param background a 200 byte buffer to store the background colors * @return 0 for success, 1 if the picture is less than 3 layers, 2 if the picture dimensions are not 160x200 */ -int C64_FLI(byte *bitmap, byte *screen_ram, byte *color_ram, byte *background); +int C64_FLI(T_IO_Context * context, byte *bitmap, byte *screen_ram, byte *color_ram, byte *background); +#if 0 /** * FLI Check/enforcer * @@ -46,6 +50,7 @@ int C64_FLI(byte *bitmap, byte *screen_ram, byte *color_ram, byte *background); * @return 0 for success, 2 if the picture is not 4 layers, 1 if the picture dimensions are not 160x200 */ int C64_FLI_enforcer(void); +#endif /** * Set the 16 colors Commodore 64 palette