Save_PRG() supports C64 hires bitmap mode
This commit is contained in:
		
							parent
							
								
									c820ba61ac
								
							
						
					
					
						commit
						19dec01d4f
					
				@ -1161,15 +1161,17 @@ static int Save_C64_window(enum c64_format *saveFormat, byte *saveWhat, word *lo
 | 
			
		||||
  return button==1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Save a C64 hires picture
 | 
			
		||||
///
 | 
			
		||||
/// c64 hires is 320x200 with only 2 colors per 8x8 block.
 | 
			
		||||
static int Save_C64_hires(T_IO_Context *context, byte saveWhat, word loadAddr)
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Encode a C64 HiRes Bitmap picture.
 | 
			
		||||
 * 320x200 pixels, with only 2 different colors per 8x8 block.
 | 
			
		||||
 *
 | 
			
		||||
 * 8000 bytes bitmap, 1000 bytes screen RAM
 | 
			
		||||
 */
 | 
			
		||||
static int Encode_C64_hires(T_IO_Context * context, byte * bitmap, byte * screen_ram)
 | 
			
		||||
{
 | 
			
		||||
  int i, pos = 0;
 | 
			
		||||
  word cx, cy, x, y;
 | 
			
		||||
  byte screen_ram[1000],bitmap[8000];
 | 
			
		||||
  FILE *file;
 | 
			
		||||
 | 
			
		||||
  for(cy=0; cy<25; cy++) // Character line, 25 lines
 | 
			
		||||
  {
 | 
			
		||||
@ -1246,7 +1248,21 @@ static int Save_C64_hires(T_IO_Context *context, byte saveWhat, word loadAddr)
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Save a C64 hires picture
 | 
			
		||||
///
 | 
			
		||||
/// c64 hires is 320x200 with only 2 colors per 8x8 block.
 | 
			
		||||
static int Save_C64_hires(T_IO_Context *context, byte saveWhat, word loadAddr)
 | 
			
		||||
{
 | 
			
		||||
  byte screen_ram[1000],bitmap[8000];
 | 
			
		||||
  FILE *file;
 | 
			
		||||
  int ret;
 | 
			
		||||
 | 
			
		||||
  ret = Encode_C64_hires(context, bitmap, screen_ram);
 | 
			
		||||
  if (ret != 0)
 | 
			
		||||
    return ret;
 | 
			
		||||
  file = Open_file_write(context);
 | 
			
		||||
 | 
			
		||||
  if(!file)
 | 
			
		||||
@ -1722,7 +1738,17 @@ void Save_PRG(T_IO_Context * context)
 | 
			
		||||
  saveFormat = (context->Width == 320) ? F_hires : F_multi;
 | 
			
		||||
  File_error = 1;
 | 
			
		||||
  Set_saving_layer(context, 0);
 | 
			
		||||
  switch (saveFormat)
 | 
			
		||||
  {
 | 
			
		||||
    case F_hires:
 | 
			
		||||
      File_error = Encode_C64_hires(context, bitmap, screen_ram);
 | 
			
		||||
      break;
 | 
			
		||||
    case F_multi:
 | 
			
		||||
      File_error = Encode_C64_multicolor(context, bitmap, screen_ram, color_ram, &background);
 | 
			
		||||
      break;
 | 
			
		||||
    default:
 | 
			
		||||
      GFX2_Log(GFX2_ERROR, "Save_PRG(): format %d not handled (yet?)\n", saveFormat);
 | 
			
		||||
  }
 | 
			
		||||
  if (File_error == 0)
 | 
			
		||||
  {
 | 
			
		||||
    FILE *file;
 | 
			
		||||
@ -1736,7 +1762,7 @@ void Save_PRG(T_IO_Context * context)
 | 
			
		||||
    }
 | 
			
		||||
    if (!Write_bytes(file, picview_prg, sizeof(picview_prg)))
 | 
			
		||||
      File_error = 2;
 | 
			
		||||
    Write_byte(file, 0x30); // Mode : Bitmap + Multicolor
 | 
			
		||||
    Write_byte(file, saveFormat == F_multi ? 0x30 : 0x20); // Mode : 0x40 Extended bg, 0x20 Bitmap, 0x10 Multicolor
 | 
			
		||||
    n = PackBits_pack_buffer(NULL, bitmap, 8000);
 | 
			
		||||
    GFX2_Log(GFX2_DEBUG, "PackBits of bitmap : 8000 => %d bytes\n", n + 1);
 | 
			
		||||
    if (n >= 0 && n < 7999)
 | 
			
		||||
@ -1764,6 +1790,8 @@ void Save_PRG(T_IO_Context * context)
 | 
			
		||||
      Write_byte(file, 0x20); // screen RAM / no packing
 | 
			
		||||
      Write_bytes(file, screen_ram, 1000);
 | 
			
		||||
    }
 | 
			
		||||
    if (saveFormat == F_multi)
 | 
			
		||||
    {
 | 
			
		||||
      //Write_byte(file, 0x30); // color RAM / no packing
 | 
			
		||||
      //Write_bytes(file, color_ram, 1000);
 | 
			
		||||
      Write_byte(file, 0x32); // color RAM / special color RAM packing
 | 
			
		||||
@ -1771,8 +1799,10 @@ void Save_PRG(T_IO_Context * context)
 | 
			
		||||
      if (n < 0)
 | 
			
		||||
        File_error = 1;
 | 
			
		||||
      GFX2_Log(GFX2_DEBUG, "custom packing of color RAM : 1000 => %d bytes\n", n);
 | 
			
		||||
 | 
			
		||||
      Write_byte(file, 0x42); // border/background/etc. / color ram RLE packing
 | 
			
		||||
      Write_byte(file, background | 0x10);
 | 
			
		||||
    }
 | 
			
		||||
    Write_byte(file, 0); // end of file
 | 
			
		||||
    fclose(file);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -404,11 +404,12 @@ ret:
 | 
			
		||||
 | 
			
		||||
int Test_C64_Formats(void)
 | 
			
		||||
{
 | 
			
		||||
  int i;
 | 
			
		||||
  int i, j;
 | 
			
		||||
  int ok = 0;
 | 
			
		||||
  T_IO_Context context;
 | 
			
		||||
  char path[256];
 | 
			
		||||
  T_GFX2_Surface * testpicmulti = NULL;
 | 
			
		||||
  T_GFX2_Surface * testpichires = NULL;
 | 
			
		||||
 | 
			
		||||
  memset(&context, 0, sizeof(context));
 | 
			
		||||
  context.Type = CONTEXT_SURFACE;
 | 
			
		||||
@ -424,6 +425,16 @@ int Test_C64_Formats(void)
 | 
			
		||||
  }
 | 
			
		||||
  testpicmulti = context.Surface;
 | 
			
		||||
  context.Surface = NULL;
 | 
			
		||||
  // Load a hires picture
 | 
			
		||||
  context_set_file_path(&context, "../tests/pic-samples/c64/hires/midear.dd");
 | 
			
		||||
  Load_C64(&context);
 | 
			
		||||
  if (File_error != 0)
 | 
			
		||||
  {
 | 
			
		||||
    fprintf(stderr, "Failed to load reference hires picture\n");
 | 
			
		||||
    goto ret;
 | 
			
		||||
  }
 | 
			
		||||
  testpichires = context.Surface;
 | 
			
		||||
  context.Surface = NULL;
 | 
			
		||||
 | 
			
		||||
  ok = 1;
 | 
			
		||||
  for (i = 0; ok && formats[i].name != NULL; i++)
 | 
			
		||||
@ -433,16 +444,29 @@ int Test_C64_Formats(void)
 | 
			
		||||
    if (!(formats[i].flags & FLAG_C64))
 | 
			
		||||
      continue;
 | 
			
		||||
    GFX2_Log(GFX2_DEBUG, "Testing format %s (Save)\n", formats[i].name);
 | 
			
		||||
    snprintf(path, sizeof(path), "/tmp/%s.%s", "test", formats[i].name);
 | 
			
		||||
    for (j = 0; j < 2; j++)
 | 
			
		||||
    {
 | 
			
		||||
      T_GFX2_Surface * ref;
 | 
			
		||||
 | 
			
		||||
      if (j == 0)
 | 
			
		||||
      {
 | 
			
		||||
        ref = testpicmulti;
 | 
			
		||||
        context.Ratio = PIXEL_WIDE;
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
        ref = testpichires;
 | 
			
		||||
        context.Ratio = PIXEL_SIMPLE;
 | 
			
		||||
      }
 | 
			
		||||
      snprintf(path, sizeof(path), "/tmp/%s-%d.%s", "test", j, formats[i].name);
 | 
			
		||||
      context_set_file_path(&context, path);
 | 
			
		||||
 | 
			
		||||
      // save the reference picture
 | 
			
		||||
    context.Surface = testpicmulti;
 | 
			
		||||
      context.Surface = ref;
 | 
			
		||||
      context.Target_address = context.Surface->pixels;
 | 
			
		||||
      context.Pitch = context.Surface->w;
 | 
			
		||||
      context.Width = context.Surface->w;
 | 
			
		||||
      context.Height = context.Surface->h;
 | 
			
		||||
    context.Ratio = PIXEL_WIDE;
 | 
			
		||||
      memcpy(context.Palette, context.Surface->palette, sizeof(T_Palette));
 | 
			
		||||
      context.Format = formats[i].format;
 | 
			
		||||
      File_error = 0;
 | 
			
		||||
@ -484,7 +508,7 @@ int Test_C64_Formats(void)
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
        if (memcmp(testpicmulti->pixels, context.Surface->pixels, 160*200) != 0)
 | 
			
		||||
          if (memcmp(ref->pixels, context.Surface->pixels, ref->w * ref->h) != 0)
 | 
			
		||||
          {
 | 
			
		||||
            GFX2_Log(GFX2_ERROR, "Save_%s/Load_%s: Pixels mismatch\n", formats[i].name, formats[i].name);
 | 
			
		||||
            ok = 0;
 | 
			
		||||
@ -494,9 +518,12 @@ int Test_C64_Formats(void)
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
ret:
 | 
			
		||||
  if (testpicmulti)
 | 
			
		||||
    Free_GFX2_Surface(testpicmulti);
 | 
			
		||||
  if (testpichires)
 | 
			
		||||
    Free_GFX2_Surface(testpichires);
 | 
			
		||||
  free(context.File_name);
 | 
			
		||||
  free(context.File_directory);
 | 
			
		||||
  return ok;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user